本文整理汇总了PHP中Product::getDefaultAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getDefaultAttribute方法的具体用法?PHP Product::getDefaultAttribute怎么用?PHP Product::getDefaultAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::getDefaultAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getItems
/**
* Get product accessories
*
* @param integer $id_lang Language id
* @return array Product accessories
*/
public static function getItems($iIdProduct, $id_lang, $active = true, Context $context = null)
{
if (!$context) {
$context = Context::getContext();
}
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`,
pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`,
MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` as manufacturer_name, cl.`name` AS category_default,
DATEDIFF(
p.`date_add`,
DATE_SUB(
NOW(),
INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY
)
) > 0 AS new
FROM `' . _DB_PREFIX_ . 'now_ideas_or_tips`
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = `id_product_2`
' . Shop::addSqlAssociation('product', 'p') . '
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_ . 'category_lang` cl ON (
product_shop.`id_category_default` = cl.`id_category`
AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . '
)
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_ . 'manufacturer` m ON (p.`id_manufacturer`= m.`id_manufacturer`)
' . Product::sqlStock('p', 0) . '
WHERE `id_product_1` = ' . (int) $iIdProduct . ($active ? ' AND product_shop.`active` = 1 AND product_shop.`visibility` != \'none\'' : '') . '
GROUP BY product_shop.id_product';
if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))) {
return false;
}
foreach ($result as &$row) {
$row['id_product_attribute'] = Product::getDefaultAttribute((int) $row['id_product']);
}
return Product::getProductsProperties($id_lang, $result);
}
示例2: updateQuantity
/**
* For a given id_product and id_product_attribute updates the quantity available
*
* @param int $id_product
* @param int $id_product_attribute Optional
* @param int $delta_quantity The delta quantity to update
* @param int $id_shop Optional
*/
public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_shop = null)
{
if (!Validate::isUnsignedId($id_product)) {
return false;
}
$id_stock_available = StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
if (!$id_stock_available) {
return false;
}
// Update quantity of the pack products
if (Pack::isPack($id_product)) {
$products_pack = Pack::getItems($id_product, (int) Configuration::get('PS_LANG_DEFAULT'));
foreach ($products_pack as $product_pack) {
$pack_id_product_attribute = Product::getDefaultAttribute($product_pack->id, 1);
StockAvailable::updateQuantity($product_pack->id, $pack_id_product_attribute, $product_pack->pack_quantity * $delta_quantity, $id_shop);
}
}
$stock_available = new StockAvailable($id_stock_available);
$stock_available->quantity = $stock_available->quantity + $delta_quantity;
$stock_available->update();
Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity));
}
示例3: calcProductDisplayPrice
public static function calcProductDisplayPrice($product, $product_properties = null, $price = null, $mode = null)
{
$key = null;
$product_object = self::productAsObject($product);
if ($product_object != null) {
if ($product_properties === null) {
$product_properties = PP::getProductProperties($product_object);
}
$display_retail_price = ($product_properties['pp_display_mode'] & 2) == 2 && (($product_properties['pp_display_mode'] & 1) == 1 && $mode != 'unit_price' || !(($product_properties['pp_display_mode'] & 1) == 1) && $mode == 'unit_price');
if ($display_retail_price) {
$price = Product::getRetailPrice($product_object);
} elseif (($product_properties['pp_display_mode'] & 1) == 1) {
if ($product_object->unit_price_ratio > 0) {
if ($price === null) {
$price = self::calcProductPrice($product_object);
}
if ($mode == 'unit_price') {
$price = Tools::ps_round((double) $price * $product_object->unit_price_ratio, _PS_PRICE_COMPUTE_PRECISION_);
} else {
if (is_array($product) && isset($product['price_tax_exc']) && $product['price_tax_exc'] > 0 && round($price, 8) > round($product['price_tax_exc'], 8)) {
$tax = $price / $product['price_tax_exc'];
}
// we use $product_object->price because unit price is calculated based on the base price, without attribute impact on the price
$price = Tools::ps_round($product_object->price / $product_object->unit_price_ratio, _PS_PRICE_COMPUTE_PRECISION_);
if (($attribute = Product::getDefaultAttribute($product_object->id)) > 0) {
$combination = $product_object->getAttributeCombinationsById($attribute, Context::getContext()->language->id);
$price += Tools::ps_round($combination[0]['unit_price_impact'], _PS_PRICE_COMPUTE_PRECISION_);
}
if (isset($tax)) {
$price = Tools::ps_round($price * $tax, _PS_PRICE_COMPUTE_PRECISION_);
}
}
}
}
if (($product_properties['pp_display_mode'] & 1) == 1) {
if ($mode == 'unit_price') {
if (!empty($product_properties['pp_price_text'])) {
$key = 'pp_price_text';
}
} else {
if (!empty($product_properties['pp_unity_text'])) {
$key = 'pp_unity_text';
}
}
} else {
if ($mode == 'unit_price') {
if (!empty($product_properties['pp_unity_text'])) {
$key = 'pp_unity_text';
}
} else {
if (!empty($product_properties['pp_price_text'])) {
$key = 'pp_price_text';
}
}
}
if ($price === null) {
$price = self::calcProductPrice($product_object);
}
}
return array($key, $price);
}
示例4: removeProduct
/**
* @see StockManagerInterface::removeProduct()
*/
public function removeProduct($id_product, $id_product_attribute = null, Warehouse $warehouse, $quantity, $id_stock_mvt_reason, $is_usable = true, $id_order = null)
{
$return = array();
if (!Validate::isLoadedObject($warehouse) || !$quantity || !$id_product) {
return $return;
}
if (!StockMvtReason::exists($id_stock_mvt_reason)) {
$id_stock_mvt_reason = Configuration::get('PS_STOCK_MVT_DEC_REASON_DEFAULT');
}
$context = Context::getContext();
// Special case of a pack
if (Pack::isPack((int) $id_product)) {
// Gets items
$products_pack = Pack::getItems((int) $id_product, (int) Configuration::get('PS_LANG_DEFAULT'));
// Foreach item
foreach ($products_pack as $product_pack) {
$pack_id_product_attribute = Product::getDefaultAttribute($product_pack->id, 1);
if ($product_pack->advanced_stock_management == 1) {
$this->removeProduct($product_pack->id, $pack_id_product_attribute, $warehouse, $product_pack->pack_quantity * $quantity, $id_stock_mvt_reason, $is_usable, $id_order);
}
}
} else {
// gets total quantities in stock for the current product
$physical_quantity_in_stock = (int) $this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), false);
$usable_quantity_in_stock = (int) $this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), true);
// check quantity if we want to decrement unusable quantity
if (!$is_usable) {
$quantity_in_stock = $physical_quantity_in_stock - $usable_quantity_in_stock;
} else {
$quantity_in_stock = $usable_quantity_in_stock;
}
// checks if it's possible to remove the given quantity
if ($quantity_in_stock < $quantity) {
return $return;
}
$stock_collection = $this->getStockCollection($id_product, $id_product_attribute, $warehouse->id);
$stock_collection->getAll();
// check if the collection is loaded
if (count($stock_collection) <= 0) {
return $return;
}
$stock_history_qty_available = array();
$mvt_params = array();
$stock_params = array();
$quantity_to_decrement_by_stock = array();
$global_quantity_to_decrement = $quantity;
// switch on MANAGEMENT_TYPE
switch ($warehouse->management_type) {
// case CUMP mode
case 'WA':
// There is one and only one stock for a given product in a warehouse in this mode
$stock = $stock_collection->current();
$mvt_params = array('id_stock' => $stock->id, 'physical_quantity' => $quantity, 'id_stock_mvt_reason' => $id_stock_mvt_reason, 'id_order' => $id_order, 'price_te' => $stock->price_te, 'last_wa' => $stock->price_te, 'current_wa' => $stock->price_te, 'id_employee' => $context->employee->id, 'employee_firstname' => $context->employee->firstname, 'employee_lastname' => $context->employee->lastname, 'sign' => -1);
$stock_params = array('physical_quantity' => $stock->physical_quantity - $quantity, 'usable_quantity' => $is_usable ? $stock->usable_quantity - $quantity : $stock->usable_quantity);
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->update();
// saves stock mvt
$stock_mvt = new StockMvt();
$stock_mvt->hydrate($mvt_params);
$stock_mvt->save();
$return[$stock->id]['quantity'] = $quantity;
$return[$stock->id]['price_te'] = $stock->price_te;
break;
case 'LIFO':
case 'FIFO':
// for each stock, parse its mvts history to calculate the quantities left for each positive mvt,
// according to the instant available quantities for this stock
foreach ($stock_collection as $stock) {
$left_quantity_to_check = $stock->physical_quantity;
if ($left_quantity_to_check <= 0) {
continue;
}
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->query('
SELECT sm.`id_stock_mvt`, sm.`date_add`, sm.`physical_quantity`,
IF ((sm2.`physical_quantity` is null), sm.`physical_quantity`, (sm.`physical_quantity` - SUM(sm2.`physical_quantity`))) as qty
FROM `' . _DB_PREFIX_ . 'stock_mvt` sm
LEFT JOIN `' . _DB_PREFIX_ . 'stock_mvt` sm2 ON sm2.`referer` = sm.`id_stock_mvt`
WHERE sm.`sign` = 1
AND sm.`id_stock` = ' . (int) $stock->id . '
GROUP BY sm.`id_stock_mvt`
ORDER BY sm.`date_add` DESC');
while ($row = Db::getInstance()->nextRow($resource)) {
// break - in FIFO mode, we have to retreive the oldest positive mvts for which there are left quantities
if ($warehouse->management_type == 'FIFO') {
if ($row['qty'] == 0) {
break;
}
}
// converts date to timestamp
$date = new DateTime($row['date_add']);
$timestamp = $date->format('U');
// history of the mvt
$stock_history_qty_available[$timestamp] = array('id_stock' => $stock->id, 'id_stock_mvt' => (int) $row['id_stock_mvt'], 'qty' => (int) $row['qty']);
// break - in LIFO mode, checks only the necessary history to handle the global quantity for the current stock
if ($warehouse->management_type == 'LIFO') {
$left_quantity_to_check -= (int) $row['physical_quantity'];
//.........这里部分代码省略.........
示例5: processChangeProductInCart
/**
* This process add or update a product in the cart
*/
protected function processChangeProductInCart()
{
$mode = Tools::getIsset('update') && $this->id_product ? 'update' : 'add';
if ($this->qty == 0) {
$this->errors[] = Tools::displayError('Null quantity.', !Tools::getValue('ajax'));
} elseif (!$this->id_product) {
$this->errors[] = Tools::displayError('Product not found', !Tools::getValue('ajax'));
}
$product = new Product($this->id_product, true, $this->context->language->id);
if (!$product->id || !$product->active || !$product->checkAccess($this->context->cart->id_customer)) {
$this->errors[] = Tools::displayError('This product is no longer available.', !Tools::getValue('ajax'));
return;
}
$qty_to_check = $this->qty;
$cart_products = $this->context->cart->getProducts();
if (is_array($cart_products)) {
foreach ($cart_products as $cart_product) {
if ((!isset($this->id_product_attribute) || $cart_product['id_product_attribute'] == $this->id_product_attribute) && (isset($this->id_product) && $cart_product['id_product'] == $this->id_product)) {
$qty_to_check = $cart_product['cart_quantity'];
if (Tools::getValue('op', 'up') == 'down') {
$qty_to_check -= $this->qty;
} else {
$qty_to_check += $this->qty;
}
break;
}
}
}
// Check product quantity availability
if ($this->id_product_attribute) {
if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) {
$this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax'));
}
} elseif ($product->hasAttributes()) {
$minimumQuantity = $product->out_of_stock == 2 ? !Configuration::get('PS_ORDER_OUT_OF_STOCK') : !$product->out_of_stock;
$this->id_product_attribute = Product::getDefaultAttribute($product->id, $minimumQuantity);
// @todo do something better than a redirect admin !!
if (!$this->id_product_attribute) {
Tools::redirectAdmin($this->context->link->getProductLink($product));
} elseif (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) {
$this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax'));
}
} elseif (!$product->checkQty($qty_to_check)) {
$this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax'));
}
// If no errors, process product addition
if (!$this->errors && $mode == 'add') {
// Add cart if no cart found
if (!$this->context->cart->id) {
if (Context::getContext()->cookie->id_guest) {
$guest = new Guest(Context::getContext()->cookie->id_guest);
$this->context->cart->mobile_theme = $guest->mobile_theme;
}
$this->context->cart->add();
if ($this->context->cart->id) {
$this->context->cookie->id_cart = (int) $this->context->cart->id;
}
}
// Check customizable fields
if (!$product->hasAllRequiredCustomizableFields() && !$this->customization_id) {
$this->errors[] = Tools::displayError('Please fill in all of the required fields, and then save your customizations.', !Tools::getValue('ajax'));
}
if (!$this->errors) {
$cart_rules = $this->context->cart->getCartRules();
$available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart, false, true);
$update_quantity = $this->context->cart->updateQty($this->qty, $this->id_product, $this->id_product_attribute, $this->customization_id, Tools::getValue('op', 'up'), $this->id_address_delivery);
if ($update_quantity < 0) {
// If product has attribute, minimal quantity is set with minimal quantity of attribute
$minimal_quantity = $this->id_product_attribute ? Attribute::getAttributeMinimalQty($this->id_product_attribute) : $product->minimal_quantity;
$this->errors[] = sprintf(Tools::displayError('You must add %d minimum quantity', !Tools::getValue('ajax')), $minimal_quantity);
} elseif (!$update_quantity) {
$this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.', !Tools::getValue('ajax'));
} elseif ((int) Tools::getValue('allow_refresh')) {
// If the cart rules has changed, we need to refresh the whole cart
$cart_rules2 = $this->context->cart->getCartRules();
if (count($cart_rules2) != count($cart_rules)) {
$this->ajax_refresh = true;
} elseif (count($cart_rules2)) {
$rule_list = array();
foreach ($cart_rules2 as $rule) {
$rule_list[] = $rule['id_cart_rule'];
}
foreach ($cart_rules as $rule) {
if (!in_array($rule['id_cart_rule'], $rule_list)) {
$this->ajax_refresh = true;
break;
}
}
} else {
$available_cart_rules2 = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart, false, true);
if (count($available_cart_rules2) != count($available_cart_rules)) {
$this->ajax_refresh = true;
} elseif (count($available_cart_rules2)) {
$rule_list = array();
foreach ($available_cart_rules2 as $rule) {
$rule_list[] = $rule['id_cart_rule'];
}
//.........这里部分代码省略.........
示例6: buildXML
public static function buildXML()
{
global $country_infos;
$context = Context::getContext();
$country_infos = array('id_group' => 0, 'id_tax' => 1);
$html = '<products>' . "\n";
/* First line, columns */
$columns = array('id', 'name', 'smallimage', 'bigimage', 'producturl', 'description', 'price', 'retailprice', 'discount', 'recommendable', 'instock');
/* Setting parameters */
$conf = Configuration::getMultiple(array('PS_REWRITING_SETTINGS', 'PS_LANG_DEFAULT', 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT', 'PS_COUNTRY_DEFAULT', 'PS_SHOP_NAME', 'PS_CURRENCY_DEFAULT', 'PS_CARRIER_DEFAULT'));
/* Searching for products */
$result = Db::getInstance()->executeS('
SELECT DISTINCT p.`id_product`, i.`id_image`
FROM `' . _DB_PREFIX_ . 'product` p
JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.id_product = p.id_product)
LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.id_product = p.id_product)
WHERE p.`active` = 1 AND i.id_image IS NOT NULL
GROUP BY p.id_product');
foreach ($result as $k => $row) {
if (Pack::isPack(intval($row['id_product']))) {
continue;
}
$product = new Product(intval($row['id_product']), true);
if (Validate::isLoadedObject($product)) {
$imageObj = new Image($row['id_image']);
$imageObj->id_product = intval($product->id);
$line = array();
$line[] = $product->manufacturer_name . ' - ' . $product->name[intval($conf['PS_LANG_DEFAULT'])];
$line[] = Tools::getProtocol() . $_SERVER['HTTP_HOST'] . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '-small.jpg';
$line[] = Tools::getProtocol() . $_SERVER['HTTP_HOST'] . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '-thickbox.jpg';
$line[] = $context->link->getProductLink(intval($product->id), $product->link_rewrite[intval($conf['PS_LANG_DEFAULT'])], $product->ean13) . '&utm_source=criteo&aff=criteo';
$line[] = str_replace(array("\n", "\r", "\t", '|'), '', strip_tags(html_entity_decode($product->description_short[intval($conf['PS_LANG_DEFAULT'])], ENT_COMPAT, 'UTF-8')));
$price = $product->getPrice(true, intval(Product::getDefaultAttribute($product->id)));
$line[] = number_format($price, 2, '.', '');
$line[] = number_format($product->getPrice(true, intval(Product::getDefaultAttribute(intval($product->id))), 6, NULL, false, false), 2, '.', '');
$line[] = $product->getPrice(true, NULL, 2, NULL, true);
$line[] = '1';
$line[] = '1';
$cptXML = 1;
$html .= "\t" . '<product id="' . $product->id . '">' . "\n";
foreach ($line as $column) {
$html .= "\t\t" . '<' . $columns[$cptXML] . '>' . $column . '</' . $columns[$cptXML] . '>' . "\n";
$cptXML++;
}
$html .= "\t" . '</product>' . "\n";
}
}
$html .= '</products>' . "\n";
echo $html;
}
示例7: 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];
}
示例8: hookDisplayProductPriceBlock
public function hookDisplayProductPriceBlock($params)
{
if (!isset($params['product'])) {
return;
}
if ($params['product'] instanceof Product) {
$id_product = (int) $params['product']->id;
} else {
$id_product = (int) $params['product']['id_product'];
}
$cache_key = $this->name . '_' . $params['type'] . '_' . $id_product;
if (!$this->isCached('displayProductPriceBlock.tpl', $this->getCacheId($cache_key))) {
$weight = 0;
$combination_weight = 0;
$id_product = 0;
$allow_oosp = 0;
if ($params['product'] instanceof Product) {
$id_product_attribute = Product::getDefaultAttribute($id_product);
$weight = (double) $params['product']->weight;
$allow_oosp = $params['product']->isAvailableWhenOutOfStock((int) $params['product']->out_of_stock);
} else {
$id_product_attribute = Product::getDefaultAttribute($id_product);
if (!isset($params['product']['weight'])) {
$product = new Product((int) $id_product);
$params['product']['weight'] = $product->weight;
}
$weight = (double) $params['product']['weight'];
$allow_oosp = $params['product']['allow_oosp'];
}
if ($id_product_attribute) {
$combination = new Combination($id_product_attribute);
$combination_weight = $combination->weight;
}
$this->smarty->assign(array('is_object' => (bool) ($params['product'] instanceof Product), 'product' => $params['product'], 'weight' => $weight, 'allow_oosp' => $allow_oosp, 'combination_weight' => $combination_weight, 'priceDisplay' => Product::getTaxCalculationMethod((int) $this->context->cookie->id_customer), 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'php_self' => $this->context->controller->php_self, 'tax_enabled' => Configuration::get('PS_TAX'), 'cms_id_shipping' => Configuration::get('LEGAL_CMS_ID_SHIPPING'), 'template_type' => $params['type'], 'weight_unit' => Configuration::get('PS_WEIGHT_UNIT'), 'show_weights' => Configuration::get('LEGAL_SHOW_WEIGHTS'), 'show_fancy' => Configuration::get('LEGAL_SHOW_FANCY'), 'seo_active' => Configuration::get('PS_REWRITING_SETTINGS')));
}
return $this->display(__FILE__, 'displayProductPriceBlock.tpl', $this->getCacheId($cache_key));
}
示例9: renderExpressCheckoutForm
public function renderExpressCheckoutForm($type)
{
if (!Configuration::get('PAYPAL_EXPRESS_CHECKOUT_SHORTCUT') && !$this->useMobile() || !in_array(ECS, $this->getPaymentMethods()) || (int) Configuration::get('PAYPAL_BUSINESS') == 1 && (int) Configuration::get('PAYPAL_PAYMENT_METHOD') == HSS && !$this->useMobile()) {
return;
}
$id_product = (int) Tools::getValue('id_product');
$id_product_attribute = (int) Product::getDefaultAttribute($id_product);
if ($id_product_attribute) {
$minimal_quantity = Attribute::getAttributeMinimalQty($id_product_attribute);
} else {
$product = new Product($id_product);
$minimal_quantity = $product->minimal_quantity;
}
$this->context->smarty->assign(array('PayPal_payment_type' => $type, 'PayPal_current_page' => $this->getCurrentUrl(), 'id_product_attribute' => $id_product_attribute, 'product_minimal_quantity' => $minimal_quantity, 'PayPal_tracking_code' => $this->getTrackingCode((int) Configuration::get('PAYPAL_PAYMENT_METHOD'))));
return $this->fetchTemplate('express_checkout_shortcut_form.tpl');
}
示例10: process
//.........这里部分代码省略.........
if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2);
}
self::$smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $this->product->id, (int) Shop::getCurrentShop(), (int) self::$cookie->id_currency, $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (double) $tax), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'homeSize' => Image::getSize('home'), 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, self::$cookie->id_lang), 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => (double) $productPriceWithoutEcoTax, 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'group_reduction' => 1 - $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_));
self::$smarty->assign(array('HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent')));
$images = $this->product->getImages((int) self::$cookie->id_lang);
$productImages = array();
foreach ($images as $k => $image) {
if ($image['cover']) {
self::$smarty->assign('mainImage', $images[0]);
$cover = $image;
$cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image'];
$cover['id_image_only'] = (int) $image['id_image'];
}
$productImages[(int) $image['id_image']] = $image;
}
if (!isset($cover)) {
$cover = array('id_image' => Language::getIsoById(self::$cookie->id_lang) . '-default', 'legend' => 'No picture', 'title' => 'No picture');
}
$size = Image::getSize('large');
self::$smarty->assign(array('cover' => $cover, 'imgWidth' => (int) $size['width'], 'mediumSize' => Image::getSize('medium'), 'largeSize' => Image::getSize('large'), 'accessories' => $this->product->getAccessories((int) self::$cookie->id_lang)));
if (count($productImages)) {
self::$smarty->assign('images', $productImages);
}
/* Attributes / Groups & colors */
$colors = array();
$attributesGroups = $this->product->getAttributesGroups((int) self::$cookie->id_lang);
// @todo (RM) should only get groups and not all declination ?
if (is_array($attributesGroups) and $attributesGroups) {
$groups = array();
$combinationImages = $this->product->getCombinationImages((int) self::$cookie->id_lang);
foreach ($attributesGroups as $k => $row) {
/* Color management */
if ((isset($row['attribute_color']) and $row['attribute_color'] or file_exists(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) and $row['id_attribute_group'] == $this->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'] = (double) $row['price'];
$combinations[$row['id_product_attribute']]['ecotax'] = (double) $row['ecotax'];
$combinations[$row['id_product_attribute']]['weight'] = (double) $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($this->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;
}
self::$smarty->assign(array('groups' => $groups, 'combinaisons' => $combinations, 'combinations' => $combinations, 'colors' => (sizeof($colors) and $this->product->id_color_default) ? $colors : false, 'combinationImages' => $combinationImages));
}
self::$smarty->assign(array('no_tax' => Tax::excludeTaxeOption() or !Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), 'customizationFields' => $this->product->customizable ? $this->product->getCustomizationFields((int) self::$cookie->id_lang) : false));
// Pack management
self::$smarty->assign('packItems', $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, (int) self::$cookie->id_lang, true) : array());
self::$smarty->assign('packs', Pack::getPacksTable($this->product->id, (int) self::$cookie->id_lang, true, 1));
}
}
self::$smarty->assign(array('ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'categories' => Category::getHomeCategories((int) self::$cookie->id_lang), 'have_image' => isset($cover) ? (int) $cover['id_image'] : false, 'tax_enabled' => Configuration::get('PS_TAX'), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'ecotax' => !sizeof($this->errors) and $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'currencySign' => $currency->sign, 'currencyRate' => $currency->conversion_rate, 'currencyFormat' => $currency->format, 'currencyBlank' => $currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ipa_customization' => Tools::getIsset('ipa_customization') ? Tools::getValue('ipa_customization') : '', 'ipa_default' => Product::getDefaultAttribute($this->product->id)));
}
示例11: 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];
}
示例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
$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];
}
示例13: 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;
//.........这里部分代码省略.........
示例14: getDefaultAttribute
public static function getDefaultAttribute($id_product, $minimum_quantity = 0)
{
if (isset(self::$_getDefaultAttributeCache[$id_product . '-' . $minimum_quantity])) {
return self::$_getDefaultAttributeCache[$id_product . '-' . $minimum_quantity];
}
self::$_getDefaultAttributeCache[$id_product . '-' . $minimum_quantity] = Product::getDefaultAttribute($id_product, $minimum_quantity);
return self::$_getDefaultAttributeCache[$id_product . '-' . $minimum_quantity];
}
示例15: searchProducts
public function searchProducts($query)
{
if (version_compare(_PS_VERSION_, '1.5', '<')) {
$sql = '
SELECT p.`id_product`, pl.`name`, p.`weight`
FROM `' . _DB_PREFIX_ . 'category_product` cp
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.`id_product` = cp.`id_product`)
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = "' . (int) $this->context->language->id . '")
WHERE pl.`name` LIKE \'%' . pSQL($query) . '%\'
OR p.`ean13` LIKE \'%' . pSQL($query) . '%\'
OR p.`upc` LIKE \'%' . pSQL($query) . '%\'
OR p.`reference` LIKE \'%' . pSQL($query) . '%\'
OR p.`supplier_reference` LIKE \'%' . pSQL($query) . '%\'
GROUP BY `id_product`
ORDER BY pl.`name` ASC
';
} else {
$sql = new DbQuery();
$sql->select('p.`id_product`, pl.`name`, p.`weight`');
$sql->from('category_product', 'cp');
$sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
$sql->join(Shop::addSqlAssociation('product', 'p'));
$sql->leftJoin('product_lang', 'pl', '
p.`id_product` = pl.`id_product`
AND pl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('pl'));
$where = 'pl.`name` LIKE \'%' . pSQL($query) . '%\'
OR p.`ean13` LIKE \'%' . pSQL($query) . '%\'
OR p.`upc` LIKE \'%' . pSQL($query) . '%\'
OR p.`reference` LIKE \'%' . pSQL($query) . '%\'
OR p.`supplier_reference` LIKE \'%' . pSQL($query) . '%\'
OR p.`id_product` IN (SELECT id_product FROM ' . _DB_PREFIX_ . 'product_supplier sp WHERE `product_supplier_reference` LIKE \'%' . pSQL($query) . '%\')';
$sql->groupBy('`id_product`');
$sql->orderBy('pl.`name` ASC');
if (Combination::isFeatureActive()) {
$sql->leftJoin('product_attribute', 'pa', 'pa.`id_product` = p.`id_product`');
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false));
$where .= ' OR pa.`reference` LIKE \'%' . pSQL($query) . '%\'';
}
$sql->where($where);
}
$result = Db::getInstance()->executeS($sql);
if (!$result) {
return array('found' => false, 'notfound' => $this->l('No product has been found.'));
}
foreach ($result as &$product) {
$product['id_product_attribute'] = Product::getDefaultAttribute($product['id_product']);
$product['weight_numeric'] = $product['weight'];
$product['weight'] = sprintf('%.3f', $product['weight']) . ' ' . _DPDPOLAND_DEFAULT_WEIGHT_UNIT_;
}
return array('products' => $result, 'found' => true);
}