首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >股票PrestaShop

股票PrestaShop
EN

Stack Overflow用户
提问于 2017-03-29 14:43:08
回答 1查看 910关注 0票数 2

我是PrestaShop的新手。我遇到了一个问题,在代码中找不到PrestaShop从库存中减去项目。

当客户创建订单并选择付款时,项目将从库存中减去,但如果客户不付款并返回,商品就不会返回库存。所以我需要了解它在代码中发生的位置,因为我需要编写自动完成它的函数。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-30 08:38:36

PaymentModule::validateOrder中,有一个调用OrderDetail->createList的方法:

代码语言:javascript
运行
复制
// 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;

OrderDetail->createList中,我们在列表中调用了$this->create foreach产品。这就是“计算”订单详细数据的地方,并且有一个$this->checkProductStock($product, $id_order_state);来检查订单是否被取消,而不是错误,以及该产品是否依赖于库存:

代码语言:javascript
运行
复制
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']);
    }
}

顺便说一句,如果你取消了一个订单,股票就会用这个定单量来重置。

但是,如果您只想在付款后减少库存,在您的情况下,我将添加一个配置PS_WAITING_PAYMENT,其值如果订单没有确认,则重写最后一个函数以添加等待付款的状态。

代码语言:javascript
运行
复制
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']);
    }
}

如果将等待付款订单状态设置为“不日志”,而新状态为“可日志”,则当您将状态更改为“确认付款”时,应该会减少库存,因为在OrderHistory->changeIdOrderState中有:

代码语言:javascript
运行
复制
...
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);
            }
        }
    ...
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43096797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档