// Old code cleaning & #PSCFV-3144
This commit is contained in:
@@ -156,8 +156,8 @@ class ProductControllerCore extends FrontController
|
||||
$this->context->cart->add();
|
||||
$this->context->cookie->id_cart = (int)$this->context->cart->id;
|
||||
}
|
||||
$this->pictureUpload($this->product, $this->context->cart);
|
||||
$this->textRecord($this->product, $this->context->cart);
|
||||
$this->pictureUpload();
|
||||
$this->textRecord();
|
||||
$this->formTargetFormat();
|
||||
}
|
||||
else if (Tools::getIsset('deletePicture') && !$this->context->cart->deletePictureToProduct($this->product->id, Tools::getValue('deletePicture')))
|
||||
@@ -198,6 +198,7 @@ class ProductControllerCore extends FrontController
|
||||
$return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category));
|
||||
else
|
||||
$return_link = 'javascript: history.back();';
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'customizationFields' => ($this->product->customizable) ? $this->product->getCustomizationFields($this->context->language->id) : false,
|
||||
'accessories' => $this->product->getAccessories($this->context->language->id),
|
||||
@@ -228,7 +229,6 @@ class ProductControllerCore extends FrontController
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('errors', $this->errors);
|
||||
|
||||
$this->setTemplate(_PS_THEME_DIR_.'product.tpl');
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ class ProductControllerCore extends FrontController
|
||||
$this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
|
||||
}
|
||||
|
||||
public function transformDescriptionWithImg($desc)
|
||||
protected function transformDescriptionWithImg($desc)
|
||||
{
|
||||
$reg = '/\[img-([0-9]+)-(left|right)-([a-z]+)\]/';
|
||||
while (preg_match($reg, $desc, $matches))
|
||||
@@ -467,7 +467,7 @@ class ProductControllerCore extends FrontController
|
||||
return $desc;
|
||||
}
|
||||
|
||||
public function pictureUpload(Product $product, Cart $cart)
|
||||
protected function pictureUpload()
|
||||
{
|
||||
if (!$field_ids = $this->product->getCustomizationFieldIds())
|
||||
return false;
|
||||
@@ -497,23 +497,22 @@ class ProductControllerCore extends FrontController
|
||||
elseif (!chmod(_PS_UPLOAD_DIR_.$file_name, 0777) || !chmod(_PS_UPLOAD_DIR_.$file_name.'_small', 0777))
|
||||
$this->errors[] = Tools::displayError('An error occurred during the image upload.');
|
||||
else
|
||||
{
|
||||
// Store customization in database
|
||||
$cart->addPictureToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_FILE, $file_name);
|
||||
}
|
||||
$this->context->cart->addPictureToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_FILE, $file_name);
|
||||
unlink($tmp_name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function textRecord(Product $product, Cart $cart)
|
||||
protected function textRecord()
|
||||
{
|
||||
if (!$field_ids = $this->product->getCustomizationFieldIds())
|
||||
return false;
|
||||
|
||||
$authorized_text_fields = array();
|
||||
foreach ($field_ids as $field_id)
|
||||
if ($field_id['type'] == Product::CUSTOMIZE_TEXTFIELD)
|
||||
$authorized_text_fields[(int)$field_id['id_customization_field']] = 'textField'.(int)$field_id['id_customization_field'];
|
||||
|
||||
$indexes = array_flip($authorized_text_fields);
|
||||
foreach ($_POST as $field_name => $value)
|
||||
if (in_array($field_name, $authorized_text_fields) && !empty($value))
|
||||
@@ -521,13 +520,13 @@ class ProductControllerCore extends FrontController
|
||||
if (!Validate::isMessage($value))
|
||||
$this->errors[] = Tools::displayError('Invalid message');
|
||||
else
|
||||
$cart->addTextFieldToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_TEXTFIELD, $value);
|
||||
$this->context->cart->addTextFieldToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_TEXTFIELD, $value);
|
||||
}
|
||||
else if (in_array($field_name, $authorized_text_fields) && empty($value))
|
||||
$cart->deleteCustomizationToProduct((int)$this->product->id, $indexes[$field_name]);
|
||||
$this->context->cart->deleteCustomizationToProduct((int)$this->product->id, $indexes[$field_name]);
|
||||
}
|
||||
|
||||
public function formTargetFormat()
|
||||
protected function formTargetFormat()
|
||||
{
|
||||
$customization_form_target = Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']));
|
||||
foreach ($_GET as $field => $value)
|
||||
@@ -538,7 +537,7 @@ class ProductControllerCore extends FrontController
|
||||
$this->context->smarty->assign('customizationFormTarget', $customization_form_target);
|
||||
}
|
||||
|
||||
public function formatQuantityDiscounts($specific_prices, $price, $tax_rate)
|
||||
protected function formatQuantityDiscounts($specific_prices, $price, $tax_rate)
|
||||
{
|
||||
foreach ($specific_prices as $key => &$row)
|
||||
{
|
||||
@@ -546,27 +545,16 @@ class ProductControllerCore extends FrontController
|
||||
if ($row['price'] >= 0) // The price may be directly set
|
||||
{
|
||||
$cur_price = (Product::$_taxCalculationMethod == PS_TAX_EXC ? $row['price'] : $row['price'] * (1 + $tax_rate / 100));
|
||||
|
||||
if ($row['reduction_type'] == 'amount')
|
||||
if (Product::$_taxCalculationMethod == PS_TAX_INC)
|
||||
$cur_price = $cur_price - $row['reduction'];
|
||||
else
|
||||
$cur_price = $cur_price - ($row['reduction'] / (1 + $tax_rate / 100));
|
||||
$cur_price -= (Product::$_taxCalculationMethod == PS_TAX_INC ? $row['reduction'] : $row['reduction'] / (1 + $tax_rate / 100));
|
||||
else
|
||||
$cur_price = $cur_price * ( 1 - ($row['reduction']));
|
||||
|
||||
$cur_price *= 1 - $row['reduction'];
|
||||
$row['real_value'] = $price - $cur_price;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($row['reduction_type'] == 'amount')
|
||||
{
|
||||
// Commenting unused code, delete if useless
|
||||
// $reduction_amount = $row['reduction'];
|
||||
// if (!$row['id_currency'])
|
||||
// $reduction_amount = Tools::convertPrice($reduction_amount, $this->context->currency->id);
|
||||
$row['real_value'] = Product::$_taxCalculationMethod == PS_TAX_INC ? $row['reduction'] : $row['reduction'] / (1 + $tax_rate / 100);
|
||||
}
|
||||
else
|
||||
$row['real_value'] = $row['reduction'] * 100;
|
||||
}
|
||||
@@ -574,5 +562,4 @@ class ProductControllerCore extends FrontController
|
||||
}
|
||||
return $specific_prices;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user