Merge branch 'master' of gitlab.antadis.net:dev-antadis/chocolatdemariage

This commit is contained in:
Nolwenn 2017-08-29 15:25:33 +02:00
commit 43c982dff8
8 changed files with 353 additions and 303 deletions

View File

@ -911,20 +911,38 @@ class Cart extends CartCore
$products_total[$id_tax_rules_group.'_'.$id_address] = 0; $products_total[$id_tax_rules_group.'_'.$id_address] = 0;
} }
// Configurator impact
$flatrate = true;
$impact = 0;
if ($product['id_configurator'] != 0) {
$impact = Product::getConfiguratorSelectedPriceTotal($product['id_product'], $product['id_configurator']);
}
switch ($ps_round_type) { switch ($ps_round_type) {
case Order::ROUND_TOTAL: case Order::ROUND_TOTAL:
$products_total[$id_tax_rules_group.'_'.$id_address] += $price * (int)$product['cart_quantity']; $product_price = $price * (int)$product['cart_quantity'];
if ($product['id_configurator'] != 0 && $flatrate == true) {
$product_price+= $impact;
}
$products_total[$id_tax_rules_group.'_'.$id_address] += $product_price;
break; break;
case Order::ROUND_LINE: case Order::ROUND_LINE:
$product_price = $price * $product['cart_quantity']; $product_price = $price * $product['cart_quantity'];
if ($product['id_configurator'] != 0 && $flatrate == true) {
$product_price+= $impact;
}
$products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision); $products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision);
break; break;
case Order::ROUND_ITEM: case Order::ROUND_ITEM:
default: default:
$product_price = /*$with_taxes ? $tax_calculator->addTaxes($price) : */$price; $product_price = $price;
$products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision) * (int)$product['cart_quantity']; $product_price = Tools::ps_round($product_price, $compute_precision) * (int)$product['cart_quantity'];
if ($product['id_configurator'] != 0 && $flatrate == true) {
$product_price+= $impact;
}
$products_total[$id_tax_rules_group] += $product_price;
break; break;
} }
} }

View File

@ -35,32 +35,13 @@ class Product extends ProductCore
return $priceImpact; return $priceImpact;
} }
/** public static function getConfiguratorSelectedPriceTotal($id_product, $id_configurator)
* Price calculation / Get product price {
* $sql = 'SELECT SUM(cs.`price`) FROM `'._DB_PREFIX_.'configurator_storage` cs
* @param int $id_shop Shop id WHERE cs.`id_product`='.(int)$id_product.' AND cs.`id_configurator`='.(int)$id_configurator;
* @param int $id_product Product id return Db::getInstance()->getValue($sql);
* @param int $id_product_attribute Product attribute id }
* @param int $id_country Country id
* @param int $id_state State id
* @param string $zipcode
* @param int $id_currency Currency id
* @param int $id_group Group id
* @param int $quantity Quantity Required for Specific prices : quantity discount application
* @param bool $use_tax with (1) or without (0) tax
* @param int $decimals Number of decimals returned
* @param bool $only_reduc Returns only the reduction amount
* @param bool $use_reduc Set if the returned amount will include reduction
* @param bool $with_ecotax insert ecotax in price output.
* @param null $specific_price If a specific price applies regarding the previous parameters,
* this variable is filled with the corresponding SpecificPrice object
* @param bool $use_group_reduction
* @param int $id_customer
* @param bool $use_customer_price
* @param int $id_cart
* @param int $real_quantity
* @return float Product price
**/
public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency, public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency,
$id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_group_reduction, $id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_group_reduction,
$id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $id_configurator = null) $id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $id_configurator = null)
@ -283,9 +264,6 @@ class Product extends ProductCore
return self::$_prices[$cache_id]; return self::$_prices[$cache_id];
} }
/**
* Override product price
*/
public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null, public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null,
$only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null, $only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null,
$id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null, $id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null,

View File

@ -5,6 +5,8 @@ class ProductController extends ProductControllerCore
protected $impactPrice; protected $impactPrice;
protected $productWithImpactPrice;
public function init() public function init()
{ {
parent::init(); parent::init();
@ -43,16 +45,22 @@ class ProductController extends ProductControllerCore
$impact = $this->product->getConfiguratorImpactPrice($this->optValues); $impact = $this->product->getConfiguratorImpactPrice($this->optValues);
} }
$this->impactPrice = $productPrice + $impact; $this->impactPrice = $impact;
// We want total price
$productPrice = $productPrice * $qty;
$this->productPriceWithImpact = $productPrice + $impact;
} }
} }
public function postProcess() public function postProcess()
{ {
if ($this->ajax && Tools::getValue('impactprice', 0)) { if ($this->ajax && Tools::getValue('impactprice', 0)) {
$qty = Tools::getValue('qty', 1);
$return = array( $return = array(
'priceDisplay' => Tools::displayPrice($this->impactPrice), 'priceUnitDisplay' => Tools::displayPrice($this->product->getPrice(true, null, 6, null, false, true, $qty)),
'price' => $this->impactPrice, 'priceDisplay' => Tools::displayPrice($this->productPriceWithImpact),
'price' => $this->productPriceWithImpact,
); );
die(Tools::jsonEncode($return)); die(Tools::jsonEncode($return));
} }

View File

@ -600,8 +600,6 @@ class Cart extends CartCore
$products = $this->getProducts($refresh); $products = $this->getProducts($refresh);
foreach ($products as $key => &$product) { foreach ($products as $key => &$product) {
$null = null; $null = null;
$product['price_without_quantity_discount'] = Product::getPriceStatic( $product['price_without_quantity_discount'] = Product::getPriceStatic(
$product['id_product'], $product['id_product'],
@ -900,20 +898,38 @@ class Cart extends CartCore
$products_total[$id_tax_rules_group.'_'.$id_address] = 0; $products_total[$id_tax_rules_group.'_'.$id_address] = 0;
} }
// Configurator impact
$flatrate = true;
$impact = 0;
if ($product['id_configurator'] != 0) {
$impact = Product::getConfiguratorSelectedPriceTotal($product['id_product'], $product['id_configurator']);
}
switch ($ps_round_type) { switch ($ps_round_type) {
case Order::ROUND_TOTAL: case Order::ROUND_TOTAL:
$products_total[$id_tax_rules_group.'_'.$id_address] += $price * (int)$product['cart_quantity']; $product_price = $price * (int)$product['cart_quantity'];
if ($product['id_configurator'] != 0 && $flatrate == true) {
$product_price+= $impact;
}
$products_total[$id_tax_rules_group.'_'.$id_address] += $product_price;
break; break;
case Order::ROUND_LINE: case Order::ROUND_LINE:
$product_price = $price * $product['cart_quantity']; $product_price = $price * $product['cart_quantity'];
if ($product['id_configurator'] != 0 && $flatrate == true) {
$product_price+= $impact;
}
$products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision); $products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision);
break; break;
case Order::ROUND_ITEM: case Order::ROUND_ITEM:
default: default:
$product_price = $price; $product_price = $price;
$products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision) * (int)$product['cart_quantity']; $product_price = Tools::ps_round($product_price, $compute_precision) * (int)$product['cart_quantity'];
if ($product['id_configurator'] != 0 && $flatrate == true) {
$product_price+= $impact;
}
$products_total[$id_tax_rules_group] += $product_price;
break; break;
} }
} }

View File

@ -125,19 +125,6 @@ class Product extends ProductCore
), ),
); );
/* /*
* module: antadisconfigurator * module: antadisconfigurator
* date: 2017-06-27 12:10:06 * date: 2017-06-27 12:10:06
@ -158,9 +145,9 @@ class Product extends ProductCore
} }
} }
$sql = 'SELECT pcoi.price FROM `'._DB_PREFIX_.'product_configurator_opt_impact` pcoi $sql = 'SELECT pcoi.`price` FROM `'._DB_PREFIX_.'product_configurator_opt_impact` pcoi
WHERE id_product = '.$this->id.' WHERE pcoi.`id_product` = '.$this->id.'
AND id_configurator_opt IN('.join(',', $optId).')'; AND pcoi.`id_configurator`_opt IN('.join(',', $optId).')';
$result = Db::getInstance()->executeS($sql); $result = Db::getInstance()->executeS($sql);
if (count($result) > 0) { if (count($result) > 0) {
foreach ($result as $item) { foreach ($result as $item) {
@ -172,6 +159,12 @@ class Product extends ProductCore
return $priceImpact; return $priceImpact;
} }
public static function getConfiguratorSelectedPriceTotal($id_product, $id_configurator)
{
$sql = 'SELECT SUM(cs.`price`) FROM `'._DB_PREFIX_.'configurator_storage` cs
WHERE cs.`id_product`='.(int)$id_product.' AND cs.`id_configurator`='.(int)$id_configurator;
return Db::getInstance()->getValue($sql);
}
/* /*
* module: antadisconfigurator * module: antadisconfigurator
@ -317,7 +310,8 @@ class Product extends ProductCore
$price += $ecotax; $price += $ecotax;
} }
} }
if ($id_configurator != null) { $flatrate = true;
if ($id_configurator != null && $flatrate == false) {
$sql = 'SELECT price FROM `'._DB_PREFIX_.'configurator_storage` WHERE id_configurator = '.(int)$id_configurator. $sql = 'SELECT price FROM `'._DB_PREFIX_.'configurator_storage` WHERE id_configurator = '.(int)$id_configurator.
' AND id_product = '.(int)$id_product; ' AND id_product = '.(int)$id_product;
$priceResult = Db::getInstance()->executeS($sql); $priceResult = Db::getInstance()->executeS($sql);

View File

@ -15,6 +15,13 @@ class ProductController extends ProductControllerCore
*/ */
protected $impactPrice; protected $impactPrice;
/*
* module: antadisconfigurator
* date: 2017-06-27 12:10:07
* version: 0.1
*/
protected $productPriceWithImpact;
/* /*
* module: antadisconfigurator * module: antadisconfigurator
* date: 2017-06-27 12:10:07 * date: 2017-06-27 12:10:07
@ -62,10 +69,11 @@ class ProductController extends ProductControllerCore
$impact = $this->product->getConfiguratorImpactPrice($this->optValues); $impact = $this->product->getConfiguratorImpactPrice($this->optValues);
} }
$this->impactPrice = $impact;
// We want total price // We want total price
$productPrice = $productPrice * $qty; $productPrice = $productPrice * $qty;
$this->productPriceWithImpact = $productPrice + $impact;
$this->impactPrice = $productPrice + $impact;
} }
} }
@ -80,8 +88,8 @@ class ProductController extends ProductControllerCore
$qty = Tools::getValue('qty', 1); $qty = Tools::getValue('qty', 1);
$return = array( $return = array(
'priceUnitDisplay' => Tools::displayPrice($this->product->getPrice(true, null, 6, null, false, true, $qty)), 'priceUnitDisplay' => Tools::displayPrice($this->product->getPrice(true, null, 6, null, false, true, $qty)),
'priceDisplay' => Tools::displayPrice($this->impactPrice), 'priceDisplay' => Tools::displayPrice($this->productPriceWithImpact),
'price' => $this->impactPrice, 'price' => $this->productPriceWithImpact,
); );
die(Tools::jsonEncode($return)); die(Tools::jsonEncode($return));
} }
@ -101,6 +109,23 @@ class ProductController extends ProductControllerCore
$this->addCSS(_THEME_CSS_DIR_.'tools/lightgallery.css'); $this->addCSS(_THEME_CSS_DIR_.'tools/lightgallery.css');
} }
public function initContent()
{
parent::initContent();
$impact = 0;
if (($id_configurator = Tools::getValue('id_configurator', 0)) != 0) {
// Product Info
if (Validate::isLoadedObject($this->product)) {
$qty = Tools::getValue('qty', 1);
$productPrice = $this->product->getPrice(true, null, 6, null, false, true, $qty);
}
$impact = Product::getConfiguratorSelectedPriceTotal($this->product->id, $id_configurator);
}
$this->context->smarty->assign('impactPrice', $impact);
}
public function ajaxProcessGetProductInfo() public function ajaxProcessGetProductInfo()
{ {
$context = Context::getContext(); $context = Context::getContext();

View File

@ -129,6 +129,9 @@
<!-- Attributs produits --> <!-- Attributs produits -->
<div class="product_attributes clearfix"> <div class="product_attributes clearfix">
{if $impactPrice > 0}
<div class="hidden">Options sélectionnés: {displayPrice price=$impactPrice}</div>
{/if}
<!-- Prix --> <!-- Prix -->
{if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE} {if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}
<div class="price"> <div class="price">
@ -141,7 +144,7 @@
{else} {else}
{assign var=quantityTotal value=$product->minimal_quantity} {assign var=quantityTotal value=$product->minimal_quantity}
{/if} {/if}
<span id="our_price_display" class="current-price" itemprop="price">{convertPrice price=$productPrice*$quantityTotal}</span> <span id="our_price_display" class="current-price" itemprop="price">{convertPrice price=$productPrice*$quantityTotal+$impactPrice}</span>
<small style="display:none;" id="unit_price_display">{convertPrice price=$productPrice}</small> <small style="display:none;" id="unit_price_display">{convertPrice price=$productPrice}</small>
<span class="old-price"{if (!$product->specificPrice || !$product->specificPrice.reduction) && $group_reduction == 0} class="hidden"{/if}> <span class="old-price"{if (!$product->specificPrice || !$product->specificPrice.reduction) && $group_reduction == 0} class="hidden"{/if}>
{if $percentReduction > 0} {if $percentReduction > 0}

View File

@ -29,6 +29,7 @@
</small> </small>
{/foreach} {/foreach}
{/if} {/if}
{if !isset($noDeleteButton) || !$noDeleteButton} {if !isset($noDeleteButton) || !$noDeleteButton}
{if (!isset($customizedDatas.$productId.$productAttributeId) OR $quantityDisplayed > 0) && empty($product.gift)} {if (!isset($customizedDatas.$productId.$productAttributeId) OR $quantityDisplayed > 0) && empty($product.gift)}
<a rel="nofollow" title="{l s='Delete'}" class="product-delete cart_quantity_delete" id="{$product.id_product}_{$product.id_product_attribute}_{if $quantityDisplayed > 0}nocustom{else}0{/if}_{$product.id_address_delivery|intval}_{$product.id_configurator|intval}" href="{$link->getPageLink('cart', true, NULL, "delete=1&amp;id_product={$product.id_product|intval}&amp;ipa={$product.id_product_attribute|intval}&amp;id_address_delivery={$product.id_address_delivery|intval}&amp;id_configurator={$product.id_configurator|intval}&amp;token={$token_cart}")|escape:'html':'UTF-8'}"> <a rel="nofollow" title="{l s='Delete'}" class="product-delete cart_quantity_delete" id="{$product.id_product}_{$product.id_product_attribute}_{if $quantityDisplayed > 0}nocustom{else}0{/if}_{$product.id_address_delivery|intval}_{$product.id_configurator|intval}" href="{$link->getPageLink('cart', true, NULL, "delete=1&amp;id_product={$product.id_product|intval}&amp;ipa={$product.id_product_attribute|intval}&amp;id_address_delivery={$product.id_address_delivery|intval}&amp;id_configurator={$product.id_configurator|intval}&amp;token={$token_cart}")|escape:'html':'UTF-8'}">
@ -126,6 +127,13 @@
{/if} {/if}
{/if} {/if}
</span> </span>
{if isset($product.configurator_opt)}
{$id_configurator}
<span class="product_configurator_options" style="display:block; clear:both; font-size:12px;">
Options : + {displayPrice price=Product::getConfiguratorSelectedPriceTotal($product.id_product, $product.id_configurator)}
</span>
{/if}
{/if} {/if}
</div> </div>
</div> </div>