本文整理汇总了PHP中Warehouse::getProductWarehouseList方法的典型用法代码示例。如果您正苦于以下问题:PHP Warehouse::getProductWarehouseList方法的具体用法?PHP Warehouse::getProductWarehouseList怎么用?PHP Warehouse::getProductWarehouseList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Warehouse
的用法示例。
在下文中一共展示了Warehouse::getProductWarehouseList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPackWarehouses
/**
* For a given pack, returns the warehouse it can be shipped from
*
* @param int $id_product
* @return int|bool id_warehouse or false
*/
public static function getPackWarehouses($id_product, $id_shop = null)
{
if (!Pack::isPack($id_product)) {
return false;
}
if (is_null($id_shop)) {
$id_shop = Context::getContext()->shop->id;
}
// warehouses of the pack
$pack_warehouses = WarehouseProductLocation::getCollection((int) $id_product);
// products in the pack
$products = Pack::getItems((int) $id_product, Configuration::get('PS_LANG_DEFAULT'));
// array with all warehouses id to check
$list = array();
// fills $list
foreach ($pack_warehouses as $pack_warehouse) {
$list['pack_warehouses'][] = (int) $pack_warehouse->id_warehouse;
}
// for each products in the pack
foreach ($products as $product) {
if ($product->advanced_stock_management) {
// gets the warehouses of one product
$product_warehouses = Warehouse::getProductWarehouseList((int) $product->id, 0, (int) $id_shop);
$list[(int) $product->id] = array();
// fills array with warehouses for this product
foreach ($product_warehouses as $product_warehouse) {
$list[(int) $product->id][] = $product_warehouse['id_warehouse'];
}
}
}
$res = false;
// returns final list
if (count($list) > 1) {
$res = call_user_func_array('array_intersect', $list);
}
return $res;
}
示例2: getPackageList
/**
* Get products grouped by package and by addresses to be sent individualy (one package = one shipping cost).
*
* @return array array(
* 0 => array( // First address
* 0 => array( // First package
* 'product_list' => array(...),
* 'carrier_list' => array(...),
* 'id_warehouse' => array(...),
* ),
* ),
* );
* @todo Add avaibility check
*/
public function getPackageList($flush = false)
{
static $cache = array();
if (isset($cache[(int) $this->id . '_' . (int) $this->id_address_delivery]) && $cache[(int) $this->id . '_' . (int) $this->id_address_delivery] !== false && !$flush) {
return $cache[(int) $this->id . '_' . (int) $this->id_address_delivery];
}
$product_list = $this->getProducts();
// Step 1 : Get product informations (warehouse_list and carrier_list), count warehouse
// Determine the best warehouse to determine the packages
// For that we count the number of time we can use a warehouse for a specific delivery address
$warehouse_count_by_address = array();
$warehouse_carrier_list = array();
$stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
foreach ($product_list as &$product) {
if ((int) $product['id_address_delivery'] == 0) {
$product['id_address_delivery'] = (int) $this->id_address_delivery;
}
if (!isset($warehouse_count_by_address[$product['id_address_delivery']])) {
$warehouse_count_by_address[$product['id_address_delivery']] = array();
}
$product['warehouse_list'] = array();
if ($stock_management_active && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement((int) $product['id_product']))) {
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute'], $this->id_shop);
if (count($warehouse_list) == 0) {
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
}
// Does the product is in stock ?
// If yes, get only warehouse where the product is in stock
$warehouse_in_stock = array();
$manager = StockManagerFactory::getManager();
foreach ($warehouse_list as $key => $warehouse) {
$product_real_quantities = $manager->getProductRealQuantities($product['id_product'], $product['id_product_attribute'], array($warehouse['id_warehouse']), true);
if ($product_real_quantities > 0 || Pack::isPack((int) $product['id_product'])) {
$warehouse_in_stock[] = $warehouse;
}
}
if (!empty($warehouse_in_stock)) {
$warehouse_list = $warehouse_in_stock;
$product['in_stock'] = true;
} else {
$product['in_stock'] = false;
}
} else {
//simulate default warehouse
$warehouse_list = array(0);
$product['in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']) > 0;
}
foreach ($warehouse_list as $warehouse) {
if (!isset($warehouse_carrier_list[$warehouse['id_warehouse']])) {
$warehouse_object = new Warehouse($warehouse['id_warehouse']);
$warehouse_carrier_list[$warehouse['id_warehouse']] = $warehouse_object->getCarriers();
}
$product['warehouse_list'][] = $warehouse['id_warehouse'];
if (!isset($warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']])) {
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']] = 0;
}
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]++;
}
}
unset($product);
arsort($warehouse_count_by_address);
// Step 2 : Group product by warehouse
$grouped_by_warehouse = array();
foreach ($product_list as &$product) {
if (!isset($grouped_by_warehouse[$product['id_address_delivery']])) {
$grouped_by_warehouse[$product['id_address_delivery']] = array('in_stock' => array(), 'out_of_stock' => array());
}
$product['carrier_list'] = array();
$id_warehouse = 0;
foreach ($warehouse_count_by_address[$product['id_address_delivery']] as $id_war => $val) {
if (in_array((int) $id_war, $product['warehouse_list'])) {
$product['carrier_list'] = array_merge($product['carrier_list'], Carrier::getAvailableCarrierList(new Product($product['id_product']), $id_war, $product['id_address_delivery'], null, $this));
if (!$id_warehouse) {
$id_warehouse = (int) $id_war;
}
}
}
if (!isset($grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse])) {
$grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse] = array();
$grouped_by_warehouse[$product['id_address_delivery']]['out_of_stock'][$id_warehouse] = array();
}
if (!$this->allow_seperated_package) {
$key = 'in_stock';
} else {
$key = $product['in_stock'] ? 'in_stock' : 'out_of_stock';
}
//.........这里部分代码省略.........
示例3: removeProduct
/**
* @see StockManagerInterface::removeProduct()
*
* @param int $id_product
* @param int|null $id_product_attribute
* @param Warehouse $warehouse
* @param int $quantity
* @param int $id_stock_mvt_reason
* @param bool $is_usable
* @param int|null $id_order
* @param int $ignore_pack
* @param Employee|null $employee
*
* @return array
* @throws PrestaShopException
*/
public function removeProduct($id_product, $id_product_attribute = null, Warehouse $warehouse, $quantity, $id_stock_mvt_reason, $is_usable = true, $id_order = null, $ignore_pack = 0, $employee = 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) && !$ignore_pack) {
if (Validate::isLoadedObject($product = new Product((int) $id_product))) {
// 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) $id_product, (int) Configuration::get('PS_LANG_DEFAULT'));
// Foreach item
foreach ($products_pack as $product_pack) {
if ($product_pack->advanced_stock_management == 1) {
$product_warehouses = Warehouse::getProductWarehouseList($product_pack->id, $product_pack->id_pack_product_attribute);
$warehouse_stock_found = false;
foreach ($product_warehouses as $product_warehouse) {
if (!$warehouse_stock_found) {
if (Warehouse::exists($product_warehouse['id_warehouse'])) {
$current_warehouse = new Warehouse($product_warehouse['id_warehouse']);
$return[] = $this->removeProduct($product_pack->id, $product_pack->id_pack_product_attribute, $current_warehouse, $product_pack->pack_quantity * $quantity, $id_stock_mvt_reason, $is_usable, $id_order);
// The product was found on this warehouse. Stop the stock searching.
$warehouse_stock_found = !empty($return[count($return) - 1]);
}
}
}
}
}
}
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)) {
$return = array_merge($return, $this->removeProduct($id_product, $id_product_attribute, $warehouse, $quantity, $id_stock_mvt_reason, $is_usable, $id_order, 1));
}
} else {
return false;
}
} 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':
/** @var Stock $stock */
// 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' => (int) $context->employee->id ? (int) $context->employee->id : $employee->id, 'employee_firstname' => $context->employee->firstname ? $context->employee->firstname : $employee->firstname, 'employee_lastname' => $context->employee->lastname ? $context->employee->lastname : $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;
//.........这里部分代码省略.........
示例4: initContentForQuantities
public function initContentForQuantities()
{
if ($this->object->id) {
$tfowlgstly = "show_quantities";
${"GLOBALS"}["ygzeqkb"] = "show_quantities";
$gmgclvkrjy = "attributes";
${"GLOBALS"}["jhngqfjufp"] = "attributes";
$cggvbxsk = "attributes";
${${"GLOBALS"}["jhngqfjufp"]} = $this->object->getAttributesResume($this->context->language->id);
${"GLOBALS"}["aofqmvff"] = "attribute";
${"GLOBALS"}["vyyogyvfbtx"] = "attributes";
$nfdcluhk = "attributes";
$khzorwi = "shop_context";
if (empty(${$nfdcluhk})) {
${$cggvbxsk}[] = array("id_product_attribute" => 0, "attribute_designation" => "");
}
${"GLOBALS"}["klqbahrije"] = "shop_context";
${${"GLOBALS"}["ldfuknydnzr"]} = array();
${${"GLOBALS"}["ymshseez"]} = array();
${"GLOBALS"}["lztnksxrb"] = "group_shop";
foreach (${${"GLOBALS"}["vyyogyvfbtx"]} as ${${"GLOBALS"}["aofqmvff"]}) {
$rvrxkz = "product_designation";
$ycvvjwmxtnm = "attribute";
$dxuqsu = "available_quantity";
${$dxuqsu}[${${"GLOBALS"}["iixdipeiyldv"]}["id_product_attribute"]] = StockAvailable::getQuantityAvailableByProduct((int) $this->object->id, ${$ycvvjwmxtnm}["id_product_attribute"]);
${$rvrxkz}[${${"GLOBALS"}["iixdipeiyldv"]}["id_product_attribute"]] = rtrim($this->object->name[$this->context->language->id] . " - " . ${${"GLOBALS"}["iixdipeiyldv"]}["attribute_designation"], " - ");
}
${${"GLOBALS"}["ueicxl"]} = true;
${$khzorwi} = Shop::getContext();
${${"GLOBALS"}["lztnksxrb"]} = $this->context->shop->getGroup();
$wktpughd = "pack_quantity";
${"GLOBALS"}["eukvwdf"] = "advanced_stock_management_warning";
if (${${"GLOBALS"}["klqbahrije"]} == Shop::CONTEXT_ALL) {
${$tfowlgstly} = false;
} elseif (${${"GLOBALS"}["ohyfjtkcy"]} == Shop::CONTEXT_GROUP) {
if (!$group_shop->share_stock) {
${${"GLOBALS"}["ueicxl"]} = false;
}
} else {
$eksumjgu = "show_quantities";
if ($group_shop->share_stock) {
${$eksumjgu} = false;
}
}
self::$smarty->assign("ps_stock_management", Configuration::get("PS_STOCK_MANAGEMENT"));
self::$smarty->assign("has_attribute", $this->object->hasAttributes());
if (Combination::isFeatureActive()) {
self::$smarty->assign("countAttributes", (int) Db::getInstance()->getValue("SELECT COUNT(id_product) FROM " . _DB_PREFIX_ . "product_attribute WHERE id_product = " . (int) $this->object->id));
}
${${"GLOBALS"}["eukvwdf"]} = false;
if (Configuration::get("PS_ADVANCED_STOCK_MANAGEMENT") && $this->object->advanced_stock_management) {
${"GLOBALS"}["awunkp"] = "p_attributes";
${"GLOBALS"}["qxobmbos"] = "warehouses";
${"GLOBALS"}["cjtetqei"] = "warehouses";
$ukjfpwyojlf = "p_attribute";
${${"GLOBALS"}["iczelyves"]} = Product::getProductAttributesIds($this->object->id);
${"GLOBALS"}["kcjlbgqb"] = "advanced_stock_management_warning";
${"GLOBALS"}["dlsnuhn"] = "warehouses";
${${"GLOBALS"}["qxobmbos"]} = array();
${"GLOBALS"}["ojmjigmfve"] = "p_attributes";
if (!${${"GLOBALS"}["awunkp"]}) {
${${"GLOBALS"}["mdrvdmghqrtc"]}[] = Warehouse::getProductWarehouseList($this->object->id, 0);
}
foreach (${${"GLOBALS"}["ojmjigmfve"]} as ${$ukjfpwyojlf}) {
${"GLOBALS"}["uevlubu"] = "ws";
${"GLOBALS"}["fpbyfow"] = "warehouses";
${"GLOBALS"}["inddsyj"] = "ws";
${${"GLOBALS"}["yrbmurnh"]} = Warehouse::getProductWarehouseList($this->object->id, ${${"GLOBALS"}["bhprusfblhn"]}["id_product_attribute"]);
if (${${"GLOBALS"}["uevlubu"]}) {
${${"GLOBALS"}["fpbyfow"]}[] = ${${"GLOBALS"}["inddsyj"]};
}
}
${${"GLOBALS"}["dlsnuhn"]} = array_unique(${${"GLOBALS"}["cjtetqei"]});
if (empty(${${"GLOBALS"}["mdrvdmghqrtc"]})) {
${${"GLOBALS"}["kcjlbgqb"]} = true;
}
}
if (${${"GLOBALS"}["uucoxnutvd"]}) {
$this->displayWarning($this->getMessage("If you wish to use the advanced stock management, you have to:"));
$this->displayWarning("- " . $this->getMessage("associate your products with warehouses"));
$this->displayWarning("- " . $this->getMessage("associate your warehouses with carriers"));
$this->displayWarning("- " . $this->getMessage("associate your warehouses with the appropriate shops"));
}
${${"GLOBALS"}["qbmqjuoutyh"]} = null;
if (Pack::isPack($this->object->id)) {
${"GLOBALS"}["wdcmwsfvsft"] = "pack_quantity";
$mdjqucflf = "items";
${${"GLOBALS"}["wfbswtei"]} = Pack::getItems((int) $this->object->id, Configuration::get("PS_LANG_DEFAULT"));
$mhikkwxp = "pack_quantities";
${"GLOBALS"}["kamnnzyptd"] = "pack_quantities";
${${"GLOBALS"}["kamnnzyptd"]} = array();
foreach (${$mdjqucflf} as ${${"GLOBALS"}["gpnqjgaosuld"]}) {
if (!$item->isAvailableWhenOutOfStock((int) $item->out_of_stock)) {
$gkwutr = "pack_id_product_attribute";
${${"GLOBALS"}["wkyidmmlbbc"]} = Product::getDefaultAttribute($item->id, 1);
${${"GLOBALS"}["pnfrmcr"]}[] = Product::getQuantity($item->id, ${$gkwutr}) / ($item->pack_quantity !== 0 ? $item->pack_quantity : 1);
}
}
$oissvbm = "pack_quantities";
${${"GLOBALS"}["wdcmwsfvsft"]} = ${$oissvbm}[0];
//.........这里部分代码省略.........