Im PaymentModule::validateOrder
gibt es einen Aufruf an die OrderDetail->createList
mit:
// Insert new Order detail list using cart for the current order
$order_detail = new OrderDetail(null, null, $this->context);
$order_detail->createList($order, $this->context->cart, $id_order_state, $order->product_list, 0, true, $package_list[$id_address][$id_package]['id_warehouse']);
$order_detail_list[] = $order_detail;
In OrderDetail->createList
haben wir einen Aufruf an $this->create
foreach Produkt in der Liste. Dies ist, wo die Auftragsdetaildaten „berechnet“, und es gibt ein $this->checkProductStock($product, $id_order_state);
, dass die Bestellung überprüft, ob nicht abgebrochen wird und nicht ein Fehler, und wenn das Produkt hängt ab Lager:
protected function checkProductStock($product, $id_order_state)
{
if ($id_order_state != Configuration::get('PS_OS_CANCELED') && $id_order_state != Configuration::get('PS_OS_ERROR')) {
$update_quantity = true;
if (!StockAvailable::dependsOnStock($product['id_product'])) {
$update_quantity = StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity']);
}
if ($update_quantity) {
$product['stock_quantity'] -= $product['cart_quantity'];
}
if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) {
$this->outOfStock = true;
}
Product::updateDefaultAttribute($product['id_product']);
}
}
Btw, wenn Sie ein Abbrechen Bestellung wird der Bestand mit dieser Bestellmenge zurückgesetzt.
Aber wenn Sie nur wollen Lager verringern, nachdem die Zahlung, die ich in Ihrem Fall eine Config PS_WAITING_PAYMENT mit dem Wert hinzufügen, würde die Aufträge, wenn nicht bestätigt wird, dann überschreibt diese letzte Funktion den Staat wartet auf Zahlung
protected function checkProductStock($product, $id_order_state)
{
if ($id_order_state != Configuration::get('PS_OS_CANCELED') && $id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_WAITING_PAYMENT')) {
$update_quantity = true;
if (!StockAvailable::dependsOnStock($product['id_product'])) {
$update_quantity = StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity']);
}
if ($update_quantity) {
$product['stock_quantity'] -= $product['cart_quantity'];
}
if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) {
$this->outOfStock = true;
}
Product::updateDefaultAttribute($product['id_product']);
}
}
hinzufügen
Wenn Sie die Warte Zahlungsauftrag Zustand nicht logable gesetzt, und der neue Zustand ist logable, wenn Sie den Zustand bestätigt Zahlung ändern sollte Lager abnehmen, da in OrderHistory-> changeIdOrderState gibt es:
...
foreach ($order->getProductsDetail() as $product) {
if (Validate::isLoadedObject($old_os)) {
// if becoming logable => adds sale
if ($new_os->logable && !$old_os->logable) {
ProductSale::addProductSale($product['product_id'], $product['product_quantity']);
// @since 1.5.0 - Stock Management
if (!Pack::isPack($product['product_id']) &&
in_array($old_os->id, $error_or_canceled_statuses) &&
!StockAvailable::dependsOnStock($product['id_product'], (int)$order->id_shop)) {
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
}
}
...