75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
class ProductController extends ProductControllerCore
|
|
{
|
|
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
if(Tools::getValue('ajax') && Tools::getValue('action') == 'getProductInfo'){
|
|
$this->ajaxProcessGetProductInfo();
|
|
}
|
|
}
|
|
|
|
public function ajaxProcessGetProductInfo()
|
|
{
|
|
$context = Context::getContext();
|
|
$product = new Product(Tools::getValue('id_product'),true,$context->cookie->id_lang);
|
|
|
|
if($product)
|
|
{
|
|
$idCombination = null;
|
|
$attributes = null;
|
|
|
|
if(Tools::getValue('idCombination'))
|
|
{
|
|
$idCombination = Tools::getValue('idCombination');
|
|
$attributes = $product->getAttributeCombinationsById($idCombination,$context->cookie->id_lang);
|
|
}
|
|
$priceDisplay = Group::getPriceDisplayMethod($context->customer->id_default_group);
|
|
|
|
if (!$priceDisplay || $priceDisplay == 2)
|
|
{
|
|
$productPrice = Tools::displayPrice($product->getPrice(true, $idCombination));
|
|
$productPriceWithoutReduction = Tools::displayPrice($product->getPriceWithoutReduct(false, $idCombination));
|
|
}
|
|
else if( $priceDisplay == 1)
|
|
{
|
|
$productPrice = Tools::displayPrice($product->getPrice(false, $idCombination));
|
|
$productPriceWithoutReduction = Tools::displayPrice($product->getPriceWithoutReduct(true, $idCombination));
|
|
}
|
|
|
|
if($idCombination !== null){
|
|
$combinationImages = $product->getCombinationImages($this->context->language->id);
|
|
if($combinationImages) {
|
|
$img = reset($combinationImages[$idCombination]);
|
|
$product->img = $context->link->getImageLink($product->link_rewrite, $img["id_image"], 'home_default');
|
|
} else {
|
|
$product->img = $context->link->getImageLink($product->link_rewrite, $product->getCoverWs(), 'home_default');
|
|
}
|
|
|
|
} else {
|
|
$product->img = $context->link->getImageLink($product->link_rewrite, $product->getCoverWs(), 'home_default');
|
|
}
|
|
|
|
$product->attributes = $attributes;
|
|
$product->productPrice = $productPrice;
|
|
$product->productPriceWithoutReduction = $productPriceWithoutReduction;
|
|
|
|
if($productPrice != $productPriceWithoutReduction) {
|
|
$product->reduction = -1 * round(100 - ($productPrice * 100 / $productPriceWithoutReduction));
|
|
}
|
|
|
|
$to_return = array(
|
|
'product' => $product,
|
|
'found' => true
|
|
);
|
|
}
|
|
else
|
|
{
|
|
$to_return = array('found' => false);
|
|
}
|
|
echo Tools::jsonEncode($to_return);
|
|
}
|
|
|
|
} |