本文整理汇总了PHP中Pack::getPacksContainingItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Pack::getPacksContainingItem方法的具体用法?PHP Pack::getPacksContainingItem怎么用?PHP Pack::getPacksContainingItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pack
的用法示例。
在下文中一共展示了Pack::getPacksContainingItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPacksContainingItem
/**
* Get all Packs that contains the given item in the corresponding declination.
*
* @param Product $item
* @param integer $item_attribute_id
* @param integer $id_lang Optional
* @return Array[Pack] The packs that contains the given item, with special dynamic attribute [pack_item_quantity]
*/
public function getPacksContainingItem($item, $item_attribute_id, $id_lang = false)
{
if ($id_lang === false) {
$configuration = Adapter_ServiceLocator::get('Core_Business_ConfigurationInterface');
$id_lang = (int) $configuration->get('PS_LANG_DEFAULT');
}
return Pack::getPacksContainingItem($item->id, $item_attribute_id, $id_lang);
}
示例2: 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;
}