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


PHP Pack::isPack方法代码示例

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


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

示例1: init

 /**
  * Initialize product controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if ($id_product = (int) Tools::getValue('id_product')) {
         $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
     }
     if (!Validate::isLoadedObject($this->product)) {
         header('HTTP/1.1 404 Not Found');
         header('Status: 404 Not Found');
     } else {
         $this->canonicalRedirection();
     }
     if (!Validate::isLoadedObject($this->product)) {
         $this->errors[] = Tools::displayError('Product not found');
     } else {
         if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) {
             $this->product->quantity = 0;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         /*
          * If the product is associated to the shop
          * and is active or not active but preview mode (need token + file_exists)
          * allow showing the product
          * In all the others cases => 404 "Product is no longer available"
          */
         if (!$this->product->isAssociatedToShop() || !$this->product->active && (Tools::getValue('adtoken') != Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) || !file_exists(_PS_ROOT_DIR_ . '/' . Tools::getValue('ad') . '/index.php'))) {
             header('HTTP/1.1 404 page not found');
             $this->errors[] = Tools::displayError('Product is no longer available.');
         } else {
             if (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) {
                 $this->errors[] = Tools::displayError('You do not have access to this product.');
             }
         }
         // Load category
         if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) {
             // If the previous page was a category and is a parent category of the product use this category as parent category
             if (isset($regs[2]) && is_numeric($regs[2])) {
                 if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
                     $this->category = new Category($regs[2], (int) $this->context->cookie->id_lang);
                 }
             } else {
                 if (isset($regs[5]) && is_numeric($regs[5])) {
                     if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
                         $this->category = new Category($regs[5], (int) $this->context->cookie->id_lang);
                     }
                 }
             }
         } else {
             // Set default product category
             $this->category = new Category($this->product->id_category_default, (int) $this->context->cookie->id_lang);
         }
     }
 }
开发者ID:rrameshsat,项目名称:Prestashop,代码行数:57,代码来源:ProductController.php

示例2: getItemTable

 public static function getItemTable($id_product, $id_lang, $full = false)
 {
     $price_sql = Product::getProductPriceSql('p.id_product', 'pp');
     $sql = "\n\t\t SELECT\n                  p.*,\n\t\t  pl.*,\n\t\t  i.`id_image`,\n\t\t  il.`legend`,\n\t\t  t.`rate`,\n\t\t  cl.`name` AS category_default,\n\t\t  a.quantity AS pack_quantity\n\t\t FROM\n                  `PREFIX_pack` a\n\t\t  LEFT JOIN `PREFIX_product` p ON\n                   p.id_product = a.id_product_item\n\t\t  LEFT JOIN `PREFIX_product_lang` pl ON\n                   p.id_product = pl.id_product AND pl.`id_lang` = {$id_lang}\n\t\t  LEFT JOIN `PREFIX_image` i ON\n                   i.`id_product` = p.`id_product` AND i.`cover` = 1\n\t\t  LEFT JOIN `PREFIX_image_lang` il ON\n                   i.`id_image` = il.`id_image` AND il.`id_lang` = {$id_lang}\n\t\t  LEFT JOIN `PREFIX_category_lang` cl ON\n                   p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = {$id_lang}\n                  {$price_sql}\n\t\t  LEFT JOIN `PREFIX_tax` t ON\n                   t.`id_tax` = pp.`id_tax`\n\t\t WHERE a.`id_product_pack` = {$id_product}";
     $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql);
     $result = Db::getInstance()->ExecuteS($sql);
     if (!$full) {
         return $result;
     }
     $arrayResult = array();
     foreach ($result as $row) {
         if (!Pack::isPack($row['id_product'])) {
             $arrayResult[] = Product::getProductProperties($id_lang, $row);
         }
     }
     return $arrayResult;
 }
开发者ID:redb,项目名称:prestashop,代码行数:17,代码来源:Pack.php

示例3: getItemTable

    public static function getItemTable($id_product, $id_lang, $full = false)
    {
        $result = Db::getInstance()->ExecuteS('
		SELECT p.*, pl.*, i.`id_image`, il.`legend`, t.`rate`, cl.`name` AS category_default, a.quantity AS pack_quantity
		FROM `' . _DB_PREFIX_ . 'pack` a
		LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.id_product = a.id_product_item
		LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.id_product = pl.id_product AND pl.`id_lang` = ' . intval($id_lang) . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . intval($id_lang) . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . intval($id_lang) . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = p.`id_tax`)
		WHERE a.`id_product_pack` = ' . intval($id_product));
        if (!$full) {
            return $result;
        }
        $arrayResult = array();
        foreach ($result as $row) {
            if (!Pack::isPack($row['id_product'])) {
                $arrayResult[] = Product::getProductProperties($id_lang, $row);
            }
        }
        return $arrayResult;
    }
开发者ID:Bruno-2M,项目名称:prestashop,代码行数:23,代码来源:Pack.php

示例4: deleteCustomizedDatas

 /**
  * @param int $id_customization
  * @return bool
  * @deprecated
  */
 public function deleteCustomizedDatas($id_customization)
 {
     Tools::displayAsDeprecated();
     if (Pack::isPack((int) $product['id_product'])) {
         $products_pack = Pack::getItems((int) $product['id_product'], (int) Configuration::get('PS_LANG_DEFAULT'));
         foreach ($products_pack as $product_pack) {
             $tab_product_pack['id_product'] = (int) $product_pack->id;
             $tab_product_pack['id_product_attribute'] = self::getDefaultAttribute($tab_product_pack['id_product'], 1);
             $tab_product_pack['cart_quantity'] = (int) ($product_pack->pack_quantity * $product['cart_quantity']);
             self::updateQuantity($tab_product_pack);
         }
     }
     if (($result = Db::getInstance()->ExecuteS('SELECT `value` FROM `' . _DB_PREFIX_ . 'customized_data` WHERE `id_customization` = ' . (int) $id_customization . ' AND `type` = ' . _CUSTOMIZE_FILE_)) === false) {
         return false;
     }
     foreach ($result as $row) {
         if (!@unlink(_PS_UPLOAD_DIR_ . $row['value']) or !@unlink(_PS_UPLOAD_DIR_ . $row['value'] . '_small')) {
             return false;
         }
     }
     return Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'customization` WHERE `id_customization` = ' . (int) $id_customization) and Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'customized_data` WHERE `id_customization` = ' . (int) $id_customization);
 }
开发者ID:srikanthash09,项目名称:codetestdatld,代码行数:27,代码来源:Product.php

示例5: displayPack

    private function displayPack(Product $obj)
    {
        global $currentIndex, $cookie;
        $boolPack = ($obj->id and Pack::isPack($obj->id) or Tools::getValue('ppack')) ? true : false;
        $packItems = $boolPack ? Pack::getItems($obj->id, $cookie->id_lang) : array();
        echo '
		<tr>
			<td>
				<input type="checkbox" name="ppack" id="ppack" value="1"' . ($boolPack ? ' checked="checked"' : '') . ' onchange="openCloseLayer(\'ppackdiv\');" />
				<label class="t" for="ppack">' . $this->l('Pack') . '</label>
			</td>
			<td>
				<div id="ppackdiv" ' . ($boolPack ? '' : ' style="display: none;"') . '>
					<div id="divPackItems">';
        foreach ($packItems as $packItem) {
            echo $packItem->pack_quantity . ' x ' . $packItem->name . '<span onclick="delPackItem(' . $packItem->id . ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />';
        }
        echo '		</div>
					<input type="hidden" name="inputPackItems" id="inputPackItems" value="';
        if (Tools::getValue('inputPackItems')) {
            echo Tools::getValue('inputPackItems');
        } else {
            foreach ($packItems as $packItem) {
                echo $packItem->pack_quantity . 'x' . $packItem->id . '-';
            }
        }
        echo '" />
					<input type="hidden" name="namePackItems" id="namePackItems" value="';
        if (Tools::getValue('namePackItems')) {
            echo Tools::getValue('namePackItems');
        } else {
            foreach ($packItems as $packItem) {
                echo $packItem->pack_quantity . 'x ' . $packItem->name . '¤';
            }
        }
        echo '" />
					<script type="text/javascript">
						var formProduct;
						var packItems = new Array();
						' . $this->fillPackItems($obj) . '
						' . $this->addPackItem() . '
						' . $this->delPackItem() . '
						delPackItem(0);
					</script>
					<select id="selectPackItems" name="selectPackItems" style="width: 380px;" onfocus="fillPackItems();">
						<option value="0" selected="selected">-- ' . $this->l('Choose') . ' --</option>
					</select>
					<input type="text" name="quantityPackItems" id="quantityPackItems" value="1" size="1" />
					<span onclick="addPackItem();" style="cursor: pointer;"><img src="../img/admin/add.gif" alt="' . $this->l('Add an item to the pack') . '" title="' . $this->l('Add an item to the pack') . '" /></span>
					<br />' . $this->l('Filter:') . ' <input type="text" size="25" name="filterPack" onkeyup="fillPackItems();" class="space" />
				</td>
			</div>
		</tr>';
    }
开发者ID:raulgimenez,项目名称:dreamongraphics_shop,代码行数:54,代码来源:AdminProducts.php

示例6: initPack

 protected function initPack(Product $product)
 {
     $this->tpl_form_vars['is_pack'] = $product->id && Pack::isPack($product->id) || Tools::getValue('ppack') || Tools::getValue('type_product') == Product::PTYPE_PACK;
     $product->packItems = Pack::getItems($product->id, $this->context->language->id);
     $input_pack_items = '';
     if (Tools::getValue('inputPackItems')) {
         $input_pack_items = Tools::getValue('inputPackItems');
     } else {
         foreach ($product->packItems as $pack_item) {
             $input_pack_items .= $pack_item->pack_quantity . 'x' . $pack_item->id . '-';
         }
     }
     $this->tpl_form_vars['input_pack_items'] = $input_pack_items;
     $input_namepack_items = '';
     if (Tools::getValue('namePackItems')) {
         $input_namepack_items = Tools::getValue('namePackItems');
     } else {
         foreach ($product->packItems as $pack_item) {
             $input_namepack_items .= $pack_item->pack_quantity . ' x ' . $pack_item->name . '¤';
         }
     }
     $this->tpl_form_vars['input_namepack_items'] = $input_namepack_items;
 }
开发者ID:jicheng17,项目名称:pengwine,代码行数:23,代码来源:AdminProductsController.php

示例7: reinjectQuantity

 protected function reinjectQuantity($order_detail, $qty_cancel_product, $delete = false)
 {
     // Reinject product
     $reinjectable_quantity = (int) $order_detail->product_quantity - (int) $order_detail->product_quantity_reinjected;
     $quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
     // @since 1.5.0 : Advanced Stock Management
     $product_to_inject = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
     $product = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0) {
         $manager = StockManagerFactory::getManager();
         $movements = StockMvt::getNegativeStockMvts($order_detail->id_order, $order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject);
         $left_to_reinject = $quantity_to_reinject;
         foreach ($movements as $movement) {
             if ($left_to_reinject > $movement['physical_quantity']) {
                 $quantity_to_reinject = $movement['physical_quantity'];
             }
             $left_to_reinject -= $quantity_to_reinject;
             if (Pack::isPack((int) $product->id)) {
                 // Gets items
                 if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0) {
                     $products_pack = Pack::getItems((int) $product->id, (int) Configuration::get('PS_LANG_DEFAULT'));
                     // Foreach item
                     foreach ($products_pack as $product_pack) {
                         if ($product_pack->advanced_stock_management == 1) {
                             $manager->addProduct($product_pack->id, $product_pack->id_pack_product_attribute, new Warehouse($movement['id_warehouse']), $product_pack->pack_quantity * $quantity_to_reinject, null, $movement['price_te'], true);
                         }
                     }
                 }
                 if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)) {
                     $manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
                 }
             } else {
                 $manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
             }
         }
         $id_product = $order_detail->product_id;
         if ($delete) {
             $order_detail->delete();
         }
         StockAvailable::synchronize($id_product);
     } elseif ($order_detail->id_warehouse == 0) {
         StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject, $order_detail->id_shop);
         if ($delete) {
             $order_detail->delete();
         }
     } else {
         $this->errors[] = Tools::displayError('This product cannot be re-stocked.');
     }
 }
开发者ID:evgrishin,项目名称:mh16014,代码行数:49,代码来源:AdminOrdersController.php

示例8: update_cart_by_site_xml


//.........这里部分代码省略.........
                    $item_charge_type = (string) $amount_type->Type;
                    if ($item_charge_type == 'Principal') {
                        $principal = (string) $amount_type->Charge->Amount;
                    }
                    if ($item_charge_type == 'Shipping') {
                        $Shipping = (string) $amount_type->Charge->Amount;
                    }
                    if ($item_charge_type == 'PrincipalPromo') {
                        $principal_promo = (string) $amount_type->Charge->Amount;
                    }
                    if ($item_charge_type == 'ShippingPromo') {
                        $shipping_promo = (string) $amount_type->Charge->Amount;
                    }
                    if ($item_charge_type == 'OtherPromo') {
                        $other_promo = (string) $amount_type->Charge->Amount;
                    }
                }
                $sql = 'INSERT into `' . $prefix . 'order_detail` set
							`id_order` = ' . $order_id . ',
							`product_id` = ' . $product_id . ',
							`product_attribute_id` = ' . $product_attribute_id . ',
							`product_name` = "' . $Title . '",
							`product_quantity` = ' . $Quantity . ',
							`product_quantity_in_stock` = ' . $Quantity . ',
							`product_price` = ' . $Amount . ',
							`product_reference` = "' . $SKU . '",
							`total_price_tax_incl` = ' . $Amount * $Quantity . ',
							`total_price_tax_excl` = ' . $Item_price_excl_tax * $Quantity . ',
							`unit_price_tax_incl` = ' . $Amount . ',
							`unit_price_tax_excl` = ' . $Item_price_excl_tax . ',
							`original_product_price` = ' . $Amount . '
							';
                Db::getInstance()->Execute($sql);
                if (Pack::isPack($product_id)) {
                    $product = new Product((int) $product_id);
                    if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2) {
                        $products_pack = Pack::getItems($product_id, (int) Configuration::get('PS_LANG_DEFAULT'));
                        foreach ($products_pack as $product_pack) {
                            $sql = 'UPDATE `' . $prefix . 'stock_available` set
							`quantity` = `quantity` - ' . $product_pack->pack_quantity * $Quantity . '
							where `id_product` = ' . $product_pack->id . ' and
							`id_product_attribute` = 0
									';
                            Db::getInstance()->Execute($sql);
                            $sql = 'UPDATE `' . $prefix . 'stock_available` set
									`quantity` = `quantity` - ' . $product_pack->pack_quantity * $Quantity . '
									where `id_product` = ' . $product_pack->id . ' and
									`id_product_attribute` = ' . $product_pack->id_pack_product_attribute . '
									';
                            Db::getInstance()->Execute($sql);
                        }
                    }
                    if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)) {
                        $sql = 'UPDATE `' . $prefix . 'stock_available` set
							`quantity` = `quantity` - ' . $Quantity . '
							where `id_product` = ' . $product_id . ' and
							`id_product_attribute` = 0
							';
                        Db::getInstance()->Execute($sql);
                        if ($product_attribute_id > 0) {
                            $sql = 'UPDATE `' . $prefix . 'stock_available` set
									`quantity` = `quantity` - ' . $Quantity . '
									where `id_product` = ' . $product_id . ' and
									`id_product_attribute` = ' . $product_attribute_id . '
									';
                            Db::getInstance()->Execute($sql);
开发者ID:ankkal,项目名称:SPN_project,代码行数:67,代码来源:NewOrderNotification.php

示例9: 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;
    }
开发者ID:rtajmahal,项目名称:PrestaShop-modules,代码行数:50,代码来源:criteo.php

示例10: 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'];
//.........这里部分代码省略.........
开发者ID:jicheng17,项目名称:vipinsg,代码行数:101,代码来源:StockManager.php

示例11: setWsType

 public function setWsType($type_str)
 {
     $reverse_type_information = array('simple' => Product::PTYPE_SIMPLE, 'pack' => Product::PTYPE_PACK, 'virtual' => Product::PTYPE_VIRTUAL);
     if (!isset($reverse_type_information[$type_str])) {
         return false;
     }
     $type = $reverse_type_information[$type_str];
     if (Pack::isPack((int) $this->id) && $type != Product::PTYPE_PACK) {
         Pack::deleteItems($this->id);
     }
     $this->cache_is_pack = $type == Product::PTYPE_PACK;
     $this->is_virtual = $type == Product::PTYPE_VIRTUAL;
     return true;
 }
开发者ID:yewed,项目名称:share,代码行数:14,代码来源:Product.php

示例12: displayPack

    private function displayPack(Product $obj)
    {
        global $currentIndex, $cookie;
        $boolPack = ($obj->id and Pack::isPack($obj->id) or Tools::getValue('ppack')) ? true : false;
        $packItems = $boolPack ? Pack::getItems($obj->id, $cookie->id_lang) : array();
        echo '
		<tr>
			<td>
				<input type="checkbox" name="ppack" id="ppack" value="1"' . ($boolPack ? ' checked="checked"' : '') . ' onclick="$(\'#ppackdiv\').slideToggle();" />
				<label class="t" for="ppack">' . $this->l('Pack') . '</label>
			</td>
			<td>
				<div id="ppackdiv" ' . ($boolPack ? '' : ' style="display: none;"') . '>
					<div id="divPackItems">';
        foreach ($packItems as $packItem) {
            echo $packItem->pack_quantity . ' x ' . $packItem->name . '<span onclick="delPackItem(' . $packItem->id . ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />';
        }
        echo '		</div>
					<input type="hidden" name="inputPackItems" id="inputPackItems" value="';
        if (Tools::getValue('inputPackItems')) {
            echo Tools::getValue('inputPackItems');
        } else {
            foreach ($packItems as $packItem) {
                echo $packItem->pack_quantity . 'x' . $packItem->id . '-';
            }
        }
        echo '" />
					<input type="hidden" name="namePackItems" id="namePackItems" value="';
        if (Tools::getValue('namePackItems')) {
            echo Tools::getValue('namePackItems');
        } else {
            foreach ($packItems as $packItem) {
                echo $packItem->pack_quantity . ' x ' . $packItem->name . '¤';
            }
        }
        echo '" />
					<input type="hidden" size="2" id="curPackItemId" />

					<p class="clear">' . $this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:') . '
					<br />' . $this->l('You cannot add downloadable products to a pack.') . '</p>
					<input type="text" size="25" id="curPackItemName" />
					<input type="text" name="curPackItemQty" id="curPackItemQty" value="1" size="1" />
					<script language="javascript">
					' . $this->addPackItem() . '
					' . $this->delPackItem() . '

					</script>
					<span onclick="addPackItem();" style="cursor: pointer;"><img src="../img/admin/add.gif" alt="' . $this->l('Add an item to the pack') . '" title="' . $this->l('Add an item to the pack') . '" /></span>
				</td>
			</div>
		</tr>';
        // param multipleSeparator:'||' ajouté à cause de bug dans lib autocomplete
        echo '<script type="text/javascript">
								urlToCall = null;
								/* function autocomplete */
								$(function() {
									$(\'#curPackItemName\')
										.autocomplete(\'ajax_products_list.php\', {
											delay: 100,
											minChars: 1,
											autoFill: true,
											max:20,
											matchContains: true,
											mustMatch:true,
											scroll:false,
											cacheLength:0,
											multipleSeparator:\'||\',
											formatItem: function(item) {
												return item[1]+\' - \'+item[0];
											}
										}).result(function(event, item){
											$(\'#curPackItemId\').val(item[1]);
										});
										$(\'#curPackItemName\').setOptions({
											extraParams: {excludeIds : getSelectedIds(), excludeVirtuals : 1}
										});

								});


								function getSelectedIds()
								{
									// input lines QTY x ID-
									var ids = ' . $obj->id . '+\',\';
									ids += $(\'#inputPackItems\').val().replace(/\\d+x/g, \'\').replace(/\\-/g,\',\');
									ids = ids.replace(/\\,$/,\'\');

									return ids;

								}

								function getAccessorieIds()
								{
									var ids = ' . $obj->id . '+\',\';
									ids += $(\'#inputAccessories\').val().replace(/\\-/g,\',\').replace(/\\,$/,\'\');
									ids = ids.replace(/\\,$/,\'\');

									return ids;
								}

//.........这里部分代码省略.........
开发者ID:nicolasjeol,项目名称:hec-ecommerce,代码行数:101,代码来源:AdminProducts.php

示例13: process

 public function process()
 {
     global $cart, $currency;
     parent::process();
     if (!Validate::isLoadedObject($this->product)) {
         $this->errors[] = Tools::displayError('Product not found');
     } else {
         if (!$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) {
             header('HTTP/1.1 404 page not found');
             $this->errors[] = Tools::displayError('Product is no longer available.');
         } elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) {
             $this->errors[] = Tools::displayError('You do not have access to this product.');
         } else {
             self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
             if (!$this->product->active) {
                 self::$smarty->assign('adminActionDisplay', true);
             }
             /* Product pictures management */
             require_once 'images.inc.php';
             if ($this->product->customizable) {
                 self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
                 if (Tools::isSubmit('submitCustomizedDatas')) {
                     $this->pictureUpload($this->product, $cart);
                     $this->textRecord($this->product, $cart);
                     $this->formTargetFormat();
                 } elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) {
                     $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture');
                 }
                 $files = self::$cookie->getFamily('pictures_' . (int) $this->product->id);
                 $textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id);
                 foreach ($textFields as $key => $textField) {
                     $textFields[$key] = str_replace('<br />', "\n", $textField);
                 }
                 self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields));
             }
             /* Features / Values */
             $features = $this->product->getFrontFeatures((int) self::$cookie->id_lang);
             $attachments = $this->product->cache_has_attachments ? $this->product->getAttachments((int) self::$cookie->id_lang) : array();
             /* Category */
             $category = false;
             if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
                 if (isset($regs[2]) and is_numeric($regs[2])) {
                     if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
                         $category = new Category((int) $regs[2], (int) self::$cookie->id_lang);
                     }
                 } elseif (isset($regs[5]) and is_numeric($regs[5])) {
                     if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
                         $category = new Category((int) $regs[5], (int) self::$cookie->id_lang);
                     }
                 }
             }
             if (!$category) {
                 $category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang);
             }
             if (isset($category) and Validate::isLoadedObject($category)) {
                 self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name)));
             } else {
                 self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name));
             }
             self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();');
             if (Pack::isPack((int) $this->product->id) and !Pack::isInStock((int) $this->product->id)) {
                 $this->product->quantity = 0;
             }
             $group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100;
             $id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0;
             $id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_;
             $id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));
             // Tax
             $tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
             self::$smarty->assign('tax_rate', $tax);
             $productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6);
             if (Product::$_taxCalculationMethod == PS_TAX_INC) {
                 $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
             }
             $productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax);
             $ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
             $ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2);
             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' => $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);
//.........这里部分代码省略.........
开发者ID:srikanthash09,项目名称:codetestdatld,代码行数:101,代码来源:ProductController.php

示例14: getProductRealQuantities

    /**
     * @see StockManagerInterface::getProductRealQuantities()
     */
    public function getProductRealQuantities($id_product, $id_product_attribute, $ids_warehouse = null, $usable = false)
    {
        if (!is_null($ids_warehouse)) {
            // in case $ids_warehouse is not an array
            if (!is_array($ids_warehouse)) {
                $ids_warehouse = array($ids_warehouse);
            }
            // casts for security reason
            $ids_warehouse = array_map('intval', $ids_warehouse);
        }
        $client_orders_qty = 0;
        // check if product is present in a pack
        if (!Pack::isPack($id_product) && ($in_pack = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT id_product_pack, quantity FROM ' . _DB_PREFIX_ . 'pack
			WHERE id_product_item = ' . (int) $id_product . '
			AND id_product_attribute_item = ' . ($id_product_attribute ? (int) $id_product_attribute : '0')))) {
            foreach ($in_pack as $value) {
                if (Validate::isLoadedObject($product = new Product((int) $value['id_product_pack'])) && ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0)) {
                    $query = new DbQuery();
                    $query->select('od.product_quantity, od.product_quantity_refunded, pk.quantity');
                    $query->from('order_detail', 'od');
                    $query->leftjoin('orders', 'o', 'o.id_order = od.id_order');
                    $query->where('od.product_id = ' . (int) $value['id_product_pack']);
                    $query->leftJoin('order_history', 'oh', 'oh.id_order = o.id_order AND oh.id_order_state = o.current_state');
                    $query->leftJoin('order_state', 'os', 'os.id_order_state = oh.id_order_state');
                    $query->leftJoin('pack', 'pk', 'pk.id_product_item = ' . (int) $id_product . ' AND pk.id_product_attribute_item = ' . ($id_product_attribute ? (int) $id_product_attribute : '0') . ' AND id_product_pack = od.product_id');
                    $query->where('os.shipped != 1');
                    $query->where('o.valid = 1 OR (os.id_order_state != ' . (int) Configuration::get('PS_OS_ERROR') . '
								   AND os.id_order_state != ' . (int) Configuration::get('PS_OS_CANCELED') . ')');
                    $query->groupBy('od.id_order_detail');
                    if (count($ids_warehouse)) {
                        $query->where('od.id_warehouse IN(' . implode(', ', $ids_warehouse) . ')');
                    }
                    $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
                    if (count($res)) {
                        foreach ($res as $row) {
                            $client_orders_qty += ($row['product_quantity'] - $row['product_quantity_refunded']) * $row['quantity'];
                        }
                    }
                }
            }
        }
        // skip if product is a pack without
        if (!Pack::isPack($id_product) || (Pack::isPack($id_product) && Validate::isLoadedObject($product = new Product((int) $id_product)) && $product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2))) {
            // Gets client_orders_qty
            $query = new DbQuery();
            $query->select('od.product_quantity, od.product_quantity_refunded');
            $query->from('order_detail', 'od');
            $query->leftjoin('orders', 'o', 'o.id_order = od.id_order');
            $query->where('od.product_id = ' . (int) $id_product);
            if (0 != $id_product_attribute) {
                $query->where('od.product_attribute_id = ' . (int) $id_product_attribute);
            }
            $query->leftJoin('order_history', 'oh', 'oh.id_order = o.id_order AND oh.id_order_state = o.current_state');
            $query->leftJoin('order_state', 'os', 'os.id_order_state = oh.id_order_state');
            $query->where('os.shipped != 1');
            $query->where('o.valid = 1 OR (os.id_order_state != ' . (int) Configuration::get('PS_OS_ERROR') . '
						   AND os.id_order_state != ' . (int) Configuration::get('PS_OS_CANCELED') . ')');
            $query->groupBy('od.id_order_detail');
            if (count($ids_warehouse)) {
                $query->where('od.id_warehouse IN(' . implode(', ', $ids_warehouse) . ')');
            }
            $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
            if (count($res)) {
                foreach ($res as $row) {
                    $client_orders_qty += $row['product_quantity'] - $row['product_quantity_refunded'];
                }
            }
        }
        // Gets supply_orders_qty
        $query = new DbQuery();
        $query->select('sod.quantity_expected, sod.quantity_received');
        $query->from('supply_order', 'so');
        $query->leftjoin('supply_order_detail', 'sod', 'sod.id_supply_order = so.id_supply_order');
        $query->leftjoin('supply_order_state', 'sos', 'sos.id_supply_order_state = so.id_supply_order_state');
        $query->where('sos.pending_receipt = 1');
        $query->where('sod.id_product = ' . (int) $id_product . ' AND sod.id_product_attribute = ' . (int) $id_product_attribute);
        if (!is_null($ids_warehouse) && count($ids_warehouse)) {
            $query->where('so.id_warehouse IN(' . implode(', ', $ids_warehouse) . ')');
        }
        $supply_orders_qties = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
        $supply_orders_qty = 0;
        foreach ($supply_orders_qties as $qty) {
            if ($qty['quantity_expected'] > $qty['quantity_received']) {
                $supply_orders_qty += $qty['quantity_expected'] - $qty['quantity_received'];
            }
        }
        // Gets {physical OR usable}_qty
        $qty = $this->getProductPhysicalQuantities($id_product, $id_product_attribute, $ids_warehouse, $usable);
        //real qty = actual qty in stock - current client orders + current supply orders
        return $qty - $client_orders_qty + $supply_orders_qty;
    }
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:94,代码来源:StockManager.php

示例15: ajaxProcessProductQuantity

 public function ajaxProcessProductQuantity()
 {
     if (!Tools::getValue('actionQty')) {
         return Tools::jsonEncode(array('error' => $this->l('Undefined action')));
     }
     $product = new Product((int) Tools::getValue('id_product'), true);
     switch (Tools::getValue('actionQty')) {
         case 'depends_on_stock':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if ((int) Tools::getValue('value') != 0 && (int) Tools::getValue('value') != 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
             }
             if (!$product->advanced_stock_management && (int) Tools::getValue('value') == 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. '))));
             }
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1 && (Pack::isPack($product->id) && !Pack::allUsesAdvancedStockManagement($product->id) && ($product->pack_stock_type == 2 || $product->pack_stock_type == 1 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)))) {
                 die(Tools::jsonEncode(array('error' => $this->l('You cannot use advanced stock management for this pack because') . '</br>' . $this->l('- advanced stock management is not enabled for these products') . '</br>' . $this->l('- you have chosen to decrement products quantities.'))));
             }
             StockAvailable::setProductDependsOnStock($product->id, (int) Tools::getValue('value'));
             break;
         case 'pack_stock_type':
             $value = Tools::getValue('value');
             if ($value === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if ((int) $value != 0 && (int) $value != 1 && (int) $value != 2 && (int) $value != 3) {
                 die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
             }
             if ($product->depends_on_stock && !Pack::allUsesAdvancedStockManagement($product->id) && ((int) $value == 1 || (int) $value == 2 || (int) $value == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2))) {
                 die(Tools::jsonEncode(array('error' => $this->l('You cannot use this stock management option because:') . '</br>' . $this->l('- advanced stock management is not enabled for these products') . '</br>' . $this->l('- advanced stock management is enabled for the pack'))));
             }
             Product::setPackStockType($product->id, $value);
             break;
         case 'out_of_stock':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if (!in_array((int) Tools::getValue('value'), array(0, 1, 2))) {
                 die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
             }
             StockAvailable::setProductOutOfStock($product->id, (int) Tools::getValue('value'));
             break;
         case 'set_qty':
             $value = Tools::getValue('value');
             if ($value !== false) {
                 $value = $product->normalizeQty(trim($value));
             }
             if ($value === false || !is_numeric($value)) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if (Tools::getValue('id_product_attribute') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined id product attribute'))));
             }
             StockAvailable::setQuantity($product->id, (int) Tools::getValue('id_product_attribute'), $value);
             Hook::exec('actionProductUpdate', array('id_product' => (int) $product->id, 'product' => $product));
             // Catch potential echo from modules
             $error = ob_get_contents();
             if (!empty($error)) {
                 ob_end_clean();
                 die(Tools::jsonEncode(array('error' => $error)));
             }
             break;
         case 'advanced_stock_management':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if ((int) Tools::getValue('value') != 1 && (int) Tools::getValue('value') != 0) {
                 die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
             }
             if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. '))));
             }
             $product->setAdvancedStockManagement((int) Tools::getValue('value'));
             if (StockAvailable::dependsOnStock($product->id) == 1 && (int) Tools::getValue('value') == 0) {
                 StockAvailable::setProductDependsOnStock($product->id, 0);
             }
             break;
     }
     die(Tools::jsonEncode(array('error' => false)));
 }
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:82,代码来源:AdminProductsController.php


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