diff --git a/classes/Cart.php b/classes/Cart.php index 4488ace53..0a62438f7 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1454,15 +1454,7 @@ class CartCore extends ObjectModel // Wrapping Fees $wrapping_fees = 0; if ($this->gift) - { - $wrapping_fees = (float)Configuration::get('PS_GIFT_WRAPPING_PRICE'); - if ($with_taxes) - { - $wrapping_fees_tax = new Tax(Configuration::get('PS_GIFT_WRAPPING_TAX')); - $wrapping_fees *= 1 + ((float)$wrapping_fees_tax->rate / 100); - } - $wrapping_fees = Tools::convertPrice(Tools::ps_round($wrapping_fees, 2), Currency::getCurrencyInstance((int)$this->id_currency)); - } + $wrapping_fees = Tools::convertPrice(Tools::ps_round($this->getGiftWrappingPrice($with_taxes), 2), Currency::getCurrencyInstance((int)$this->id_currency)); $order_total_discount = 0; if (!in_array($type, array(Cart::ONLY_SHIPPING, Cart::ONLY_PRODUCTS)) && CartRule::isFeatureActive()) @@ -1539,6 +1531,32 @@ class CartCore extends ObjectModel return Tools::ps_round((float)$order_total, 2); } + + /** + * Get the gift wrapping price + * @param boolean $with_taxes With or without taxes + * @return gift wrapping price + */ + public function getGiftWrappingPrice($with_taxes = true, $id_address = null) + { + static $address = null; + + if ($id_address === null) + $id_address = (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; + + if ($address === null) + $address = Address::initialize($id_address); + + $wrapping_fees = (float)Configuration::get('PS_GIFT_WRAPPING_PRICE'); + if ($with_taxes && $wrapping_fees > 0) + { + $tax_manager = TaxManagerFactory::getManager($address, (int)Configuration::get('PS_GIFT_WRAPPING_TAX_RULES_GROUP')); + $tax_calculator = $tax_manager->getTaxCalculator(); + $wrapping_fees = $tax_calculator->addTaxes($wrapping_fees); + } + + return $wrapping_fees; + } /** * Get the number of packages diff --git a/classes/exception/PrestaShopException.php b/classes/exception/PrestaShopException.php index c0920313c..273edad33 100644 --- a/classes/exception/PrestaShopException.php +++ b/classes/exception/PrestaShopException.php @@ -52,7 +52,7 @@ class PrestaShopExceptionCore extends Exception echo '

['.get_class($this).']

'; printf( '

%s
at line %d in file %s

', - $this->getMessage(), + Tools::safeOutput($this->getMessage()), $this->getLine(), ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $this->getFile()), '/') ); diff --git a/controllers/admin/AdminOrderPreferencesController.php b/controllers/admin/AdminOrderPreferencesController.php index cd60f3cad..8ab477f41 100644 --- a/controllers/admin/AdminOrderPreferencesController.php +++ b/controllers/admin/AdminOrderPreferencesController.php @@ -53,11 +53,6 @@ class AdminOrderPreferencesControllerCore extends AdminController ) ); - // Tax list - $taxes[] = array('id' => 0, 'name' => $this->l('None')); - foreach (Tax::getTaxes($this->context->language->id) as $tax) - $taxes[] = array('id' => $tax['id_tax'], 'name' => $tax['name']); - $this->fields_options = array( 'general' => array( 'title' => $this->l('General'), @@ -140,14 +135,14 @@ class AdminOrderPreferencesControllerCore extends AdminController 'cast' => 'floatval', 'type' => 'price' ), - 'PS_GIFT_WRAPPING_TAX' => array( + 'PS_GIFT_WRAPPING_TAX_RULES_GROUP' => array( 'title' => $this->l('Gift-wrapping tax'), 'desc' => $this->l('Set a tax for gift-wrapping'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', - 'list' => $taxes, - 'identifier' => 'id' + 'list' => array_merge(array(array('id_tax_rules_group' => 0, 'name' => $this->l('None'))), TaxRulesGroup::getTaxRulesGroups(true)), + 'identifier' => 'id_tax_rules_group' ), 'PS_RECYCLABLE_PACK' => array( 'title' => $this->l('Offer recycled packaging'), diff --git a/controllers/admin/AdminShippingController.php b/controllers/admin/AdminShippingController.php index f7dfcb7b4..e9dd1003e 100644 --- a/controllers/admin/AdminShippingController.php +++ b/controllers/admin/AdminShippingController.php @@ -98,7 +98,7 @@ class AdminShippingControllerCore extends AdminController else $array_carrier[] = $carrier['id_carrier']; - $id_carrier = Tools::getValue('id_carrier'); + $id_carrier = (int)Tools::getValue('id_carrier'); if (count($carriers) && isset($array_carrier[0])) { diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 9bbe1314c..e57dd8dca 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -141,9 +141,8 @@ class OrderOpcControllerCore extends ParentOrderController $this->_processAddressFormat(); $this->_assignAddress(); // Wrapping fees - $wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')); - $wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX'))); - $wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100))); + $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false); + $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice(); $return = array_merge(array( 'order_opc_adress' => $this->context->smarty->fetch(_PS_THEME_DIR_.'order-address.tpl'), 'block_user_info' => (isset($blockUserInfo) ? $blockUserInfo->hookTop(array()) : ''), @@ -203,9 +202,8 @@ class OrderOpcControllerCore extends ParentOrderController { $result = $this->_getCarrierList(); // Wrapping fees - $wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')); - $wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX'))); - $wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100))); + $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false); + $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice(); $result = array_merge($result, array( 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), @@ -493,9 +491,10 @@ class OrderOpcControllerCore extends ParentOrderController $carriers = $this->context->cart->simulateCarriersOutput(); $delivery_option = $this->context->cart->getDeliveryOption(null, false, false); - $wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')); - $wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX'))); - $wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100))); + + $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false); + $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice(); + $vars = array( 'free_shipping' => $free_shipping, 'checkedTOS' => (int)($this->context->cookie->checkedTOS), @@ -505,7 +504,7 @@ class OrderOpcControllerCore extends ParentOrderController 'conditions' => (int)(Configuration::get('PS_CONDITIONS')), 'link_conditions' => $link_conditions, 'recyclable' => (int)($this->context->cart->recyclable), - 'gift_wrapping_price' => (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')), + 'gift_wrapping_price' => (float)$wrapping_fees, 'total_wrapping_cost' => Tools::convertPrice($wrapping_fees_tax_inc, $this->context->currency), 'total_wrapping_tax_exc_cost' => Tools::convertPrice($wrapping_fees, $this->context->currency), 'delivery_option_list' => $this->context->cart->getDeliveryOptionList(), diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index 6de89a766..9cf6a2d47 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -470,9 +470,8 @@ class ParentOrderControllerCore extends FrontController protected function _assignWrappingAndTOS() { // Wrapping fees - $wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')); - $wrapping_fees_tax = new Tax(Configuration::get('PS_GIFT_WRAPPING_TAX')); - $wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100))); + $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false); + $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice(); // TOS $cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $this->context->language->id); @@ -495,7 +494,7 @@ class ParentOrderControllerCore extends FrontController 'checked' => $this->context->cart->simulateCarrierSelectedOutput(), 'address_collection' => $this->context->cart->getAddressCollection(), 'delivery_option' => $this->context->cart->getDeliveryOption(null, false), - 'gift_wrapping_price' => (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')), + 'gift_wrapping_price' => (float)$wrapping_fees, 'total_wrapping_cost' => Tools::convertPrice($wrapping_fees_tax_inc, $this->context->currency), 'total_wrapping_tax_exc_cost' => Tools::convertPrice($wrapping_fees, $this->context->currency))); } diff --git a/install-dev/upgrade/sql/1.5.3.0.sql b/install-dev/upgrade/sql/1.5.3.0.sql index 757b64804..40d23ae80 100644 --- a/install-dev/upgrade/sql/1.5.3.0.sql +++ b/install-dev/upgrade/sql/1.5.3.0.sql @@ -26,3 +26,13 @@ ALTER TABLE `PREFIX_cart` CHANGE `delivery_option` `delivery_option` TEXT CHARAC ALTER TABLE `PREFIX_currency_shop` ADD `conversion_rate` DECIMAL( 13, 6 ) NOT NULL; UPDATE `PREFIX_currency_shop` a SET `conversion_rate` = (SELECT `conversion_rate` FROM `PREFIX_currency` b WHERE a.id_currency = b.id_currency); + +INSERT INTO `PREFIX_configuration`(`name`, `value`, `id_shop`, `id_shop_group`, `date_add`, `date_upd`) + (SELECT 'PS_GIFT_WRAPPING_TAX_RULES_GROUP', b.`id_tax_rules_group`, a.`id_shop`, a.`id_shop_group`, NOW(), NOW() + FROM `PREFIX_configuration` a + JOIN `PREFIX_tax_rule` b ON (a.value = b.id_tax) + WHERE a.name='PS_GIFT_WRAPPING_TAX' + GROUP BY a.`id_shop`, a.`id_shop_group` + ); + +DELETE FROM `PREFIX_configuration` WHERE name='PS_GIFT_WRAPPING_TAX'; diff --git a/modules/homeslider/homeslider.php b/modules/homeslider/homeslider.php index deca9d4af..cc14afcd8 100644 --- a/modules/homeslider/homeslider.php +++ b/modules/homeslider/homeslider.php @@ -217,25 +217,25 @@ class HomeSlider extends Module $this->_html .= '
- px + px
'; /* Width field */ $this->_html .= '
- px + px
'; /* Speed field */ $this->_html .= '
- ms + ms
'; /* Pause field */ $this->_html .= '
- ms + ms
'; /* Loop field */ $this->_html .= ' diff --git a/modules/homeslider/homeslider.tpl b/modules/homeslider/homeslider.tpl index 842187bdf..f385f315a 100644 --- a/modules/homeslider/homeslider.tpl +++ b/modules/homeslider/homeslider.tpl @@ -44,7 +44,7 @@ var homeslider_pause = {$homeslider.pause};