当前位置: 首页>>代码示例>>PHP>>正文


PHP Pack::getQuantity方法代码示例

本文整理汇总了PHP中Pack::getQuantity方法的典型用法代码示例。如果您正苦于以下问题:PHP Pack::getQuantity方法的具体用法?PHP Pack::getQuantity怎么用?PHP Pack::getQuantity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pack的用法示例。


在下文中一共展示了Pack::getQuantity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateQty

    /**
     * Update product quantity
     *
     * @param integer $quantity Quantity to add (or substract)
     * @param integer $id_product Product ID
     * @param integer $id_product_attribute Attribute ID if needed
     * @param string $operator Indicate if quantity must be increased or decreased
     */
    public function updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, Shop $shop = null, $auto_add_cart_rule = true)
    {
        if (!$shop) {
            $shop = Context::getContext()->shop;
        }
        if (Context::getContext()->customer->id) {
            if ($id_address_delivery == 0 && (int) $this->id_address_delivery) {
                // The $id_address_delivery is null, use the cart delivery address
                $id_address_delivery = $this->id_address_delivery;
            } elseif ($id_address_delivery == 0) {
                // The $id_address_delivery is null, get the default customer address
                $id_address_delivery = (int) Address::getFirstCustomerAddressId((int) Context::getContext()->customer->id);
            } elseif (!Customer::customerHasAddress(Context::getContext()->customer->id, $id_address_delivery)) {
                // The $id_address_delivery must be linked with customer
                $id_address_delivery = 0;
            }
        }
        $quantity = (int) $quantity;
        $id_product = (int) $id_product;
        $id_product_attribute = (int) $id_product_attribute;
        $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), $shop->id);
        if ($id_product_attribute) {
            $combination = new Combination((int) $id_product_attribute);
            if ($combination->id_product != $id_product) {
                return false;
            }
        }
        /* If we have a product combination, the minimal quantity is set with the one of this combination */
        if (!empty($id_product_attribute)) {
            $minimal_quantity = (int) Attribute::getAttributeMinimalQty($id_product_attribute);
        } else {
            $minimal_quantity = (int) $product->minimal_quantity;
        }
        if (!Validate::isLoadedObject($product)) {
            die(Tools::displayError());
        }
        if (isset(self::$_nbProducts[$this->id])) {
            unset(self::$_nbProducts[$this->id]);
        }
        if (isset(self::$_totalWeight[$this->id])) {
            unset(self::$_totalWeight[$this->id]);
        }
        if ((int) $quantity <= 0) {
            return $this->deleteProduct($id_product, $id_product_attribute, (int) $id_customization);
        } elseif (!$product->available_for_order || Configuration::get('PS_CATALOG_MODE')) {
            return false;
        } else {
            /* Check if the product is already in the cart */
            $result = $this->containsProduct($id_product, $id_product_attribute, (int) $id_customization, (int) $id_address_delivery);
            /* Update quantity if product already exist */
            if ($result) {
                if ($operator == 'up') {
                    $sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity
							FROM ' . _DB_PREFIX_ . 'product p
							' . Product::sqlStock('p', $id_product_attribute, true, $shop) . '
							WHERE p.id_product = ' . $id_product;
                    $result2 = Db::getInstance()->getRow($sql);
                    $product_qty = (int) $result2['quantity'];
                    // Quantity for product pack
                    if (Pack::isPack($id_product)) {
                        $product_qty = Pack::getQuantity($id_product, $id_product_attribute);
                    }
                    $new_qty = (int) $result['quantity'] + (int) $quantity;
                    $qty = '+ ' . (int) $quantity;
                    if (!Product::isAvailableWhenOutOfStock((int) $result2['out_of_stock'])) {
                        if ($new_qty > $product_qty) {
                            return false;
                        }
                    }
                } else {
                    if ($operator == 'down') {
                        $qty = '- ' . (int) $quantity;
                        $new_qty = (int) $result['quantity'] - (int) $quantity;
                        if ($new_qty < $minimal_quantity && $minimal_quantity > 1) {
                            return -1;
                        }
                    } else {
                        return false;
                    }
                }
                /* Delete product from cart */
                if ($new_qty <= 0) {
                    return $this->deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization);
                } else {
                    if ($new_qty < $minimal_quantity) {
                        return -1;
                    } else {
                        Db::getInstance()->execute('
						UPDATE `' . _DB_PREFIX_ . 'cart_product`
						SET `quantity` = `quantity` ' . $qty . ', `date_add` = NOW()
						WHERE `id_product` = ' . (int) $id_product . (!empty($id_product_attribute) ? ' AND `id_product_attribute` = ' . (int) $id_product_attribute : '') . '
						AND `id_cart` = ' . (int) $this->id . (Configuration::get('PS_ALLOW_MULTISHIPPING') && $this->isMultiAddressDelivery() ? ' AND `id_address_delivery` = ' . (int) $id_address_delivery : '') . '
//.........这里部分代码省略.........
开发者ID:dev-lav,项目名称:htdocs,代码行数:101,代码来源:Cart.php

示例2: updateQuantity

    /**
     * Update product quantity
     *
     * @param integer $quantity Quantity to add (or substract)
     * @param $product_id
     * @param null $product_attribute_id
     * @param bool $customization_id
     * @param string $operator Indicate if quantity must be increased or decreased
     * @param int $address_delivery_id
     * @param JeproshopShopModelShop $shop
     * @param bool $auto_add_cart_rule
     * @return bool|int
     * @internal param int $id_product Product ID
     * @internal param int $id_product_attribute Attribute ID if needed
     */
    public function updateQuantity($quantity, $product_id, $product_attribute_id = null, $customization_id = false, $operator = 'up', $address_delivery_id = 0, JeproshopShopModelShop $shop = null, $auto_add_cart_rule = true)
    {
        if (!$shop) {
            $shop = JeproshopContext::getContext()->shop;
        }
        $db = JFactory::getDBO();
        if (JeproshopContext::getContext()->customer->customer_id) {
            if ($address_delivery_id == 0 && (int) $this->address_delivery_id) {
                // The $id_address_delivery is null, use the cart delivery address
                $address_delivery_id = $this->address_delivery_id;
            } elseif ($address_delivery_id == 0) {
                // The $id_address_delivery is null, get the default customer address
                $address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId((int) JeproshopContext::getContext()->customer->customer_id);
            } elseif (!JeproshopCustomerModelCustomer::customerHasAddress(JeproshopContext::getContext()->customer->customer_id, $address_delivery_id)) {
                // The $id_address_delivery must be linked with customer
                $address_delivery_id = 0;
            }
        }
        $quantity = (int) $quantity;
        $product_id = (int) $product_id;
        $product_attribute_id = (int) $product_attribute_id;
        $product = new JeproshopProductModelProduct($product_id, false, JeproshopSettingModelSetting::getValue('default_lang'), $shop->shop_id);
        if ($product_attribute_id) {
            $combination = new JeproshopCombinationModelCombination((int) $product_attribute_id);
            if ($combination->product_id != $product_id) {
                return false;
            }
        }
        /* If we have a product combination, the minimal quantity is set with the one of this combination */
        if (!empty($product_attribute_id)) {
            $minimal_quantity = (int) JeproshopAttributeModelAttribute::getAttributeMinimalQty($product_attribute_id);
        } else {
            $minimal_quantity = (int) $product->minimal_quantity;
        }
        if (!JeproshopValidator::isLoadedObject($product, 'product_id')) {
            die(Tools::displayError());
        }
        if (isset(self::$_nbProducts[$this->cart_id])) {
            unset(self::$_nbProducts[$this->cart_id]);
        }
        if (isset(self::$_totalWeight[$this->cart_id])) {
            unset(self::$_totalWeight[$this->cart_id]);
        }
        if ((int) $quantity <= 0) {
            return $this->deleteProduct($product_id, $product_attribute_id, (int) $customization_id);
        } elseif (!$product->available_for_order || JeproshopSettingModelSeting::getValue('catalog_mode')) {
            return false;
        } else {
            /* Check if the product is already in the cart */
            $result = $this->containsProduct($product_id, $product_attribute_id, (int) $customization_id, (int) $address_delivery_id);
            /* Update quantity if product already exist */
            if ($result) {
                if ($operator == 'up') {
                    $query = "SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity FROM " . $db->quoteName('#__jeproshop_product') . " AS product" . JeproshopProductModelProduct::sqlStock('p', $product_attribute_id, true, $shop);
                    $query .= " WHERE product.product_id = " . $product_id;
                    $db->setQuery($query);
                    $result2 = $db->loadObject();
                    $product_qty = (int) $result2->quantity;
                    // Quantity for product pack
                    if (JeproshopProductPack::isPack($product_id)) {
                        $product_qty = JeproshopProductPack::getQuantity($product_id, $product_attribute_id);
                    }
                    $new_qty = (int) $result->quantity + (int) $quantity;
                    $qty = '+ ' . (int) $quantity;
                    if (!JeproshopProductModelProduct::isAvailableWhenOutOfStock((int) $result2->out_of_stock)) {
                        if ($new_qty > $product_qty) {
                            return false;
                        }
                    }
                } else {
                    if ($operator == 'down') {
                        $qty = '- ' . (int) $quantity;
                        $new_qty = (int) $result->quantity - (int) $quantity;
                        if ($new_qty < $minimal_quantity && $minimal_quantity > 1) {
                            return -1;
                        }
                    } else {
                        return false;
                    }
                }
                /* Delete product from cart */
                if ($new_qty <= 0) {
                    return $this->deleteProduct((int) $product_id, (int) $product_attribute_id, (int) $customization_id);
                } else {
                    if ($new_qty < $minimal_quantity) {
//.........这里部分代码省略.........
开发者ID:jeprodev,项目名称:jeproshop,代码行数:101,代码来源:cart.php

示例3: removeProduct


//.........这里部分代码省略.........
							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['qty'];
                                if ($left_quantity_to_check <= 0) {
                                    break;
                                }
                            }
                        }
                    }
                    if ($warehouse->management_type == 'LIFO') {
                        // orders stock history by timestamp to get newest history first
                        krsort($stock_history_qty_available);
                    } else {
                        // orders stock history by timestamp to get oldest history first
                        ksort($stock_history_qty_available);
                    }
                    // checks each stock to manage the real quantity to decrement for each of them
                    foreach ($stock_history_qty_available as $entry) {
                        if ($entry['qty'] >= $global_quantity_to_decrement) {
                            $quantity_to_decrement_by_stock[$entry['id_stock']][$entry['id_stock_mvt']] = $global_quantity_to_decrement;
                            $global_quantity_to_decrement = 0;
                        } else {
                            $quantity_to_decrement_by_stock[$entry['id_stock']][$entry['id_stock_mvt']] = $entry['qty'];
                            $global_quantity_to_decrement -= $entry['qty'];
                        }
                        if ($global_quantity_to_decrement <= 0) {
                            break;
                        }
                    }
                    // for each stock, decrements it and logs the mvts
                    foreach ($stock_collection as $stock) {
                        if (array_key_exists($stock->id, $quantity_to_decrement_by_stock) && is_array($quantity_to_decrement_by_stock[$stock->id])) {
                            $total_quantity_for_current_stock = 0;
                            foreach ($quantity_to_decrement_by_stock[$stock->id] as $id_mvt_referrer => $qte) {
                                $mvt_params = array('id_stock' => $stock->id, 'physical_quantity' => $qte, 'id_stock_mvt_reason' => $id_stock_mvt_reason, 'id_order' => $id_order, 'price_te' => $stock->price_te, 'sign' => -1, 'referer' => $id_mvt_referrer, 'id_employee' => (int) $context->employee->id ? (int) $context->employee->id : $employee->id);
                                // saves stock mvt
                                $stock_mvt = new StockMvt();
                                $stock_mvt->hydrate($mvt_params);
                                $stock_mvt->save();
                                $total_quantity_for_current_stock += $qte;
                            }
                            $stock_params = array('physical_quantity' => $stock->physical_quantity - $total_quantity_for_current_stock, 'usable_quantity' => $is_usable ? $stock->usable_quantity - $total_quantity_for_current_stock : $stock->usable_quantity);
                            $return[$stock->id]['quantity'] = $total_quantity_for_current_stock;
                            $return[$stock->id]['price_te'] = $stock->price_te;
                            // saves stock in warehouse
                            $stock->hydrate($stock_params);
                            $stock->update();
                        }
                    }
                    break;
            }
            if (Pack::isPacked($id_product, $id_product_attribute)) {
                $packs = Pack::getPacksContainingItem($id_product, $id_product_attribute, (int) Configuration::get('PS_LANG_DEFAULT'));
                foreach ($packs as $pack) {
                    // Decrease stocks of the pack only if pack is in linked stock mode (option called 'Decrement both')
                    if (!((int) $pack->pack_stock_type == 2) && !((int) $pack->pack_stock_type == 3 && (int) Configuration::get('PS_PACK_STOCK_TYPE') == 2)) {
                        continue;
                    }
                    // Decrease stocks of the pack only if there is not enough items to constituate the actual pack stocks.
                    // How many packs can be constituated with the remaining product stocks
                    $quantity_by_pack = $pack->pack_item_quantity;
                    $stock_available_quantity = $quantity_in_stock - $quantity;
                    $max_pack_quantity = max(array(0, floor($stock_available_quantity / $quantity_by_pack)));
                    $quantity_delta = Pack::getQuantity($pack->id) - $max_pack_quantity;
                    if ($pack->advanced_stock_management == 1 && $quantity_delta > 0) {
                        $product_warehouses = Warehouse::getPackWarehouses($pack->id);
                        $warehouse_stock_found = false;
                        foreach ($product_warehouses as $product_warehouse) {
                            if (!$warehouse_stock_found) {
                                if (Warehouse::exists($product_warehouse)) {
                                    $current_warehouse = new Warehouse($product_warehouse);
                                    $return[] = $this->removeProduct($pack->id, null, $current_warehouse, $quantity_delta, $id_stock_mvt_reason, $is_usable, $id_order, 1);
                                    // The product was found on this warehouse. Stop the stock searching.
                                    $warehouse_stock_found = !empty($return[count($return) - 1]);
                                }
                            }
                        }
                    }
                }
            }
        }
        // if we remove a usable quantity, exec hook
        if ($is_usable) {
            Hook::exec('actionProductCoverage', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'warehouse' => $warehouse));
        }
        return $return;
    }
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:101,代码来源:StockManager.php

示例4: updateQty

    public function updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, Shop $shop = null, $auto_add_cart_rule = true, $id_cart_product = 0, $ext_prop_quantities = null, $ext_qty = 0)
    {
        if (!$shop) {
            $shop = Context::getContext()->shop;
        }
        if (Context::getContext()->customer->id) {
            if ($id_address_delivery == 0 && (int) $this->id_address_delivery) {
                // The $id_address_delivery is null, use the cart delivery address
                $id_address_delivery = $this->id_address_delivery;
            } elseif ($id_address_delivery == 0) {
                // The $id_address_delivery is null, get the default customer address
                $id_address_delivery = (int) Address::getFirstCustomerAddressId((int) Context::getContext()->customer->id);
            } elseif (!Customer::customerHasAddress(Context::getContext()->customer->id, $id_address_delivery)) {
                // The $id_address_delivery must be linked with customer
                $id_address_delivery = 0;
            }
        }
        //$quantity = (int)$quantity;
        $id_product = (int) $id_product;
        $id_product_attribute = (int) $id_product_attribute;
        $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), $shop->id);
        if ($id_product_attribute) {
            $combination = new Combination((int) $id_product_attribute);
            if ($combination->id_product != $id_product) {
                return false;
            }
        }
        $properties = $product->productProperties();
        $quantity = $product->normalizeQty($quantity);
        /* If we have a product combination, the minimal quantity is set with the one of this combination */
        if (!empty($id_product_attribute)) {
            $minimal_quantity = $product->attributeMinQty($id_product_attribute);
        } else {
            $minimal_quantity = $product->minQty();
        }
        if (!Validate::isLoadedObject($product)) {
            die(Tools::displayError());
        }
        if (isset(self::$_nbProducts[$this->id])) {
            unset(self::$_nbProducts[$this->id]);
        }
        if (isset(self::$_totalWeight[$this->id])) {
            unset(self::$_totalWeight[$this->id]);
        }
        Hook::exec('actionBeforeCartUpdateQty', array('cart' => $this, 'product' => $product, 'id_product_attribute' => $id_product_attribute, 'id_customization' => $id_customization, 'quantity' => $quantity, 'operator' => $operator, 'id_address_delivery' => $id_address_delivery, 'shop' => $shop, 'auto_add_cart_rule' => $auto_add_cart_rule));
        if ($quantity <= 0) {
            return $this->deleteProduct($id_product, $id_product_attribute, (int) $id_customization, 0, $id_cart_product);
        } elseif (!$product->available_for_order || Configuration::get('PS_CATALOG_MODE') && !defined('_PS_ADMIN_DIR_')) {
            return false;
        } else {
            if ($id_cart_product == 0 && !PP::qtyPolicyLegacy($properties['pp_qty_policy'])) {
                $result = false;
            } else {
                /* Check if the product is already in the cart */
                $result = $this->containsProduct($id_product, $id_product_attribute, (int) $id_customization, (int) $id_address_delivery, PP::productQtyPolicyLegacy($product) ? 0 : $quantity, $id_cart_product);
            }
            /* Update quantity if product already exist */
            if ($result) {
                if ($operator == 'up' || $operator == 'update') {
                    $sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, IFNULL(stock.quantity_remainder, 0) as quantity_remainder
							FROM ' . _DB_PREFIX_ . 'product p
							' . Product::sqlStock('p', $id_product_attribute, true, $shop) . '
							WHERE p.id_product = ' . $id_product;
                    $result2 = Db::getInstance()->getRow($sql);
                    $product_qty = (int) $result2['quantity'] + (double) $result2['quantity_remainder'];
                    // Quantity for product pack
                    if (Pack::isPack($id_product)) {
                        $product_qty = Pack::getQuantity($id_product, $id_product_attribute);
                    }
                    if ($operator == 'up') {
                        $q = $id_cart_product > 0 || PP::qtyPolicyLegacy($properties['pp_qty_policy']) ? (int) $quantity : 1;
                        $new_qty = PP::resolveQty((int) $result['quantity'] + $q, $result['quantity_fractional']);
                        $new_min_qty = $properties['pp_ext'] == 1 ? (int) $result['quantity'] + $q : $new_qty;
                        $qty = '+ ' . (int) $q;
                    } else {
                        $new_qty = $new_min_qty = $qty = $quantity;
                    }
                    if (!Product::isAvailableWhenOutOfStock((int) $result2['out_of_stock'])) {
                        if ($new_qty > $product_qty) {
                            return false;
                        }
                    }
                } else {
                    if ($operator == 'down') {
                        $q = $id_cart_product > 0 ? (int) $quantity : 1;
                        $new_qty = PP::resolveQty((int) $result['quantity'] - $q, $result['quantity_fractional']);
                        $new_min_qty = $properties['pp_ext'] == 1 ? (int) $result['quantity'] - $q : $new_qty;
                        $qty = '- ' . (int) $q;
                        if ($new_min_qty < $minimal_quantity && (PP::qtyPolicyLegacy($properties['pp_qty_policy'] || $properties['pp_ext'] == 1) ? $minimal_quantity > 1 : $new_qty > 0)) {
                            return -1;
                        }
                    } else {
                        return false;
                    }
                }
                /* Delete product from cart */
                if (($properties['pp_ext'] == 1 ? $new_min_qty : $new_qty) <= 0) {
                    return $this->deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization, $id_address_delivery, $id_cart_product);
                } else {
                    if ($new_min_qty < $minimal_quantity) {
//.........这里部分代码省略.........
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:101,代码来源:Cart.php


注:本文中的Pack::getQuantity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。