本文整理汇总了PHP中Product::defineProductImage方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::defineProductImage方法的具体用法?PHP Product::defineProductImage怎么用?PHP Product::defineProductImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::defineProductImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setProduct
public function setProduct($product, $combination)
{
// create the product
$context = Context::getContext();
$this->give_it_product = new GiveItSdkProduct();
$this->give_it_product->setCurrency($context->currency->iso_code);
$usetax = Product::getTaxCalculationMethod((int) $context->customer->id) != PS_TAX_EXC;
if ($combination['id_product_attribute'] == 0) {
$combination['attributes'] = '';
$image = Product::getCover($product->id);
} else {
$comb = new Combination($combination['id_product_attribute']);
if ($image = $comb->getWsImages()) {
$image = $image[0];
$image['id_image'] = $image['id'];
}
}
$image['id_product'] = $product->id;
$image['id_image'] = Product::defineProductImage($image, Context::getContext()->language->id);
$img_profile = version_compare(_PS_VERSION_, '1.5', '<') ? 'home' : ImageType::getFormatedName('medium');
$image = $image ? $context->link->getImageLink($product->link_rewrite, $image['id_image'], $img_profile) : '';
// first, set the product details.
$this->give_it_product->setProductDetails(array('code' => $product->id . '_' . $combination['id_product_attribute'], 'price' => (int) (Product::getPriceStatic((int) $product->id, $usetax, $combination['id_product_attribute']) * 100), 'name' => $product->name . ($combination['attributes'] ? ' : ' . $combination['attributes'] : ''), 'image' => $image));
$delivery = $this->setDelivery();
// add the delivery option to the product
$this->give_it_product->addBuyerOption($delivery);
//We should validate this product
$this->product_valid = $this->give_it_product->validate();
}
示例2: process
public function process()
{
parent::process();
$hasProduct = false;
$product_list = Tools::getValue('compare_product_list');
$postProducts = isset($product_list) ? rtrim($product_list, '|') : '';
if (!Configuration::get('PS_COMPARATOR_MAX_ITEM')) {
return Tools::redirect('404.php');
}
if ($postProducts) {
$ids = array_unique(explode('|', $postProducts));
if (sizeof($ids) > 0) {
if (sizeof($ids) > Configuration::get('PS_COMPARATOR_MAX_ITEM')) {
$ids = array_slice($ids, 0, Configuration::get('PS_COMPARATOR_MAX_ITEM'));
}
$listProducts = array();
$listFeatures = array();
foreach ($ids as $id) {
$curProduct = new Product((int) $id, true, (int) self::$cookie->id_lang);
if (!Validate::isLoadedObject($curProduct)) {
continue;
}
if (!$curProduct->active) {
unset($ids[$k]);
continue;
}
foreach ($curProduct->getFrontFeatures(self::$cookie->id_lang) as $feature) {
$listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value'];
}
$cover = Product::getCover((int) $id);
$curProduct->id_image = Tools::htmlentitiesUTF8(Product::defineProductImage(array('id_image' => $cover['id_image'], 'id_product' => $id), self::$cookie->id_lang));
$curProduct->allow_oosp = Product::isAvailableWhenOutOfStock($curProduct->out_of_stock);
$listProducts[] = $curProduct;
}
if (sizeof($listProducts) > 0) {
$width = 80 / sizeof($listProducts);
$hasProduct = true;
$ordered_features = Feature::getFeaturesForComparison($ids, self::$cookie->id_lang);
self::$smarty->assign(array('ordered_features' => $ordered_features, 'product_features' => $listFeatures, 'products' => $listProducts, 'link' => new Link(), 'width' => $width, 'homeSize' => Image::getSize('home')));
self::$smarty->assign('HOOK_EXTRA_PRODUCT_COMPARISON', Module::hookExec('extraProductComparison', array('list_ids_product' => $ids)));
}
}
}
self::$smarty->assign('hasProduct', $hasProduct);
}
示例3: getBestSalesLight
public static function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10)
{
global $link;
if ($pageNumber < 0) {
$pageNumber = 0;
}
if ($nbProducts < 1) {
$nbProducts = 10;
}
$groups = FrontController::getCurrentCustomerGroups();
$sqlGroups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`, ps.`quantity` sales, p.`ean13`, p.`upc`, cl.`link_rewrite` category
FROM `' . _DB_PREFIX_ . 'product_sale` ps
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON ps.`id_product` = p.`id_product`
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = ' . (int) $id_lang . ')
WHERE p.`active` = 1
AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `' . _DB_PREFIX_ . 'category_group` cg
LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` ' . $sqlGroups . '
)
ORDER BY sales DESC
LIMIT ' . (int) ($pageNumber * $nbProducts) . ', ' . (int) $nbProducts);
if (!$result) {
return false;
}
foreach ($result as &$row) {
$row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['id_image'] = Product::defineProductImage($row, $id_lang);
}
return $result;
}
示例4: getProducts
/**
* Return cart products
*
* @result array Products
*/
public function getProducts($refresh = false, $id_product = false)
{
if (!$this->id) {
return array();
}
if ($this->_products and !$refresh) {
return $this->_products;
}
$sql = '
SELECT cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, pl.`name`,
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`id_tax`, p.`on_sale`, p.`ecotax`,
p.`quantity`, p.`price`, p.`reduction_price`, p.`reduction_percent`, p.`reduction_from`, p.`reduction_to`, p.`weight`, p.`out_of_stock`, p.`active`, p.`date_add`, p.`date_upd`,
t.`id_tax`, tl.`name` AS tax, t.`rate`, pa.`price` AS price_attribute, pa.`quantity` AS quantity_attribute,
pa.`ecotax` AS ecotax_attr, i.`id_image`, il.`legend`, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id,
IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference,
IF (IFNULL(pa.`weight`, 0) = \'\', p.`weight`, pa.`weight`) AS weight_attribute,
IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13
FROM `' . _DB_PREFIX_ . 'cart_product` cp
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = cp.`id_product`
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . intval($this->id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pa.`id_product_attribute` = cp.`id_product_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = p.`id_tax`)
LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = ' . intval($this->id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_image` pai ON (pai.`id_product_attribute` = cp.`id_product_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = cp.`id_product` AND (IF(pai.`id_image`, pai.`id_image` = i.`id_image`, i.`cover` = 1)))
LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . intval($this->id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . intval($this->id_lang) . ')
WHERE `id_cart` = ' . intval($this->id) . '
' . ($id_product ? ' AND cp.`id_product` = ' . intval($id_product) : '') . '
AND p.`id_product` IS NOT NULL
GROUP BY unique_id
ORDER BY cp.date_add ASC';
$result = Db::getInstance()->ExecuteS($sql);
/* Modify SQL results */
$products = array();
if (empty($result)) {
return array();
}
foreach ($result as $k => $row) {
if (isset($row['ecotax_attr']) and $row['ecotax_attr'] > 0) {
$row['ecotax'] = floatval($row['ecotax_attr']);
}
$row['stock_quantity'] = intval($row['quantity']);
$row['weight'] = $row['weight_attribute'];
$row['quantity'] = intval($row['cart_quantity']);
$row['price'] = Product::getPriceStatic(intval($row['id_product']), false, isset($row['id_product_attribute']) ? intval($row['id_product_attribute']) : NULL, 6, NULL, false, true, intval($row['quantity']));
$row['price_wt'] = Product::getPriceStatic(intval($row['id_product']), true, isset($row['id_product_attribute']) ? intval($row['id_product_attribute']) : NULL, 6, NULL, false, true, intval($row['quantity']));
$row['total'] = $row['price'] * intval($row['quantity']);
$row['total_wt'] = $row['price_wt'] * intval($row['quantity']);
$row['id_image'] = Product::defineProductImage($row);
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
$row['features'] = Product::getFeaturesStatic(intval($row['id_product']));
/* Add attributes to the SQL result if needed */
if (isset($row['id_product_attribute']) and intval($row['id_product_attribute'])) {
$result2 = Db::getInstance()->ExecuteS('
SELECT agl.`public_name` AS public_group_name, al.`name` AS attribute_name
FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac
LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON a.`id_attribute` = pac.`id_attribute`
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . intval($this->id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = ' . intval($this->id_lang) . ')
WHERE pac.`id_product_attribute` = ' . intval($row['id_product_attribute']));
$attributesList = '';
$attributesListSmall = '';
if ($result2) {
foreach ($result2 as $k2 => $row2) {
$attributesList .= $row2['public_group_name'] . ' : ' . $row2['attribute_name'] . ', ';
$attributesListSmall .= $row2['attribute_name'] . ', ';
}
}
$attributesList = rtrim($attributesList, ', ');
$attributesListSmall = rtrim($attributesListSmall, ', ');
$row['attributes'] = $attributesList;
$row['attributes_small'] = $attributesListSmall;
$row['stock_quantity'] = $row['quantity_attribute'];
}
$products[] = $row;
}
$this->_products = $products;
return $this->_products;
}
示例5: getProductProperties
public static function getProductProperties($id_lang, $row, Context $context = null)
{
if (!$row['id_product']) {
return false;
}
if ($context == null) {
$context = Context::getContext();
}
// 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 (Combination::isFeatureActive() && (!isset($row['id_product_attribute']) || !$row['id_product_attribute']) && (isset($row['cache_default_attribute']) && ($ipa_default = $row['cache_default_attribute']) !== null || ($ipa_default = Product::getDefaultAttribute($row['id_product'], !$row['allow_oosp'])))) {
$row['id_product_attribute'] = $ipa_default;
}
if (!Combination::isFeatureActive() || !isset($row['id_product_attribute'])) {
$row['id_product_attribute'] = 0;
}
// Tax
$usetax = Tax::excludeTaxeOption();
$cache_key = $row['id_product'] . '-' . $row['id_product_attribute'] . '-' . $id_lang . '-' . (int) $usetax;
if (isset($row['id_product_pack'])) {
$cache_key .= '-pack' . $row['id_product_pack'];
}
if (isset(self::$producPropertiesCache[$cache_key])) {
return self::$producPropertiesCache[$cache_key];
}
// Datas
$row['category'] = Category::getLinkRewrite((int) $row['id_category_default'], (int) $id_lang);
$row['link'] = $context->link->getProductLink((int) $row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['attribute_price'] = 0;
if (isset($row['id_product_attribute']) && $row['id_product_attribute']) {
$row['attribute_price'] = (double) Product::getProductAttributePrice($row['id_product_attribute']);
}
$row['price_tax_exc'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) && !empty($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, self::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6);
if (self::$_taxCalculationMethod == PS_TAX_EXC) {
$row['price_tax_exc'] = Tools::ps_round($row['price_tax_exc'], 2);
$row['price'] = Product::getPriceStatic((int) $row['id_product'], true, isset($row['id_product_attribute']) && !empty($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6);
$row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) && !empty($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 2, null, false, false);
} else {
$row['price'] = Tools::ps_round(Product::getPriceStatic((int) $row['id_product'], true, isset($row['id_product_attribute']) && !empty($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 2), 2);
$row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, isset($row['id_product_attribute']) && !empty($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, false);
}
$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);
} else {
$row['quantity'] = Product::getQuantity((int) $row['id_product']);
}
$row['id_image'] = Product::defineProductImage($row, $id_lang);
$row['features'] = Product::getFrontFeaturesStatic((int) $id_lang, $row['id_product']);
$row['attachments'] = array();
if (!isset($row['cache_has_attachments']) || $row['cache_has_attachments']) {
$row['attachments'] = Product::getAttachmentsStatic((int) $id_lang, $row['id_product']);
}
$row['virtual'] = !isset($row['is_virtual']) || $row['is_virtual'] ? 1 : 0;
// 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'] && !Pack::isInStock($row['id_product'])) {
$row['quantity'] = 0;
}
self::$producPropertiesCache[$cache_key] = $row;
return self::$producPropertiesCache[$cache_key];
}
示例6: getImage
private function getImage($id_product, $id_image, $link_rewrite)
{
$id_image = Product::defineProductImage(array('id_image' => $id_image, 'id_product' => $id_product), $this->context->language->id);
$img_profile = version_compare(_PS_VERSION_, '1.5', '<') ? 'small' : ImageType::getFormatedName('small');
$image_link = $this->context->link->getImageLink($link_rewrite, $id_image, $img_profile);
if (!$image_link) {
return $this->module_instance->l('Image');
} else {
return $image_link;
}
}
示例7: getProductProperties
public static function getProductProperties($id_lang, $row)
{
if (!$row['id_product']) {
return false;
}
$link = new Link();
// Tax
$usetax = true;
$tax = floatval(Tax::getApplicableTax(intval($row['id_tax']), floatval($row['rate'])));
if (Tax::excludeTaxeOption() or !$tax) {
$usetax = false;
}
// Datas
$row['category'] = Category::getLinkRewrite($row['id_category_default'], intval($id_lang));
$row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
if ((!isset($row['id_product_attribute']) or !$row['id_product_attribute']) and $ipa_default = Product::getDefaultAttribute($row['id_product'], !$row['allow_oosp'])) {
$row['id_product_attribute'] = $ipa_default;
}
$row['attribute_price'] = isset($row['id_product_attribute']) and $row['id_product_attribute'] ? floatval(Product::getProductAttributePrice($row['id_product_attribute'])) : 0;
$row['price_tax_exc'] = Product::getPriceStatic($row['id_product'], false, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 2);
$row['price'] = Product::getPriceStatic($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 2);
$row['reduction'] = self::getReductionValue($row['reduction_price'], $row['reduction_percent'], $row['reduction_from'], $row['reduction_to'], $row['price'], $usetax, floatval($row['rate']));
$row['price_without_reduction'] = Product::getPriceStatic($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 2, NULL, false, false);
$row['quantity'] = Product::getQuantity($row['id_product']);
$row['id_image'] = Product::defineProductImage($row);
$row['features'] = Product::getFrontFeaturesStatic(intval($id_lang), $row['id_product']);
$row['attachments'] = Product::getAttachmentsStatic(intval($id_lang), $row['id_product']);
$row['pack'] = Pack::isPack($row['id_product']);
$row['packItems'] = $row['pack'] ? Pack::getItemTable($row['id_product'], $id_lang) : array();
$row['nopackprice'] = $row['pack'] ? Pack::noPackPrice($row['id_product']) : 0;
return $row;
}
示例8: initContent
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
//Clean compare product table
CompareProduct::cleanCompareProducts('week');
$hasProduct = false;
if (!Configuration::get('PS_COMPARATOR_MAX_ITEM')) {
return Tools::redirect('index.php?controller=404');
}
if (($product_list = Tools::getValue('compare_product_list')) && ($postProducts = isset($product_list) ? rtrim($product_list, '|') : '')) {
$ids = array_unique(explode('|', $postProducts));
} else {
if (isset($this->context->cookie->id_compare)) {
$ids = CompareProduct::getCompareProducts($this->context->cookie->id_compare);
} else {
$ids = null;
}
}
if ($ids) {
if (count($ids) > 0) {
if (count($ids) > Configuration::get('PS_COMPARATOR_MAX_ITEM')) {
$ids = array_slice($ids, 0, Configuration::get('PS_COMPARATOR_MAX_ITEM'));
}
$listProducts = array();
$listFeatures = array();
foreach ($ids as $k => &$id) {
$curProduct = new Product((int) $id, true, $this->context->language->id);
if (!Validate::isLoadedObject($curProduct) || !$curProduct->active || !$curProduct->isAssociatedToShop()) {
if (isset($this->context->cookie->id_compare)) {
CompareProduct::removeCompareProduct($this->context->cookie->id_compare, $id);
}
unset($ids[$k]);
continue;
}
foreach ($curProduct->getFrontFeatures($this->context->language->id) as $feature) {
$listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value'];
}
$cover = Product::getCover((int) $id);
$curProduct->id_image = Tools::htmlentitiesUTF8(Product::defineProductImage(array('id_image' => $cover['id_image'], 'id_product' => $id), $this->context->language->id));
$curProduct->allow_oosp = Product::isAvailableWhenOutOfStock($curProduct->out_of_stock);
$listProducts[] = $curProduct;
}
if (count($listProducts) > 0) {
$width = 80 / count($listProducts);
$hasProduct = true;
$ordered_features = Feature::getFeaturesForComparison($ids, $this->context->language->id);
$this->context->smarty->assign(array('ordered_features' => $ordered_features, 'product_features' => $listFeatures, 'products' => $listProducts, 'width' => $width, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
$this->context->smarty->assign('HOOK_EXTRA_PRODUCT_COMPARISON', Hook::exec('displayProductComparison', array('list_ids_product' => $ids)));
} else {
if (isset($this->context->cookie->id_compare)) {
$object = new CompareProduct((int) $this->context->cookie->id_compare);
if (Validate::isLoadedObject($object)) {
$object->delete();
}
}
}
}
}
$this->context->smarty->assign('hasProduct', $hasProduct);
$this->setTemplate(_PS_THEME_DIR_ . 'products-comparison.tpl');
}
示例9: getProductProperties
public static function getProductProperties($id_lang, $row)
{
if (!$row['id_product']) {
return false;
}
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
if ((!isset($row['id_product_attribute']) or !$row['id_product_attribute']) and $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 = true;
$tax = floatval(Tax::getApplicableTax(intval($row['id_tax']), floatval($row['rate'])));
if (Tax::excludeTaxeOption() or !$tax) {
$usetax = false;
}
$cacheKey = $row['id_product'] . '-' . $row['id_product_attribute'] . '-' . $id_lang . '-' . intval($usetax);
if (array_key_exists($cacheKey, self::$producPropertiesCache)) {
return self::$producPropertiesCache[$cacheKey];
}
// Datas
$link = new Link();
$row['category'] = Category::getLinkRewrite($row['id_category_default'], intval($id_lang));
$row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['attribute_price'] = (isset($row['id_product_attribute']) and $row['id_product_attribute']) ? floatval(Product::getProductAttributePrice($row['id_product_attribute'])) : 0;
$row['price_tax_exc'] = Product::getPriceStatic($row['id_product'], false, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 6);
if (self::$_taxCalculationMethod == PS_TAX_EXC) {
$row['price_tax_exc'] = Tools::ps_round($row['price_tax_exc'], 2);
$row['price'] = Product::getPriceStatic($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 6);
} else {
$row['price'] = Tools::ps_round(Product::getPriceStatic($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 6), 2);
}
$row['reduction'] = self::getReductionValue($row['reduction_price'], $row['reduction_percent'], $row['reduction_from'], $row['reduction_to'], $row['price'], $usetax, floatval($row['rate']));
$row['price_without_reduction'] = Product::getPriceStatic($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 6, NULL, false, false);
$row['quantity'] = Product::getQuantity($row['id_product']);
$row['id_image'] = Product::defineProductImage($row);
$row['features'] = Product::getFrontFeaturesStatic(intval($id_lang), $row['id_product']);
$row['attachments'] = Product::getAttachmentsStatic(intval($id_lang), $row['id_product']);
$row['pack'] = Pack::isPack($row['id_product']);
$row['packItems'] = $row['pack'] ? Pack::getItemTable($row['id_product'], $id_lang) : array();
$row['nopackprice'] = $row['pack'] ? Pack::noPackPrice($row['id_product']) : 0;
self::$producPropertiesCache[$cacheKey] = $row;
return self::$producPropertiesCache[$cacheKey];
}
示例10: getProductProperties
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];
}
示例11: getBestSalesLight
public static function getBestSalesLight($id_lang, $page_number = 0, $nb_products = 10, Context $context = null)
{
if (!$context) {
$context = Context::getContext();
}
if ($page_number < 0) {
$page_number = 0;
}
if ($nb_products < 1) {
$nb_products = 10;
}
$groups = FrontController::getCurrentCustomerGroups();
$sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
//Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage
$sql = 'SELECT cp.`id_product`
FROM `' . _DB_PREFIX_ . 'category_group` cg
INNER JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cp.`id_product` IS NOT NULL AND cg.`id_group` ' . $sql_groups . ' AND cp.`id_product` IS NOT NULL';
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
$ids = array();
foreach ($products as $product) {
$ids[$product['id_product']] = 1;
}
$ids = array_keys($ids);
sort($ids);
$ids = array_filter($ids);
$ids = count($ids) > 0 ? implode(',', $ids) : 'NULL';
//Main query
$sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`,
ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, p.quantity, p.customizable,
IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, p.out_of_stock
FROM `' . _DB_PREFIX_ . 'product_sale` ps
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON ps.`id_product` = p.`id_product`
' . Shop::addSqlAssociation('product', 'p') . '
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (ps.`id_product` = pa.`id_product` AND pa.default_on = 1)
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl
ON p.`id_product` = pl.`id_product`
AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl
ON cl.`id_category` = product_shop.`id_category_default`
AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . '
WHERE product_shop.`active` = 1
AND p.`visibility` != \'none\'
AND p.`id_product` IN (' . $ids . ')
GROUP BY product_shop.id_product
ORDER BY sales DESC
LIMIT ' . (int) ($page_number * $nb_products) . ', ' . (int) $nb_products;
if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))) {
return false;
}
foreach ($result as &$row) {
$row['link'] = $context->link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['id_image'] = Product::defineProductImage($row, $id_lang);
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
$row['price_tax_exc'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) && !empty($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, Product::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6);
}
return $result;
}
示例12: getProductProperties
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 mbj
$link = new Link();
$row['category'] = Category::getLinkRewrite((int) $row['id_category_default'], (int) $id_lang);
$row['link'] = $link->getProductLink((int) $row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
//usado link
//init
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT p.*
FROM `' . _DB_PREFIX_ . 'product` p
INNER JOIN ' . _DB_PREFIX_ . 'product_lang pl ON p.id_product = pl.id_product
WHERE p.id_product = ' . (int) $ro1w['supplier_reference']) as $subrow) {
$row_us['id_category_default'] = $subrow['id_category_default'];
$row_us['link_rewrite'] = $subrow['link_rewrite'];
$row_us['ean13'] = $subrow['ean13'];
}
$row['category_used'] = Category::getLinkRewrite((int) $row_us['id_category_default'], (int) $id_lang);
$row['link_used'] = $link->getProductLink((int) $row['supplier_reference'], $row_us['link_rewrite'], $row['category_used'], $row_us['ean13']);
$row['link_extr'] = 'id::' . $row['id_product'];
//precio mall - distribuidor - lista - internet
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT pa.price
FROM `' . _DB_PREFIX_ . 'product_attribute` pa
INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute
WHERE pac.id_attribute = 25 and pa.id_product = ' . (int) $row['id_product']) as $subrow) {
$row['price_distribuidor_p'] = round($subrow['price']);
}
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT pa.price
FROM `' . _DB_PREFIX_ . 'product_attribute` pa
INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute
WHERE pac.id_attribute = 24 and pa.id_product = ' . (int) $row['id_product']) as $subrow) {
$row['price_distribuidor'] = round($subrow['price']);
}
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT pa.price
FROM `' . _DB_PREFIX_ . 'product_attribute` pa
INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute
WHERE pac.id_attribute = 23 and pa.id_product = ' . (int) $row['id_product']) as $subrow) {
$row['price_tienda'] = round($subrow['price']);
}
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT pa.price
FROM `' . _DB_PREFIX_ . 'product_attribute` pa
INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute
WHERE pac.id_attribute = 22 and pa.id_product = ' . (int) $row['id_product']) as $subrow) {
$row['price_mall'] = round($subrow['price']);
}
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT pa.price
FROM `' . _DB_PREFIX_ . 'product_attribute` pa
INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute
WHERE pac.id_attribute = 21 and pa.id_product = ' . (int) $row['id_product']) as $subrow) {
$row['price_internet'] = round($subrow['price']);
}
$row['attribute_price'] = (isset($row['id_product_attribute']) and $row['id_product_attribute']) ? (double) Product::getProductAttributePrice($row['id_product_attribute']) : 0;
$row['price_tax_exc'] = Product::getPriceStatic((int) $row['id_product'], false, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, self::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6);
if (self::$_taxCalculationMethod == PS_TAX_EXC) {
$row['price_tax_exc'] = Tools::ps_round($row['price_tax_exc'], 2);
$row['price'] = Product::getPriceStatic((int) $row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, 6);
$row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], false, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, 2, NULL, false, false);
} else {
$row['price'] = Tools::ps_round(Product::getPriceStatic((int) $row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, 2), 2);
$row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, 6, NULL, false, false);
}
$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']);
$row['attachments'] = (!isset($row['cache_has_attachments']) or $row['cache_has_attachments']) ? Product::getAttachmentsStatic((int) $id_lang, $row['id_product']) : array();
// 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;
}
self::$producPropertiesCache[$cacheKey] = $row;
//.........这里部分代码省略.........
示例13: getBestSalesLight
public static function getBestSalesLight($id_lang, $page_number = 0, $nb_products = 10, Context $context = null)
{
$agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p", true);
if (!$context) {
$context = Context::getContext();
}
if ($page_number < 0) {
$page_number = 0;
}
if ($nb_products < 1) {
$nb_products = 10;
}
$groups = FrontController::getCurrentCustomerGroups();
$sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
$sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`,
stock.out_of_stock,
MAX(product_attribute_shop.id_product_attribute) id_product_attribute,
p.available_for_order,
p.customizable,
product_shop.id_category_default,
IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity,
ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category
' . $agile_sql_parts['selects'] . '
FROM `' . _DB_PREFIX_ . 'product_sale` ps
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON ps.`id_product` = p.`id_product`
' . $agile_sql_parts['joins'] . '
' . Shop::addSqlAssociation('product', 'p') . '
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa
ON (p.`id_product` = pa.`id_product`)
' . Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') . '
' . Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) . '
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl
ON p.`id_product` = pl.`id_product`
AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl
ON cl.`id_category` = product_shop.`id_category_default`
AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . '
WHERE product_shop.`active` = 1
' . $agile_sql_parts['wheres'] . '
AND p.`visibility` != \'none\'
AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `' . _DB_PREFIX_ . 'category_group` cg
LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` ' . $sql_groups . '
)
GROUP BY product_shop.id_product
ORDER BY sales DESC
LIMIT ' . (int) ($page_number * $nb_products) . ', ' . (int) $nb_products;
if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))) {
return false;
}
$result = Product::getProductsProperties($id_lang, $result);
foreach ($result as &$row) {
$row['link'] = $context->link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['id_image'] = Product::defineProductImage($row, $id_lang);
}
$result = AgileSellerManager::prepareSellerRattingInfo($result);
return $result;
}
示例14: getProducts
/**
* Return cart products
*
* @result array Products
*/
public function getProducts($refresh = false, $id_product = false)
{
if (!$this->id) {
return array();
}
if ($this->_products and !$refresh) {
return $this->_products;
}
$sql = '
SELECT cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, pl.`name`,
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`id_tax`, p.`on_sale`, p.`ecotax`,
p.`quantity`, p.`price`, p.`reduction_price`, p.`reduction_percent`, p.`reduction_from`, p.`reduction_to`, p.`weight`, p.`out_of_stock`, p.`active`, p.`date_add`, p.`date_upd`,
t.`id_tax`, tl.`name` AS tax, t.`rate`, pa.`price` AS price_attribute, pa.`quantity` AS quantity_attribute,
pa.`ecotax` AS ecotax_attr, i.`id_image`, il.`legend`, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id,
IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference,
(p.`weight`+ pa.`weight`) weight_attribute,
IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13, pai.`id_image` AS \'pai_id_image\'
FROM `' . _DB_PREFIX_ . 'cart_product` cp
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = cp.`id_product`
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . intval($this->id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pa.`id_product_attribute` = cp.`id_product_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = p.`id_tax`)
LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = ' . intval($this->id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_image` pai ON (pai.`id_product_attribute` = pa.`id_product_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (IF(pai.`id_image`,
i.`id_image` =
(SELECT i2.`id_image`
FROM `' . _DB_PREFIX_ . 'image` i2
INNER JOIN `' . _DB_PREFIX_ . 'product_attribute_image` pai2 ON (pai2.`id_image` = i2.`id_image`)
WHERE i2.`id_product` = p.`id_product` AND pai2.`id_product_attribute` = pa.`id_product_attribute`
ORDER BY i2.`position`
LIMIT 1),
i.`id_product` = p.`id_product` AND i.`cover` = 1)
)
LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . intval($this->id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . intval($this->id_lang) . ')
WHERE `id_cart` = ' . intval($this->id) . '
' . ($id_product ? ' AND cp.`id_product` = ' . intval($id_product) : '') . '
AND p.`id_product` IS NOT NULL
GROUP BY unique_id
ORDER BY cp.date_add ASC';
$result = Db::getInstance()->ExecuteS($sql);
if (empty($result)) {
return array();
}
/* Modify SQL results */
$this->_products = array();
foreach ($result as $k => $row) {
if (isset($row['ecotax_attr']) and $row['ecotax_attr'] > 0) {
$row['ecotax'] = floatval($row['ecotax_attr']);
}
$row['stock_quantity'] = intval($row['quantity']);
// for compatibility with 1.2 themes
$row['quantity'] = intval($row['cart_quantity']);
if ($row['id_product_attribute']) {
$row['weight'] = $row['weight_attribute'];
}
if ($this->_taxCalculationMethod == PS_TAX_EXC) {
$row['price'] = Product::getPriceStatic(intval($row['id_product']), false, isset($row['id_product_attribute']) ? intval($row['id_product_attribute']) : NULL, 2, NULL, false, true, intval($row['cart_quantity']), false, intval($this->id_customer) ? intval($this->id_customer) : NULL, intval($this->id), intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL);
// Here taxes are computed only once the quantity has been applied to the product price
$row['price_wt'] = Product::getPriceStatic(intval($row['id_product']), true, isset($row['id_product_attribute']) ? intval($row['id_product_attribute']) : NULL, 2, NULL, false, true, intval($row['cart_quantity']), false, intval($this->id_customer) ? intval($this->id_customer) : NULL, intval($this->id), intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL);
$row['total_wt'] = Tools::ps_round($row['price'] * floatval($row['cart_quantity']) * (1 + floatval($row['rate']) / 100), 2);
$row['total'] = $row['price'] * intval($row['cart_quantity']);
} else {
$row['price'] = Product::getPriceStatic(intval($row['id_product']), false, intval($row['id_product_attribute']), 6, NULL, false, true, $row['cart_quantity'], false, intval($this->id_customer) ? intval($this->id_customer) : NULL, intval($this->id), intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL);
$row['price_wt'] = Product::getPriceStatic(intval($row['id_product']), true, intval($row['id_product_attribute']), 2, NULL, false, true, $row['cart_quantity'], false, intval($this->id_customer) ? intval($this->id_customer) : NULL, intval($this->id), intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL);
/* In case when you use QuantityDiscount, getPriceStatic() can be return more of 2 decimals */
$row['price_wt'] = Tools::ps_round($row['price_wt'], 2);
$row['total_wt'] = $row['price_wt'] * intval($row['cart_quantity']);
$row['total'] = Tools::ps_round($row['price'] * intval($row['cart_quantity']), 2);
}
$row['id_image'] = Product::defineProductImage($row);
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
$row['features'] = Product::getFeaturesStatic(intval($row['id_product']));
/* Add attributes to the SQL result if needed */
if (isset($row['id_product_attribute']) and intval($row['id_product_attribute'])) {
$result2 = Db::getInstance()->ExecuteS('
SELECT agl.`public_name` AS public_group_name, al.`name` AS attribute_name
FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac
LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON a.`id_attribute` = pac.`id_attribute`
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . intval($this->id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = ' . intval($this->id_lang) . ')
WHERE pac.`id_product_attribute` = ' . intval($row['id_product_attribute']));
$attributesList = '';
$attributesListSmall = '';
if ($result2) {
foreach ($result2 as $k2 => $row2) {
$attributesList .= $row2['public_group_name'] . ' : ' . $row2['attribute_name'] . ', ';
$attributesListSmall .= $row2['attribute_name'] . ', ';
}
}
//.........这里部分代码省略.........
示例15: getProductProperties
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
$link = new Link();
$row['category'] = Category::getLinkRewrite((int) $row['id_category_default'], (int) $id_lang);
$row['link'] = $link->getProductLink((int) $row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['attribute_price'] = (isset($row['id_product_attribute']) and $row['id_product_attribute']) ? (double) Product::getProductAttributePrice($row['id_product_attribute']) : 0;
$row['price_tax_exc'] = Product::getPriceStatic((int) $row['id_product'], false, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, self::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6);
if (self::$_taxCalculationMethod == PS_TAX_EXC) {
$row['price_tax_exc'] = Tools::ps_round($row['price_tax_exc'], 2);
$row['price'] = Product::getPriceStatic((int) $row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, 6);
$row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], false, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, 2, NULL, false, false);
} else {
$row['price'] = Tools::ps_round(Product::getPriceStatic((int) $row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, 2), 2);
$row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) $row['id_product_attribute'] : NULL, 6, NULL, false, false);
}
$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']);
$row['attachments'] = (!isset($row['cache_has_attachments']) or $row['cache_has_attachments']) ? Product::getAttachmentsStatic((int) $id_lang, $row['id_product']) : array();
// 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;
}
self::$producPropertiesCache[$cacheKey] = $row;
return self::$producPropertiesCache[$cacheKey];
}