本文整理汇总了PHP中Stock::hydrate方法的典型用法代码示例。如果您正苦于以下问题:PHP Stock::hydrate方法的具体用法?PHP Stock::hydrate怎么用?PHP Stock::hydrate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stock
的用法示例。
在下文中一共展示了Stock::hydrate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addProduct
/**
* @see StockManagerInterface::addProduct()
*/
public function addProduct($id_product, $id_product_attribute = 0, Warehouse $warehouse, $quantity, $id_stock_mvt_reason, $price_te, $is_usable = true, $id_supply_order = null)
{
if (!Validate::isLoadedObject($warehouse) || !$price_te || !$quantity || !$id_product) {
return false;
}
$price_te = (double) round($price_te, 6);
if (!StockMvtReason::exists($id_stock_mvt_reason)) {
$id_stock_mvt_reason = Configuration::get('PS_STOCK_MVT_INC_REASON_DEFAULT');
}
$context = Context::getContext();
$mvt_params = array('id_stock' => null, 'physical_quantity' => $quantity, 'id_stock_mvt_reason' => $id_stock_mvt_reason, 'id_supply_order' => $id_supply_order, 'price_te' => $price_te, 'last_wa' => null, 'current_wa' => null, 'id_employee' => $context->employee->id, 'employee_firstname' => $context->employee->firstname, 'employee_lastname' => $context->employee->lastname, 'sign' => 1);
$stock_exists = false;
// switch on MANAGEMENT_TYPE
switch ($warehouse->management_type) {
// case CUMP mode
case 'WA':
$stock_collection = $this->getStockCollection($id_product, $id_product_attribute, $warehouse->id);
// if this product is already in stock
if (count($stock_collection) > 0) {
$stock_exists = true;
// for a warehouse using WA, there is one and only one stock for a given product
$stock = $stock_collection->current();
// calculates WA price
$last_wa = $stock->price_te;
$current_wa = $this->calculateWA($stock, $quantity, $price_te);
$mvt_params['id_stock'] = $stock->id;
$mvt_params['last_wa'] = $last_wa;
$mvt_params['current_wa'] = $current_wa;
$stock_params = array('physical_quantity' => $stock->physical_quantity + $quantity, 'price_te' => $current_wa, 'usable_quantity' => $is_usable ? $stock->usable_quantity + $quantity : $stock->usable_quantity, 'id_warehouse' => $warehouse->id);
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->update();
} else {
$mvt_params['last_wa'] = 0;
$mvt_params['current_wa'] = $price_te;
}
break;
// case FIFO / LIFO mode
// case FIFO / LIFO mode
case 'FIFO':
case 'LIFO':
$stock_collection = $this->getStockCollection($id_product, $id_product_attribute, $warehouse->id, $price_te);
// if this product is already in stock
if (count($stock_collection) > 0) {
$stock_exists = true;
// there is one and only one stock for a given product in a warehouse and at the current unit price
$stock = $stock_collection->current();
$stock_params = array('physical_quantity' => $stock->physical_quantity + $quantity, 'usable_quantity' => $is_usable ? $stock->usable_quantity + $quantity : $stock->usable_quantity);
// updates stock in warehouse
$stock->hydrate($stock_params);
$stock->update();
// sets mvt_params
$mvt_params['id_stock'] = $stock->id;
}
break;
default:
return false;
break;
}
if (!$stock_exists) {
$stock = new Stock();
$stock_params = array('id_product_attribute' => $id_product_attribute, 'id_product' => $id_product, 'physical_quantity' => $quantity, 'price_te' => $price_te, 'usable_quantity' => $is_usable ? $quantity : 0, 'id_warehouse' => $warehouse->id);
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->add();
$mvt_params['id_stock'] = $stock->id;
}
// saves stock mvt
$stock_mvt = new StockMvt();
$stock_mvt->hydrate($mvt_params);
$stock_mvt->add();
return true;
}
示例2: postProcess
//.........这里部分代码省略.........
$_POST['id_supply_order_state'] = 1;
//defaut creation state
// specify global reference currency
$_POST['id_ref_currency'] = Currency::getDefaultCurrency()->id;
// specify supplier name
$_POST['supplier_name'] = Supplier::getNameById($id_supplier);
//specific discount check
$_POST['discount_rate'] = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('discount_rate', 0));
}
// manage each associated product
$this->manageOrderProducts();
// if the threshold is defined and we are saving the order
if (Tools::isSubmit('submitAddsupply_order') && Validate::isInt($quantity_threshold)) {
$this->loadProducts((int) $quantity_threshold);
}
}
// Manage state change
if (Tools::isSubmit('submitChangestate') && Tools::isSubmit('id_supply_order') && Tools::isSubmit('id_supply_order_state')) {
if ($this->tabAccess['edit'] != '1') {
$this->errors[] = Tools::displayError('You do not have permission to change the order status.');
}
// get state ID
$id_state = (int) Tools::getValue('id_supply_order_state', 0);
if ($id_state <= 0) {
$this->errors[] = Tools::displayError('The selected supply order status is not valid.');
}
// get supply order ID
$id_supply_order = (int) Tools::getValue('id_supply_order', 0);
if ($id_supply_order <= 0) {
$this->errors[] = Tools::displayError('The supply order ID is not valid.');
}
if (!count($this->errors)) {
// try to load supply order
$supply_order = new SupplyOrder($id_supply_order);
if (Validate::isLoadedObject($supply_order)) {
// get valid available possible states for this order
$states = SupplyOrderState::getSupplyOrderStates($supply_order->id_supply_order_state);
foreach ($states as $state) {
// if state is valid, change it in the order
if ($id_state == $state['id_supply_order_state']) {
$new_state = new SupplyOrderState($id_state);
$old_state = new SupplyOrderState($supply_order->id_supply_order_state);
// special case of validate state - check if there are products in the order and the required state is not an enclosed state
if ($supply_order->isEditable() && !$supply_order->hasEntries() && !$new_state->enclosed) {
$this->errors[] = Tools::displayError('It is not possible to change the status of this order because you did not order any products.');
}
if (!count($this->errors)) {
$supply_order->id_supply_order_state = $state['id_supply_order_state'];
if ($supply_order->save()) {
if ($new_state->pending_receipt) {
$supply_order_details = $supply_order->getEntries();
foreach ($supply_order_details as $supply_order_detail) {
$is_present = Stock::productIsPresentInStock($supply_order_detail['id_product'], $supply_order_detail['id_product_attribute'], $supply_order->id_warehouse);
if (!$is_present) {
$stock = new Stock();
$stock_params = array('id_product_attribute' => $supply_order_detail['id_product_attribute'], 'id_product' => $supply_order_detail['id_product'], 'physical_quantity' => 0, 'price_te' => $supply_order_detail['price_te'], 'usable_quantity' => 0, 'id_warehouse' => $supply_order->id_warehouse);
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->add();
}
}
}
// if pending_receipt,
// or if the order is being canceled,
// or if the order is received completely
// synchronizes StockAvailable
if ($new_state->pending_receipt && !$new_state->receipt_state || ($old_state->receipt_state || $old_state->pending_receipt) && $new_state->enclosed && !$new_state->receipt_state || $new_state->receipt_state && $new_state->enclosed) {
$supply_order_details = $supply_order->getEntries();
$products_done = array();
foreach ($supply_order_details as $supply_order_detail) {
if (!in_array($supply_order_detail['id_product'], $products_done)) {
StockAvailable::synchronize($supply_order_detail['id_product']);
$products_done[] = $supply_order_detail['id_product'];
}
}
}
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
$redirect = self::$currentIndex . '&token=' . $token;
$this->redirect_after = $redirect . '&conf=5';
}
}
}
}
} else {
$this->errors[] = Tools::displayError('The selected supplier is not valid.');
}
}
}
// updates receipt
if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && Tools::isSubmit('id_supply_order')) {
$this->postProcessUpdateReceipt();
}
// use template to create a supply order
if (Tools::isSubmit('create_supply_order') && Tools::isSubmit('id_supply_order')) {
$this->postProcessCopyFromTemplate();
}
if (!count($this->errors) && $this->is_editing_order || !$this->is_editing_order) {
parent::postProcess();
}
}