本文整理汇总了PHP中Product::getQuantity方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getQuantity方法的具体用法?PHP Product::getQuantity怎么用?PHP Product::getQuantity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::getQuantity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProductQuantity
public static function getProductQuantity($product, $id_product_attribute = false)
{
$allow_oosp = self::isAllowOOSP($product);
$qty = Product::getQuantity($product->id, $id_product_attribute);
if ($qty > 0) {
return $qty;
}
if ($allow_oosp) {
return 1000;
}
return $qty;
}
示例2: ajaxGetProductsForSupplyOrder
public function ajaxGetProductsForSupplyOrder()
{
require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/stock/ErpSupplyOrderClasses.php';
require_once _PS_MODULE_DIR_ . 'erpillicopresta/erpillicopresta.php';
/* manage advanced stock */
$stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
$sales_forecast_type = Configuration::get('ERP_SALES_FORECAST_CHOICE');
$id_supplier = (int) Tools::getValue('id_supplier', false);
$id_currency = (int) Tools::getValue('id_currency', false);
$id_categorie = (int) Tools::getValue('id_categorie', false);
$id_manufacturer = (int) Tools::getValue('id_manufacturer', false);
$id_warehouse = (int) Tools::getValue('id_warehouse', null);
$existing_ids = Tools::getValue('ids');
//$token_get_product = Tools::getValue('token');
$products = ErpSupplyOrderClasses::searchProduct($id_supplier, $id_categorie, $id_manufacturer, $id_currency);
if (!empty($products)) {
$advanced_stock_token = Tools::getAdminToken('AdminAdvancedStock' . (int) Tab::getIdFromClassName('AdminAdvancedStock') . (int) $this->context->employee->id);
foreach ($products as $product) {
// If product already in destination array, continue
if (strrpos($existing_ids, $product['id']) !== false) {
continue;
}
$ids = explode('_', $product['id']);
$id_product = $ids[0];
$id_product_attribute = $ids[1];
// If the advanced stock manager is activated
if ($stock_management_active == '1') {
// Get the physical and usable quantities
$query = new DbQuery();
$query->select('physical_quantity');
$query->select('usable_quantity');
$query->from('stock');
$query->where('id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute);
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
/* the two quantities */
$physical_quantity = (int) $res['physical_quantity'];
$usable_quantity = (int) $res['usable_quantity'];
// The real quantity depends of the warehouse
$manager = StockManagerFactory::getManager();
$product['stock'] = $real_quantity = (int) $manager->getProductRealQuantities($id_product, $id_product_attribute, $id_warehouse, true);
} else {
// get the free quantities
$product['stock'] = $usable_quantity = (int) Product::getQuantity($id_product, $id_product_attribute);
}
/* TAX */
/* Get the current tax */
$query = new DbQuery();
$query->select('rate');
$query->from('tax', 't');
$query->innerJoin('tax_rule', 'tr', 'tr.id_tax = t.id_tax');
$query->innerJoin('product', 'p', 'p.id_tax_rules_group = tr.id_tax_rules_group');
$query->where('p.id_product = ' . (int) $id_product);
$query->where('tr.id_country IN (SELECT id_country
FROM ' . _DB_PREFIX_ . 'address
WHERE id_supplier = ' . (int) $id_supplier . ')');
$product['tax_rate'] = round(Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query), 1);
$prices = ErpSupplyOrderClasses::getWholesalePrice((int) $id_product, (int) $id_product_attribute, (int) $id_supplier);
$product['unit_price_te'] = Tools::convertPriceFull($prices, new Currency((int) $id_currency));
// sales quantity for X rolling month
$quantity_sales = ErpSupplyOrderClasses::getQuantitySales((int) $id_product, (int) $id_product_attribute);
// if sale forecast is activ
if ($sales_forecast_type != 0) {
// if we use the 6 month rolling method
if ($sales_forecast_type == 1) {
$sales_forecasts = round(ErpSupplyOrderClasses::getProductSalesForecasts($id_product, $id_product_attribute), 1);
} else {
$sales_forecasts = round(ErpSupplyOrderClasses::getProductSalesForecastsByPeriod($id_product, $id_product_attribute), 1);
}
} else {
$sales_forecasts = 'NA';
}
// Sales gain
$sales_gains = ErpSupplyOrderClasses::getProductSalesGains($id_product, $id_product_attribute);
// Prepare the hidden json foreach line
$product['comment'] = '';
$product_json = Tools::jsonEncode($product);
echo '<tr>
<td class="product_json hide">' . $product_json . '</td>
<td><input type="checkbox" class="select_product" name="select_product"/></td>
<td>' . $product['supplier_reference'] . '</td>
<td>' . $product['reference'] . '</td>
<td>
<a href="#" class="cluetip-supply-price" title="' . $this->l('Supplier Price') . '"
rel="index.php?controller=AdminAdvancedStock&ajax=1&id_product=' . $id_product . '&id_product_attribute=' . $id_product_attribute . '&id_currency=' . $id_currency . '&task=getProductSupplierPrice&token=' . $advanced_stock_token . '" >
<img src="themes/default/img/icon-search.png">
</a>
' . $product['name'] . '
</td>';
if (Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedSupplyOrder'))) {
echo '<td align="center"> <p style="background-color:' . ErpSupplyOrderClasses::getStockLevelColor($real_quantity) . '; width:16px; height:16px"></p> </td>';
}
echo '<td align="center">' . $usable_quantity . '</td>
' . ($stock_management_active == '1' ? '
<td align="center">' . $physical_quantity . '</td>
<td align="center">' . $real_quantity . '</td>' : '') . '';
if (Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedSupplyOrder'))) {
echo '<td align="center">' . $quantity_sales . '</td>
<td align="center">' . $sales_gains . '</td>';
if (Configuration::get('ERP_SALES_FORECAST_CHOICE') != 0) {
echo '<td>' . $sales_forecasts . '</td>';
//.........这里部分代码省略.........
示例3: isInStock
public static function isInStock($id_product)
{
if (!Pack::isFeatureActive()) {
return true;
}
$items = Pack::getItems((int) $id_product, Configuration::get('PS_LANG_DEFAULT'));
foreach ($items as $item) {
/** @var Product $item */
// Updated for 1.5.0
if (Product::getQuantity($item->id) < $item->pack_quantity && !$item->isAvailableWhenOutOfStock((int) $item->out_of_stock)) {
return false;
}
}
return true;
}
示例4: array
$this->context->smarty->assign(array('order' => $order, 'price' => Tools::displayPrice($order['total_paid'], $this->context->currency), 'use_mobile' => $this->context->getMobileDevice()));
if (!$order) {
$this->context->smarty->assign('errors', array($this->paypal->l('Payment error')));
}
echo $this->paypal->fetchTemplate('/views/templates/front/', 'order-confirmation');
}
}
if (Tools::getValue('id_module') && Tools::getValue('key') && Tools::getValue('id_cart') && Tools::getValue('id_order')) {
if (_PS_VERSION_ < '1.5') {
new PayPalExpressCheckoutSubmit();
}
} elseif (Tools::getValue('get_qty')) {
/* Ajax response */
$id_product = (int) Tools::getValue('id_product');
$id_product_attribute = (int) Tools::getValue('id_product_attribute');
if (Product::getQuantity((int) $id_product, (int) $id_product_attribute) <= 0) {
$paypal = new Paypal();
die($paypal->l('This product is no longer in stock with those attributes but is available with others'));
}
die(true);
} else {
$request_type = Tools::getValue('express_checkout');
$ppec = new PaypalExpressCheckout($request_type);
if ($request_type && $ppec->type) {
$id_product = (int) Tools::getValue('id_product');
$id_product_attribute = (int) Tools::getValue('id_p_attr');
$product_quantity = (int) Tools::getValue('quantity');
if ($id_product > 0 && $id_product_attribute !== false && $product_quantity > 0) {
// Create new Cart to avoid any refresh or other bad manipulations
$ppec->context->cart = new Cart();
$ppec->context->cart->id_currency = (int) $ppec->context->currency->id;
示例5: insertOrderItems
protected function insertOrderItems(ShopgateOrder $order)
{
$this->log('start insertOrderItems()', ShopgateLogger::LOGTYPE_DEBUG);
$products = array();
//Check product quantitys
$settings = Configuration::getMultiple(array('SHOPGATE_MIN_QUANTITY_CHECK', 'SHOPGATE_OUT_OF_STOCK_CHECK'));
// complete weight of the order
foreach ($order->getItems() as $i) {
list($id_product, $id_product_attribute) = $this->getProductIdentifiers($i);
if ($id_product == 0) {
continue;
}
$wantedQty = (int) $i->getQuantity();
$product = new Product($id_product, true, (int) Configuration::get('PS_LANG_DEFAULT'));
$minQty = 1;
if ((int) $id_product_attribute) {
$stockQty = (int) Product::getQuantity((int) $id_product, (int) $id_product_attribute);
if (version_compare(_PS_VERSION_, '1.4.0.7', '>=')) {
// this attribute doesn't exist before 1.4.0.7
$minQty = Attribute::getAttributeMinimalQty((int) $id_product_attribute);
}
} else {
$stockQty = (int) Product::getQuantity((int) $id_product, NULL);
if (version_compare(_PS_VERSION_, '1.4.0.2', '>=')) {
// this attribute doesn't exist before 1.4.0.2
$minQty = (int) $product->minimal_quantity;
}
}
$oos_available = Product::isAvailableWhenOutOfStock($product->out_of_stock);
$qtyDifference = 0;
if (!$oos_available && $wantedQty > $stockQty) {
$qtyDifference = $wantedQty - $stockQty;
}
$p = array();
$p['id_product'] = (int) $id_product;
$p['id_product_attribute'] = (int) $id_product_attribute;
$p['name'] = $product->name;
$p['quantity'] = $wantedQty;
$p['quantity_in_stock'] = $stockQty;
$p['quantity_difference'] = $qtyDifference;
if (empty($p['name'])) {
$p['name'] = $i->getName();
}
if ($oos_available) {
$stockQty = $wantedQty;
}
if ((bool) $settings['SHOPGATE_MIN_QUANTITY_CHECK'] && $wantedQty < $minQty) {
throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DATABASE_ERROR, 'Minimum quantity required', true);
}
if ((bool) $settings['SHOPGATE_OUT_OF_STOCK_CHECK'] && $wantedQty > $stockQty) {
throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DATABASE_ERROR, 'Out of stock', true);
}
array_push($products, $p);
}
$this->log('end insertOrderItems()', ShopgateLogger::LOGTYPE_DEBUG);
return $products;
}
示例6: 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];
}
示例7: explode
$offer_price_in_rs = Tools::convertPrice($offer_price_in, 4);
$mrp_in = Product::getPriceStatic($productObj->id, true, NULL, 6, NULL, false, false, 1, false, NULL, NULL, IND_ADDRESS_ID);
$mrp_in_rs = Tools::convertPrice($mrp_in, 4);
$color = '';
if (isset($productObj->generic_color) && !empty($productObj->generic_color)) {
$colors = explode(',', $productObj->generic_color);
foreach ($colors as $c) {
$color = strtolower(preg_replace('/\\s+/', '-', trim($c)));
}
}
$fabric = '';
if (isset($productObj->fabric) && !empty($productObj->fabric)) {
$fabric = $productObj->fabric;
}
$availability = 'TRUE';
$quantity = Product::getQuantity($id_product);
if ((int) $quantity < 1) {
$availability = 'FALSE';
}
$catIds = $productObj->getCategories();
$category_names = array();
foreach ($catIds as $catID) {
$category = new Category((int) $catID);
$category_names[] = $category->getName(1);
}
$category_names = array_diff($category_names, array('Home'));
$categories = implode(',', $category_names);
$category = 'Other';
if (in_array(CAT_SAREE, $catIds)) {
$category = 'Saree';
} elseif (in_array(CAT_SKD, $catIds)) {
示例8: initContent
public function initContent()
{
parent::initContent();
$token = Tools::getValue('token');
$module = new BlockWishList();
if ($token) {
$wishlist = WishList::getByToken($token);
WishList::refreshWishList($wishlist['id_wishlist']);
$products = WishList::getProductByIdCustomer((int) $wishlist['id_wishlist'], (int) $wishlist['id_customer'], $this->context->language->id, null, true);
$nb_products = count($products);
$priority_names = array(0 => $module->l('High'), 1 => $module->l('Medium'), 2 => $module->l('Low'));
for ($i = 0; $i < $nb_products; ++$i) {
$obj = new Product((int) $products[$i]['id_product'], true, $this->context->language->id);
if (!Validate::isLoadedObject($obj)) {
continue;
} else {
$products[$i]['priority_name'] = $priority_names[$products[$i]['priority']];
$quantity = Product::getQuantity((int) $products[$i]['id_product'], $products[$i]['id_product_attribute']);
$products[$i]['attribute_quantity'] = $quantity;
$products[$i]['product_quantity'] = $quantity;
$products[$i]['allow_oosp'] = $obj->isAvailableWhenOutOfStock((int) $obj->out_of_stock);
if ($products[$i]['id_product_attribute'] != 0) {
$combination_imgs = $obj->getCombinationImages($this->context->language->id);
if (isset($combination_imgs[$products[$i]['id_product_attribute']][0])) {
$products[$i]['cover'] = $obj->id . '-' . $combination_imgs[$products[$i]['id_product_attribute']][0]['id_image'];
} else {
$cover = Product::getCover($obj->id);
$products[$i]['cover'] = $obj->id . '-' . $cover['id_image'];
}
} else {
$images = $obj->getImages($this->context->language->id);
foreach ($images as $image) {
if ($image['cover']) {
$products[$i]['cover'] = $obj->id . '-' . $image['id_image'];
break;
}
}
}
if (!isset($products[$i]['cover'])) {
$products[$i]['cover'] = $this->context->language->iso_code . '-default';
}
}
$products[$i]['bought'] = false;
/*
for ($j = 0, $k = 0; $j < sizeof($bought); ++$j)
{
if ($bought[$j]['id_product'] == $products[$i]['id_product'] AND
$bought[$j]['id_product_attribute'] == $products[$i]['id_product_attribute']
)
$products[$i]['bought'][$k++] = $bought[$j];
}*/
}
WishList::incCounter((int) $wishlist['id_wishlist']);
$ajax = Configuration::get('PS_BLOCK_CART_AJAX');
$wishlists = WishList::getByIdCustomer((int) $wishlist['id_customer']);
foreach ($wishlists as $key => $item) {
if ($item['id_wishlist'] == $wishlist['id_wishlist']) {
unset($wishlists[$key]);
break;
}
}
$this->context->smarty->assign(array('current_wishlist' => $wishlist, 'token' => $token, 'ajax' => isset($ajax) && (int) $ajax == 1 ? '1' : '0', 'wishlists' => $wishlists, 'products' => $products));
}
$this->setTemplate('view.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: restoreOrderToCart
protected function restoreOrderToCart(Cart $cart)
{
if (!$cart || !ValidateCore::isLoadedObject($cart)) {
return null;
}
Db::getInstance()->execute('BEGIN');
$new_cart = null;
try {
/** @var CartCore $new_cart */
/** @noinspection PhpUndefinedClassInspection */
$new_cart = new Cart();
/** @noinspection PhpUndefinedFieldInspection */
$new_cart->id_customer = (int) $cart->id_customer;
/** @noinspection PhpUndefinedFieldInspection */
$new_cart->id_address_delivery = (int) $cart->id_address_delivery;
/** @noinspection PhpUndefinedFieldInspection */
$new_cart->id_address_invoice = (int) $cart->id_address_invoice;
/** @noinspection PhpUndefinedFieldInspection */
$new_cart->id_lang = (int) $cart->id_lang;
/** @noinspection PhpUndefinedFieldInspection */
$new_cart->id_currency = (int) $cart->id_currency;
/** @noinspection PhpUndefinedFieldInspection */
$new_cart->id_carrier = (int) $cart->id_carrier;
/** @noinspection PhpUndefinedFieldInspection */
$new_cart->recyclable = (int) $cart->recyclable;
/** @noinspection PhpUndefinedFieldInspection */
$new_cart->gift = (int) $cart->gift;
$new_cart->add();
/** @noinspection PhpUndefinedMethodInspection */
$products = $cart->getProducts();
if ($products) {
foreach ($products as $p) {
$idProduct = $p['id_product'];
$idProductAttribute = $p['id_product_attribute'];
$qty = $p['cart_quantity'];
/** @noinspection PhpUndefinedClassInspection */
/** @noinspection PhpUndefinedFieldInspection */
$producToAdd = new Product((int) $idProduct, true, (int) $cart->id_lang);
/** @noinspection PhpUndefinedFieldInspection */
if (!$producToAdd->id || !$producToAdd->active) {
continue;
}
/* Check the quantity availability */
if ($idProductAttribute > 0 and is_numeric($idProductAttribute)) {
/** @noinspection PhpUndefinedClassInspection */
/** @noinspection PhpUndefinedMethodInspection */
/** @noinspection PhpUndefinedFieldInspection */
if (!$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) and !Attribute::checkAttributeQty((int) $idProductAttribute, (int) $qty)) {
/* There is not enough product attribute in stock - set customer qty to current stock on hand */
/** @noinspection PhpUndefinedFunctionInspection */
$qty = getAttributeQty($idProductAttribute);
}
} elseif (!$producToAdd->checkQty((int) $qty)) {
/* There is not enough product in stock - set customer qty to current stock on hand */
/** @noinspection PhpUndefinedMethodInspection */
$qty = $producToAdd->getQuantity($idProduct);
}
$new_cart->updateQty((int) $qty, (int) $idProduct, (int) $idProductAttribute, NULL, 'up');
unset($p);
}
}
$new_cart->update();
Db::getInstance()->execute('COMMIT');
} catch (Exception $e) {
Db::getInstance()->execute('ROLLBACK');
throw $e;
}
/** @noinspection PhpUndefinedFieldInspection */
$this->context->cookie->id_cart = (int) $new_cart->id;
return $new_cart;
}
示例11: hookProductFooter
public function hookProductFooter($params)
{
$product_quantity = Product::getQuantity((int) Tools::getValue('id_product'));
if ($product_quantity == 0) {
return;
}
if (Configuration::get('PAYPAL_USA_EXPRESS_CHECKOUT') == 1 && Configuration::get('PAYPAL_USA_EXP_CHK_PRODUCT')) {
$this->smarty->assign('paypal_usa_action', $this->context->link->getModuleLink('paypalusa', 'expresscheckout', array('pp_exp_initial' => 1)));
$this->smarty->assign('paypal_usa_merchant_country_is_mx', Validate::isLoadedObject($this->_shop_country) && $this->_shop_country->iso_code == 'MX');
return $this->display(__FILE__, 'views/templates/hooks/express-checkout.tpl');
}
}
示例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: getInventoryObj
protected function getInventoryObj($divaProduct, $sku, &$quantity, &$shipping_sla, $zero = false)
{
$id_product = $sku["id_product"];
$is_parent = $sku["is_parent"];
$has_children = empty($sku["attribute"]) ? false : true;
$size = empty($sku["attribute"]) ? "One Size" : $sku["attribute"]["attribute_name"];
$id_sku = $sku['id_sku'];
$inventoryData = new MarketplaceWebService_XML_Data_Inventory();
$inventoryData->setSKU($id_sku);
if ($is_parent === false && $has_children === false) {
$quantity = (int) Product::getQuantity($id_product);
if ($quantity < 0) {
$inventoryData->setQuantity(0);
} else {
$inventoryData->setQuantity($quantity);
}
} else {
if ($is_parent) {
$quantity = (int) Product::getQuantity($id_product);
if ($quantity < 0) {
$inventoryData->setQuantity(0);
} else {
$inventoryData->setQuantity($quantity);
}
} else {
$quantity = (int) Product::getQuantity($id_product, $sku['attribute']['id_product_attribute']);
if ($quantity < 0) {
$inventoryData->setQuantity(0);
} else {
$inventoryData->setQuantity($quantity);
}
}
}
if ($zero) {
$inventoryData->setQuantity(0);
}
$shipping_sla = (int) $divaProduct->shipping_sla;
$inventoryData->setFulfillmentLatency($shipping_sla);
return $inventoryData;
}
示例14: postProcess
//.........这里部分代码省略.........
if (array_key_exists($order_detail->product_id, $customization_quantities) && array_key_exists($order_detail->product_attribute_id, $customization_quantities[$order_detail->product_id])) {
$customization_quantity = (int) $customization_quantities[$order_detail->product_id][$order_detail->product_attribute_id];
}
if ($order_detail->product_quantity - $customization_quantity - $order_detail->product_quantity_refunded - $order_detail->product_quantity_return < $qtyCancelProduct) {
$this->_errors[] = Tools::displayError('Invalid quantity selected for product.');
}
}
}
if ($customizationList) {
$customization_quantities = Customization::retrieveQuantitiesFromIds(array_keys($customizationList));
foreach ($customizationList as $id_customization => $id_order_detail) {
$qtyCancelProduct = abs($customizationQtyList[$id_customization]);
$customization_quantity = $customization_quantities[$id_customization];
if (!$qtyCancelProduct) {
$this->_errors[] = Tools::displayError('No quantity selected for product.');
}
if ($qtyCancelProduct > $customization_quantity['quantity'] - ($customization_quantity['quantity_refunded'] + $customization_quantity['quantity_returned'])) {
$this->_errors[] = Tools::displayError('Invalid quantity selected for product.');
}
}
}
if (!sizeof($this->_errors) and $productList) {
foreach ($productList as $key => $id_order_detail) {
$qtyCancelProduct = abs($qtyList[$key]);
$orderDetail = new OrderDetail((int) $id_order_detail);
// Reinject product
if (!$order->hasBeenDelivered() or $order->hasBeenDelivered() and Tools::isSubmit('reinjectQuantities')) {
$reinjectableQuantity = (int) $orderDetail->product_quantity - (int) $orderDetail->product_quantity_reinjected;
$quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct;
if (!Product::reinjectQuantities($orderDetail, $quantityToReinject)) {
$this->_errors[] = Tools::displayError('Cannot re-stock product') . ' <span class="bold">' . $orderDetail->product_name . '</span>';
} else {
$updProductAttributeID = !empty($orderDetail->product_attribute_id) ? (int) $orderDetail->product_attribute_id : NULL;
$newProductQty = Product::getQuantity((int) $orderDetail->product_id, $updProductAttributeID);
$product = get_object_vars(new Product((int) $orderDetail->product_id, false, (int) $cookie->id_lang));
if (!empty($orderDetail->product_attribute_id)) {
$updProduct['quantity_attribute'] = (int) $newProductQty;
$product['quantity_attribute'] = $updProduct['quantity_attribute'];
} else {
$updProduct['stock_quantity'] = (int) $newProductQty;
$product['stock_quantity'] = $updProduct['stock_quantity'];
}
Hook::updateQuantity($product, $order);
}
}
// Delete product
if (!$order->deleteProduct($order, $orderDetail, $qtyCancelProduct)) {
$this->_errors[] = Tools::displayError('An error occurred during deletion of the product.') . ' <span class="bold">' . $orderDetail->product_name . '</span>';
}
Module::hookExec('cancelProduct', array('order' => $order, 'id_order_detail' => $id_order_detail));
}
}
if (!sizeof($this->_errors) and $customizationList) {
foreach ($customizationList as $id_customization => $id_order_detail) {
$orderDetail = new OrderDetail((int) $id_order_detail);
$qtyCancelProduct = abs($customizationQtyList[$id_customization]);
if (!$order->deleteCustomization($id_customization, $qtyCancelProduct, $orderDetail)) {
$this->_errors[] = Tools::displayError('An error occurred during deletion of product customization.') . ' ' . $id_customization;
}
}
}
// E-mail params
if ((isset($_POST['generateCreditSlip']) or isset($_POST['generateDiscount'])) and !sizeof($this->_errors)) {
$customer = new Customer((int) $order->id_customer);
$params['{lastname}'] = $customer->lastname;
$params['{firstname}'] = $customer->firstname;
示例15: postProcess
//.........这里部分代码省略.........
if (array_key_exists($order_detail->product_id, $customization_quantities) && array_key_exists($order_detail->product_attribute_id, $customization_quantities[$order_detail->product_id])) {
$customization_quantity = (int) $customization_quantities[$order_detail->product_id][$order_detail->product_attribute_id];
}
if ($order_detail->product_quantity - $customization_quantity - $order_detail->product_quantity_refunded - $order_detail->product_quantity_return < $qtyCancelProduct) {
$this->_errors[] = Tools::displayError('Invalid quantity selected for product.');
}
}
}
if ($customizationList) {
$customization_quantities = Customization::retrieveQuantitiesFromIds(array_keys($customizationList));
foreach ($customizationList as $id_customization => $id_order_detail) {
$qtyCancelProduct = abs($customizationQtyList[$id_customization]);
$customization_quantity = $customization_quantities[$id_customization];
if (!$qtyCancelProduct) {
$this->_errors[] = Tools::displayError('No quantity selected for product.');
}
if ($qtyCancelProduct > $customization_quantity['quantity'] - ($customization_quantity['quantity_refunded'] + $customization_quantity['quantity_returned'])) {
$this->_errors[] = Tools::displayError('Invalid quantity selected for product.');
}
}
}
if (!sizeof($this->_errors) and $productList) {
foreach ($productList as $key => $id_order_detail) {
$qtyCancelProduct = abs($qtyList[$key]);
$orderDetail = new OrderDetail((int) $id_order_detail);
// Reinject product
if (!$order->hasBeenDelivered() or $order->hasBeenDelivered() and Tools::isSubmit('reinjectQuantities')) {
$reinjectableQuantity = (int) $orderDetail->product_quantity - (int) $orderDetail->product_quantity_reinjected;
$quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct;
if (!Product::reinjectQuantities($orderDetail, $quantityToReinject)) {
$this->_errors[] = Tools::displayError('Cannot re-stock product') . ' <span class="bold">' . $orderDetail->product_name . '</span>';
} else {
$updProductAttributeID = !empty($orderDetail->product_attribute_id) ? (int) $orderDetail->product_attribute_id : NULL;
$newProductQty = Product::getQuantity((int) $orderDetail->product_id, $updProductAttributeID);
$product = get_object_vars(new Product((int) $orderDetail->product_id, false, (int) $cookie->id_lang));
if (!empty($orderDetail->product_attribute_id)) {
$updProduct['quantity_attribute'] = (int) $newProductQty;
$product['quantity_attribute'] = $updProduct['quantity_attribute'];
} else {
$updProduct['stock_quantity'] = (int) $newProductQty;
$product['stock_quantity'] = $updProduct['stock_quantity'];
}
Hook::updateQuantity($product, $order);
}
}
// Delete product
if (!$order->deleteProduct($order, $orderDetail, $qtyCancelProduct)) {
$this->_errors[] = Tools::displayError('An error occurred during deletion of the product.') . ' <span class="bold">' . $orderDetail->product_name . '</span>';
}
Module::hookExec('cancelProduct', array('order' => $order, 'id_order_detail' => $id_order_detail));
}
}
if (!sizeof($this->_errors) and $customizationList) {
foreach ($customizationList as $id_customization => $id_order_detail) {
$orderDetail = new OrderDetail((int) $id_order_detail);
$qtyCancelProduct = abs($customizationQtyList[$id_customization]);
if (!$order->deleteCustomization($id_customization, $qtyCancelProduct, $orderDetail)) {
$this->_errors[] = Tools::displayError('An error occurred during deletion of product customization.') . ' ' . $id_customization;
}
}
}
// E-mail params
if ((isset($_POST['generateCreditSlip']) or isset($_POST['generateDiscount'])) and !sizeof($this->_errors)) {
$customer = new Customer((int) $order->id_customer);
$params['{lastname}'] = $customer->lastname;
$params['{firstname}'] = $customer->firstname;