public static function getProductProperties($id_lang, $row) { if (!$row['id_product']) { return false; } // Product::getDefaultAttribute is only called if id_product_attribute is missing from the SQL query at the origin of it: consider adding it in order to avoid unnecessary queries $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']); if ((!isset($row['id_product_attribute']) or !$row['id_product_attribute']) and (isset($row['cache_default_attribute']) and ($ipa_default = $row['cache_default_attribute']) !== NULL or $ipa_default = Product::getDefaultAttribute($row['id_product'], !$row['allow_oosp']))) { $row['id_product_attribute'] = $ipa_default; } if (!isset($row['id_product_attribute'])) { $row['id_product_attribute'] = 0; } // Tax $usetax = Tax::excludeTaxeOption(); $cacheKey = $row['id_product'] . '-' . $row['id_product_attribute'] . '-' . $id_lang . '-' . (int) $usetax; if (array_key_exists($cacheKey, self::$producPropertiesCache)) { return self::$producPropertiesCache[$cacheKey]; } // Datas $row['category'] = Category::getLinkRewrite((int) $row['id_category_default'], (int) $id_lang); if (!preg_match("/^1.3.*/", _PS_VERSION_)) { // Not available in Prestashop 1.3.x $row['reduction'] = Product::getPriceStatic((int) $row['id_product'], (bool) $usetax, (int) $row['id_product_attribute'], 6, NULL, true, true, 1, true, NULL, NULL, NULL, $specific_prices); $row['specific_prices'] = $specific_prices; } if ($row['id_product_attribute']) { $row['quantity_all_versions'] = $row['quantity']; $row['quantity'] = Product::getQuantity((int) $row['id_product'], $row['id_product_attribute'], isset($row['cache_is_pack']) ? $row['cache_is_pack'] : NULL); } $row['id_image'] = Product::defineProductImage($row, $id_lang); $row['features'] = Product::getFrontFeaturesStatic((int) $id_lang, $row['id_product']); // Pack management $row['pack'] = !isset($row['cache_is_pack']) ? Pack::isPack($row['id_product']) : (int) $row['cache_is_pack']; $row['packItems'] = $row['pack'] ? Pack::getItemTable($row['id_product'], $id_lang) : array(); $row['nopackprice'] = $row['pack'] ? Pack::noPackPrice($row['id_product']) : 0; if ($row['pack'] and !Pack::isInStock($row['id_product'])) { $row['quantity'] = 0; } $sql_combination = ' SELECT pa.id_product_attribute, pa.price, pa.quantity, pa.id_product FROM `' . _DB_PREFIX_ . 'product` p LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product`) WHERE p.`id_product` =' . $row['id_product']; $result_combination = ProductExtended::getDbInstance()->ExecuteS($sql_combination); $row['combinations'] = array(); if ($result_combination) { foreach ($result_combination as $combination) { $combination['attributes'] = array(); /* New combinations system Prestashop 1.5.x */ if (!preg_match("/^1.(3|4).*/", _PS_VERSION_)) { $combination['quantity'] = StockAvailable::getQuantityAvailableByProduct($row['id_product'], $combination['id_product_attribute']); } if (isset($combination['id_product_attribute'])) { $sql_attribute = ' SELECT pa.id_product_attribute, agl.id_attribute_group, al.name as name_value, agl.name as name_option FROM `' . _DB_PREFIX_ . 'product_attribute` pa LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON (a.`id_attribute` = pac.`id_attribute`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = ' . $id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (agl.`id_attribute_group` = ag.`id_attribute_group` AND agl.`id_lang` = ' . $id_lang . ') WHERE pa.`id_product_attribute` =' . $combination['id_product_attribute']; $result_attribute = ProductExtended::getDbInstance()->ExecuteS($sql_attribute); if ($result_attribute) { foreach ($result_attribute as $attribute) { array_push($combination['attributes'], $attribute); } } array_push($row['combinations'], $combination); } } } $sql_image = ' SELECT DISTINCT i.*, pl.link_rewrite FROM `' . _DB_PREFIX_ . 'product` p LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (p.`id_product` = i.`id_product`) LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product`) WHERE p.`id_product` =' . $row['id_product']; $result_image = ProductExtended::getDbInstance()->ExecuteS($sql_image); $row['images'] = array(); $lang = new Language($id_lang); $row['url_locale'] = $lang->iso_code; if ($result_image) { $link = preg_match("/^1.(3|4).*/", _PS_VERSION_) ? new Link() : Context::getContext()->link; foreach ($result_image as $image) { if (!preg_match("/^1.3.*/", _PS_VERSION_)) { // Image URL gives relative version using 1.3.x- $image['image_url'] = $link->getImageLink($image['link_rewrite'], $image['id_product'] . '-' . $image['id_image']); } array_push($row['images'], $image); } } self::$producPropertiesCache[$cacheKey] = $row; return self::$producPropertiesCache[$cacheKey]; }
public function getTotal() { return ProductExtended::getProducts($_GET['id_category'], NULL, $_GET['id_lang'], NULL, NULL, NULL, NULL, true, NULL); }