2

如何避免仍在“处理”中的产品数量减少并在订单发货或交付时更新?

我已经编辑了这部分代码orderdetail.php并将其添加$id_order_state != Configuration::get('PS_OS_PREPARATION')到 if 语句中。是的,处理时数量不会减少,但发货时也不会减少。请帮助我被困在这里。

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_OS_PREPARATION')) {
        $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']);
    }
}
4

1 回答 1

0

OrderDetail 对象只为每个 Order 创建一次,之后即使您更改 Order State 也不会更新。因此,当您的 OrderDetail 对象被创建时,您的修改将不会更新库存,因为它没有正确的状态。并且当您稍后更改 Order State 时,checkProductStock将永远不会再次调用该方法。

您可以创建一个挂钩的自定义模块(女巫在类的方法actionOrderStatusPostUpdate内触发。在您的模块中,如果状态为“已发货”,您将复制该方法并从挂钩中调用它。changeIdOrderState()OrderHistory()checkProductStock()


编辑

如果要直接在核心中添加:

编辑classes/order/OrderHistory.php

在方法changeIdOrderState()中更改最后几行:

    // executes hook
    Hook::exec('actionOrderStatusPostUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int)$order->id, ), null, false, true, false, $order->id_shop);

    // Here change 4 to the desired id_order_state
    if ($new_order_state == 4)
    {
        $virtual_products = $order->getVirtualProducts();
        foreach ($virtual_products as $virtual_product)
        {
            $this->checkProductStock($virtual_product['product_id'], $new_order_state);
        }
    }

    ShopUrl::resetMainDomainCache();
}

之后在这个类中添加一个新方法:

protected function checkProductStock($product, $id_order_state)
{
    $update_quantity = true;
    if (!StockAvailable::dependsOnStock($product['product_id']))
    {
        StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity']);
    }

    Product::updateDefaultAttribute($product['product_id']);
}

此代码未经测试。


我建议您在覆盖中执行此操作:

在witch中创建一个/overrides/classes/order/OrderHistory.php包含这两个方法的新文件并将类定义更改为,添加此文件后class OrderHistory extends OrderHistoryCore {必须删除。/cache/class_index.php

于 2016-04-28T08:43:55.577 回答