bebeboutik/modules/expresscart/ajax.php

205 lines
10 KiB
PHP
Executable File

<?php
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../init.php');
$controller->preProcess();
function formatQuantityDiscounts($specificPrices, $price, $taxRate) {
foreach($specificPrices as $key => &$row) {
$row['quantity'] = &$row['from_quantity'];
// The price may be directly set
if ($row['price'] != 0) {
$cur_price = (Product::$_taxCalculationMethod == PS_TAX_EXC? $row['price']: $row['price'] * (1 + $taxRate / 100));
if($row['reduction_type'] == 'amount') {
$cur_price = Product::$_taxCalculationMethod == PS_TAX_INC? $cur_price - $row['reduction']: $cur_price - ($row['reduction'] / (1 + $taxRate / 100));
} else {
$cur_price = $cur_price * ( 1 - ($row['reduction']));
}
$row['real_value'] = $price - $cur_price;
} else {
global $cookie;
$id_currency = (int) $cookie->id_currency;
if($row['reduction_type'] == 'amount') {
$reduction_amount = $row['reduction'];
if(!$row['id_currency']) {
$reduction_amount = Tools::convertPrice($reduction_amount, $id_currency);
}
$row['real_value'] = Product::$_taxCalculationMethod == PS_TAX_INC? $reduction_amount: $reduction_amount / (1 + $taxRate / 100);
} else {
$row['real_value'] = $row['reduction'] * 100;
}
}
$row['nextQuantity'] = (isset($specificPrices[$key + 1])? (int)($specificPrices[$key + 1]['from_quantity']): -1);
}
return $specificPrices;
}
$result = '';
if($id_product = (int) Tools::getValue('id_product')) {
$tpl = 'product';
if((int) Tools::getValue('page')) {
$tpl = 'product_footer';
}
$product = new Product($id_product, true, (int) $cookie->id_lang);
if(Validate::isLoadedObject($product)) {
$ecotax_rate = (float) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotaxTaxAmount = Tools::ps_round($product->ecotax, 2);
if(Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2);
}
$id_customer = (isset($cookie->id_customer) && $cookie->id_customer)? (int) $cookie->id_customer: 0;
$id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer): _PS_DEFAULT_CUSTOMER_GROUP_;
$id_country = (int) ($id_customer? Customer::getCurrentCountry($id_customer): Configuration::get('PS_COUNTRY_DEFAULT'));
$ps_language = new Language((int) $cookie->id_lang);
$group_reduction = GroupReduction::getValueForProduct($product->id, $id_group);
if($group_reduction == 0) {
$group_reduction = Group::getReduction((int) $cookie->id_customer) / 100;
}
$tax = (float) Tax::getProductTaxRate((int) $product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$productPriceWithTax = Product::getPriceStatic($product->id, TRUE, NULL, 6);
if(Product::$_taxCalculationMethod == PS_TAX_INC) {
$productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
}
$productPriceWithoutEcoTax = (float) ($productPriceWithTax - $product->ecotax);
$colors = array();
$attributesGroups = $product->getAttributesGroups((int) $cookie->id_lang);
if(is_array($attributesGroups) && $attributesGroups) {
$groups = array();
$combinationImages = $product->getCombinationImages((int) $cookie->id_lang);
foreach($attributesGroups as $k => $row) {
/* Color management */
if(((isset($row['attribute_color']) && $row['attribute_color']) || (file_exists(_PS_COL_IMG_DIR_.$row['id_attribute'].'.jpg'))) && $row['id_attribute_group'] == $product->id_color_default) {
$colors[$row['id_attribute']]['value'] = $row['attribute_color'];
$colors[$row['id_attribute']]['name'] = $row['attribute_name'];
if(!isset($colors[$row['id_attribute']]['attributes_quantity'])) {
$colors[$row['id_attribute']]['attributes_quantity'] = 0;
}
$colors[$row['id_attribute']]['attributes_quantity'] += (int)($row['quantity']);
}
if(!isset($groups[$row['id_attribute_group']])) {
$groups[$row['id_attribute_group']] = array(
'name' => $row['public_group_name'],
'is_color_group' => $row['is_color_group'],
'default' => -1,
);
}
$groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name'];
if($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) {
$groups[$row['id_attribute_group']]['default'] = (int)($row['id_attribute']);
}
if(!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) {
$groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0;
}
$groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int)($row['quantity']);
$combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name'];
$combinations[$row['id_product_attribute']]['attributes'][] = (int) $row['id_attribute'];
$combinations[$row['id_product_attribute']]['price'] = (float) $row['price'];
$combinations[$row['id_product_attribute']]['ecotax'] = (float) $row['ecotax'];
$combinations[$row['id_product_attribute']]['weight'] = (float) $row['weight'];
$combinations[$row['id_product_attribute']]['quantity'] = (int) $row['quantity'];
$combinations[$row['id_product_attribute']]['reference'] = $row['reference'];
$combinations[$row['id_product_attribute']]['ean13'] = $row['ean13'];
$combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact'];
$combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity'];
$combinations[$row['id_product_attribute']]['id_image'] = isset($combinationImages[$row['id_product_attribute']][0]['id_image'])? $combinationImages[$row['id_product_attribute']][0]['id_image']: -1;
}
//wash attributes list (if some attributes are unavailables and if allowed to wash it)
if(!Product::isAvailableWhenOutOfStock($product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) {
foreach($groups as &$group) {
foreach($group['attributes_quantity'] as $key => &$quantity) {
if(!$quantity) {
unset($group['attributes'][$key]);
}
}
}
foreach($colors as $key => $color) {
if(!$color['attributes_quantity']) {
unset($colors[$key]);
}
}
}
foreach($groups as &$group) {
natcasesort($group['attributes']);
}
foreach($combinations as $id_product_attribute => $comb) {
$attributeList = '';
foreach($comb['attributes'] as $id_attribute) {
$attributeList .= '\''.(int) $id_attribute.'\',';
}
$attributeList = rtrim($attributeList, ',');
$combinations[$id_product_attribute]['list'] = $attributeList;
}
$smarty->assign(array(
'groups' => $groups,
'combinaisons' => $combinations, /* Kept for compatibility purpose only */
'combinations' => $combinations,
'colors' => (sizeof($colors) && $product->id_color_default)? $colors: FALSE,
'combinationImages' => $combinationImages,
));
}
$smarty->assign(array(
'cartex' => Module::isInstalled('blockcartex'),
'product' => $product,
'quantity_discounts' => formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $product->id, (int) Shop::getCurrentShop(), (int) $cookie->id_currency, $id_country, $id_group), $product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, FALSE), (float) $tax),
'ecotax_tax_inc' => $ecotaxTaxAmount,
'tax_rate' => $tax,
'ecotax_tax_exc' => Tools::ps_round($product->ecotax, 2),
'ecotaxTax_rate' => $ecotax_rate,
'product_manufacturer' => new Manufacturer((int) $product->id_manufacturer, $cookie->id_lang),
'static_token' => Tools::getToken(FALSE),
'token' => Tools::getToken(),
'lang_iso' => $ps_language->iso_code,
'productPriceWithoutEcoTax' => (float) $productPriceWithoutEcoTax,
'PS_CATALOG_MODE' => (bool) Configuration::get('PS_CATALOG_MODE'),
'allow_oosp' => $product->isAvailableWhenOutOfStock((int) $product->out_of_stock),
'last_qties' => (int) Configuration::get('PS_LAST_QTIES'),
'group_reduction' => (1 - $group_reduction),
'ENT_NOQUOTES' => ENT_NOQUOTES,
'priceDisplay' => Product::getTaxCalculationMethod(),
'roundMode' => (int) Configuration::get('PS_PRICE_ROUND_MODE'),
'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'),
'tax_enabled' => Configuration::get('PS_TAX'),
'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'),
'display_ht' => !Tax::excludeTaxeOption(),
'ecotax' => ($product->ecotax > 0? Tools::convertPrice((float) $product->ecotax): 0),
'currencySign' => $currency->sign,
'currencyRate' => $currency->conversion_rate,
'currencyFormat' => $currency->format,
'currencyBlank' => $currency->blank,
'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
'no_tax' => Tax::excludeTaxeOption() || !Tax::getProductTaxRate((int) $product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}),
'customizationFields' => ($product->customizable? $product->getCustomizationFields((int) $cookie->id_lang): FALSE),
'packItems' => $product->cache_is_pack? Pack::getItemTable($product->id, (int) $cookie->id_lang, TRUE): array(),
'packs' => Pack::getPacksTable($product->id, (int) $cookie->id_lang, TRUE, 1),
'virtual' => ProductDownload::getIdFromIdProduct((int) $product->id),
));
$result = $smarty->fetch(file_exists(_PS_THEME_DIR_.'modules/expresscart/'.$tpl.'.tpl')? '../../themes/'._THEME_NAME_.'/modules/expresscart/'.$tpl.'.tpl': $tpl.'.tpl', __FILE__);
} else {
$smarty->assign('error', 'product_missing');
$result = $smarty->fetch(file_exists(_PS_THEME_DIR_.'modules/expresscart/error.tpl')? '../../themes/'._THEME_NAME_.'/modules/expresscart/error.tpl': 'error.tpl', __FILE__);
}
} else {
$smarty->assign('error', 'product_missing');
$result = $smarty->fetch(file_exists(_PS_THEME_DIR_.'modules/expresscart/error.tpl')? '../../themes/'._THEME_NAME_.'/modules/expresscart/error.tpl': 'error.tpl', __FILE__);
}
echo $result;