[-] Core: the gift wrapping taxes is now handled by tax rules group

This commit is contained in:
Rémi Gaillard
2012-12-21 18:01:43 +01:00
parent 0e961a9ed1
commit 41ca79cc77
9 changed files with 59 additions and 38 deletions
+27 -9
View File
@@ -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
+1 -1
View File
@@ -52,7 +52,7 @@ class PrestaShopExceptionCore extends Exception
echo '<h2>['.get_class($this).']</h2>';
printf(
'<p><b>%s</b><br /><i>at line </i><b>%d</b><i> in file </i><b>%s</b></p>',
$this->getMessage(),
Tools::safeOutput($this->getMessage()),
$this->getLine(),
ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $this->getFile()), '/')
);
@@ -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'),
@@ -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]))
{
+9 -10
View File
@@ -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(),
+3 -4
View File
@@ -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)));
}
+10
View File
@@ -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';
+4 -4
View File
@@ -217,25 +217,25 @@ class HomeSlider extends Module
$this->_html .= '
<label>'.$this->l('Height:').'</label>
<div class="margin-form">
<input type="text" name="HOMESLIDER_HEIGHT" id="speed" size="3" value="'.Configuration::get('HOMESLIDER_HEIGHT').'" /> px
<input type="text" name="HOMESLIDER_HEIGHT" id="speed" size="3" value="'.Tools::safeOutput(Configuration::get('HOMESLIDER_HEIGHT')).'" /> px
</div>';
/* Width field */
$this->_html .= '
<label>'.$this->l('Width:').'</label>
<div class="margin-form">
<input type="text" name="HOMESLIDER_WIDTH" id="pause" size="3" value="'.Configuration::get('HOMESLIDER_WIDTH').'" /> px
<input type="text" name="HOMESLIDER_WIDTH" id="pause" size="3" value="'.Tools::safeOutput(Configuration::get('HOMESLIDER_WIDTH')).'" /> px
</div>';
/* Speed field */
$this->_html .= '
<label>'.$this->l('Speed:').'</label>
<div class="margin-form">
<input type="text" name="HOMESLIDER_SPEED" id="speed" size="3" value="'.Configuration::get('HOMESLIDER_SPEED').'" /> ms
<input type="text" name="HOMESLIDER_SPEED" id="speed" size="3" value="'.Tools::safeOutput(Configuration::get('HOMESLIDER_SPEED')).'" /> ms
</div>';
/* Pause field */
$this->_html .= '
<label>'.$this->l('Pause:').'</label>
<div class="margin-form">
<input type="text" name="HOMESLIDER_PAUSE" id="pause" size="3" value="'.Configuration::get('HOMESLIDER_PAUSE').'" /> ms
<input type="text" name="HOMESLIDER_PAUSE" id="pause" size="3" value="'.Tools::safeOutput(Configuration::get('HOMESLIDER_PAUSE')).'" /> ms
</div>';
/* Loop field */
$this->_html .= '
+1 -1
View File
@@ -44,7 +44,7 @@ var homeslider_pause = {$homeslider.pause};
<ul id="homeslider">
{foreach from=$homeslider_slides item=slide}
{if $slide.active}
<li><a href="{$slide.url|escape:'htmlall':'UTF-8'}" title="{$slide.description|escape:'htmlall':'UTF-8'}"><img src="{$smarty.const._MODULE_DIR_}/homeslider/images/{$slide.image|escape:'htmlall':'UTF-8'}" alt="{$slide.legend|escape:'htmlall':'UTF-8'}" legend="{$slide.description}" height="{$homeslider.height|intval}" width="{$homeslider.width|intval}" /></a></li>
<li><a href="{$slide.url|escape:'htmlall':'UTF-8'}" title="{$slide.description|escape:'htmlall':'UTF-8'}"><img src="{$smarty.const._MODULE_DIR_}/homeslider/images/{$slide.image|escape:'htmlall':'UTF-8'}" alt="{$slide.legend|escape:'htmlall':'UTF-8'}" legend="{$slide.description|escape:'htmlall':'UTF-8'}" height="{$homeslider.height|intval}" width="{$homeslider.width|intval}" /></a></li>
{/if}
{/foreach}
</ul>