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;
}
// Configurator impact
$flatrate = true;
$impact = 0;
if ($product['id_configurator'] != 0) {
$impact = Product::getConfiguratorSelectedPriceTotal($product['id_product'], $product['id_configurator']);
}
switch ($ps_round_type) {
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;
case Order::ROUND_LINE:
$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);
break;
case Order::ROUND_ITEM:
default:
$product_price = /*$with_taxes ? $tax_calculator->addTaxes($price) : */$price;
$products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision) * (int)$product['cart_quantity'];
$product_price = $price;
$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;
}
}

View File

@ -35,32 +35,13 @@ class Product extends ProductCore
return $priceImpact;
}
/**
* Price calculation / Get product price
*
* @param int $id_shop Shop id
* @param int $id_product Product id
* @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 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);
}
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_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];
}
/**
* Override product price
*/
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,
$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 $productWithImpactPrice;
public function init()
{
parent::init();
@ -43,16 +45,22 @@ class ProductController extends ProductControllerCore
$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()
{
if ($this->ajax && Tools::getValue('impactprice', 0)) {
$qty = Tools::getValue('qty', 1);
$return = array(
'priceDisplay' => Tools::displayPrice($this->impactPrice),
'price' => $this->impactPrice,
'priceUnitDisplay' => Tools::displayPrice($this->product->getPrice(true, null, 6, null, false, true, $qty)),
'priceDisplay' => Tools::displayPrice($this->productPriceWithImpact),
'price' => $this->productPriceWithImpact,
);
die(Tools::jsonEncode($return));
}

View File

@ -600,8 +600,6 @@ class Cart extends CartCore
$products = $this->getProducts($refresh);
foreach ($products as $key => &$product) {
$null = null;
$product['price_without_quantity_discount'] = Product::getPriceStatic(
$product['id_product'],
@ -900,20 +898,38 @@ class Cart extends CartCore
$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) {
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;
case Order::ROUND_LINE:
$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);
break;
case Order::ROUND_ITEM:
default:
$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;
}
}

View File

@ -125,19 +125,6 @@ class Product extends ProductCore
),
);
/*
* module: antadisconfigurator
* 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
WHERE id_product = '.$this->id.'
AND id_configurator_opt IN('.join(',', $optId).')';
$sql = 'SELECT pcoi.`price` FROM `'._DB_PREFIX_.'product_configurator_opt_impact` pcoi
WHERE pcoi.`id_product` = '.$this->id.'
AND pcoi.`id_configurator`_opt IN('.join(',', $optId).')';
$result = Db::getInstance()->executeS($sql);
if (count($result) > 0) {
foreach ($result as $item) {
@ -172,6 +159,12 @@ class Product extends ProductCore
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
@ -317,7 +310,8 @@ class Product extends ProductCore
$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.
' AND id_product = '.(int)$id_product;
$priceResult = Db::getInstance()->executeS($sql);

View File

@ -15,6 +15,13 @@ class ProductController extends ProductControllerCore
*/
protected $impactPrice;
/*
* module: antadisconfigurator
* date: 2017-06-27 12:10:07
* version: 0.1
*/
protected $productPriceWithImpact;
/*
* module: antadisconfigurator
* date: 2017-06-27 12:10:07
@ -62,10 +69,11 @@ class ProductController extends ProductControllerCore
$impact = $this->product->getConfiguratorImpactPrice($this->optValues);
}
$this->impactPrice = $impact;
// We want total price
$productPrice = $productPrice * $qty;
$this->impactPrice = $productPrice + $impact;
$this->productPriceWithImpact = $productPrice + $impact;
}
}
@ -80,8 +88,8 @@ class ProductController extends ProductControllerCore
$qty = Tools::getValue('qty', 1);
$return = array(
'priceUnitDisplay' => Tools::displayPrice($this->product->getPrice(true, null, 6, null, false, true, $qty)),
'priceDisplay' => Tools::displayPrice($this->impactPrice),
'price' => $this->impactPrice,
'priceDisplay' => Tools::displayPrice($this->productPriceWithImpact),
'price' => $this->productPriceWithImpact,
);
die(Tools::jsonEncode($return));
}
@ -101,6 +109,23 @@ class ProductController extends ProductControllerCore
$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()
{
$context = Context::getContext();

View File

@ -129,6 +129,9 @@
<!-- Attributs produits -->
<div class="product_attributes clearfix">
{if $impactPrice > 0}
<div class="hidden">Options sélectionnés: {displayPrice price=$impactPrice}</div>
{/if}
<!-- Prix -->
{if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE}
<div class="price">
@ -141,7 +144,7 @@
{else}
{assign var=quantityTotal value=$product->minimal_quantity}
{/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>
<span class="old-price"{if (!$product->specificPrice || !$product->specificPrice.reduction) && $group_reduction == 0} class="hidden"{/if}>
{if $percentReduction > 0}

View File

@ -29,6 +29,7 @@
</small>
{/foreach}
{/if}
{if !isset($noDeleteButton) || !$noDeleteButton}
{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'}">
@ -126,6 +127,13 @@
{/if}
{/if}
</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}
</div>
</div>