80 lines
3.8 KiB
PHP
80 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* PRO Module to show VAT-free price with the price tax incl.
|
|
*
|
|
* @author Singleton software <info@singleton-software.com>
|
|
* @copyright 2018 Singleton software
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
*/
|
|
|
|
class DualPriceDisplayProProductCombinationsModuleFrontController extends ModuleFrontController
|
|
{
|
|
public function __construct() {
|
|
parent::__construct();
|
|
}
|
|
|
|
public function initContent() {
|
|
parent::initContent();
|
|
}
|
|
|
|
public function displayAjaxGetProductCombinationPrice() {
|
|
if (Tools::getIsset('token')) {
|
|
$idProduct = (int)Tools::getValue('id_product');
|
|
$idProductAttribute = (Tools::getIsset('group') ? (int)self::getProductAttributesID((int)Tools::getValue('id_product'), Tools::getValue('group')) : 0);
|
|
$quantity = (int)Tools::getValue('qty');
|
|
} else {
|
|
$idProduct = (int)Tools::getValue('productID');
|
|
$idProductAttribute = (int)Tools::getValue('productAttributeID');
|
|
$quantity = (int)Tools::getValue('quantity');
|
|
}
|
|
$productPrice = array();
|
|
$productPrice['taxInclPrice'] = Tools::displayPrice(Product::getPriceStatic($idProduct, true, (($idProductAttribute > 0) ? $idProductAttribute : null), 6, null, false, true) * $quantity, $this->context->currency);
|
|
$productPrice['taxExclPrice'] = Tools::displayPrice(Product::getPriceStatic($idProduct, false, (($idProductAttribute > 0) ? $idProductAttribute : null), 6, null, false, true) * $quantity, $this->context->currency);
|
|
$productPrice['originalTaxInclPrice'] = Tools::displayPrice(Product::getPriceStatic($idProduct, true, (($idProductAttribute > 0) ? $idProductAttribute : null), 6, null, false, false) * $quantity, $this->context->currency);
|
|
$productPrice['originalTaxExclPrice'] = Tools::displayPrice(Product::getPriceStatic($idProduct, false, (($idProductAttribute > 0) ? $idProductAttribute : null), 6, null, false, false) * $quantity, $this->context->currency);
|
|
$productPrice['hasDiscount'] = ($productPrice['taxInclPrice'] < $productPrice['originalTaxInclPrice']);
|
|
die(Tools::jsonEncode(
|
|
array(
|
|
'productPriceInDetail' => $productPrice,
|
|
'productID' => $idProduct
|
|
)
|
|
));
|
|
}
|
|
|
|
public static function getProductAttributesID($productId, $groups) {
|
|
if (!is_array($groups)) {
|
|
return 0;
|
|
}
|
|
|
|
$productAttributeId = Db::getInstance()->getValue('
|
|
SELECT pac.`id_product_attribute`
|
|
FROM `'._DB_PREFIX_.'product_attribute_combination` pac
|
|
INNER JOIN `'._DB_PREFIX_.'product_attribute` pa ON pa.id_product_attribute = pac.id_product_attribute
|
|
WHERE id_product = '.(int)$productId.' AND id_attribute IN ('.implode(',', array_map('intval', $groups)).')
|
|
GROUP BY id_product_attribute
|
|
HAVING COUNT(id_product) = '.count($groups));
|
|
|
|
if ($productAttributeId === false) {
|
|
$ordered = array();
|
|
$result = Db::getInstance()->executeS('SELECT `id_attribute` FROM `'._DB_PREFIX_.'attribute` a
|
|
INNER JOIN `'._DB_PREFIX_.'attribute_group` g ON a.`id_attribute_group` = g.`id_attribute_group`
|
|
WHERE `id_attribute` IN ('.implode(',', array_map('intval', $groups)).') ORDER BY g.`position` ASC');
|
|
|
|
foreach ($result as $row) {
|
|
$ordered[] = $row['id_attribute'];
|
|
}
|
|
|
|
while ($productAttributeId === false && count($ordered) > 0) {
|
|
array_pop($ordered);
|
|
$productAttributeId = Db::getInstance()->getValue('
|
|
SELECT pac.`id_product_attribute`
|
|
FROM `'._DB_PREFIX_.'product_attribute_combination` pac
|
|
INNER JOIN `'._DB_PREFIX_.'product_attribute` pa ON pa.id_product_attribute = pac.id_product_attribute
|
|
WHERE id_product = '.(int)$productId.' AND id_attribute IN ('.implode(',', array_map('intval', $ordered)).')
|
|
GROUP BY id_product_attribute
|
|
HAVING COUNT(id_product) = '.count($ordered));
|
|
}
|
|
}
|
|
return $productAttributeId;
|
|
}
|
|
} |