【问题标题】:Prestashop - Cancelled order product quantity not increased in stock quantityPrestashop - 取消订单产品数量未增加库存数量
【发布时间】:2015-11-13 13:09:52
【问题描述】:

我正在为某些产品使用 Prestashop Advance Stock Management System。当我使用产品下订单时(启用了高级库存管理),数量是从实际输入值(允许我们手动输入数量的输入框)中扣除的,而不是从库存中扣除的(我可以在库存管理列表中看到相同的数量)。在我将订单状态更改为“已发货/已开票”后,库存数量会减少。

当我取消该订单时,库存数量不会增加。我想在取消订单时自动增加库存数量。我是新手,我不知道该怎么做。请帮我解决这个问题。

提前致谢

【问题讨论】:

  • 我没有在商店检查过这个问题,但从逻辑上看它看起来是正确的。我的意思是,您发货了订单“库存 - 数量”,然后您取消订单(无库存操作),然后您需要取回产品,也许检查并更新数量,例如如果产品还是新的等等。
  • 但是我需要的是,取消订单时产品数量应该会自动增加。
  • 我的解决方案对您有帮助吗?你没有就你的问题或答案给出任何cmets?赏金呢?

标签: prestashop shopping-cart stock prestashop-1.5 cancellation


【解决方案1】:

你应该打电话给OrderDetail::checkProductStock,而后者又会打电话给StockAvailable::updateQuantity

$update_quantity = StockAvailable::updateQuantity(...

有趣的是在更新数量之前有这个条件

if (!StockAvailable::dependsOnStock($product['id_product']))

我建议你 override this method 并在需要时返回 true。

您还可以在复制订单之前设置一个全局标志,然后检查该标志,如果它为 true,则返回 true 以防止更新库存。

override/classes/stock/StockAvailable.php 中的覆盖代码

class StockAvailable extends StockAvailableCore 
{

  public static function dependsOnStock($id_product, $id_shop = null)
  {
    $no_quantity_update = isset($GLOBALS['no_quantity_update']) && $GLOBALS['no_quantity_update'];
    if ($no_quantity_update) 
      return true;
    else return parent::dependsOnStock($id_product, $id_shop = null);
  }

}

要使此覆盖生效,请删除文件cache/class_index.php 以刷新覆盖列表

您的模块代码:

//set to false just to be sure
$GLOBALS['no_quantity_update'] = false;
$this->module->validateOrder($cart->id, Configuration...

您可以直接在核心代码上进行修改,但不建议这样做

您也可以查看different hooks list

【讨论】:

    【解决方案2】:
    $productid = $request->input('productid');
    $userid = $request->input('userid');  
    $quantityt= $request->input('quantity');
    
    $data2=Cart::where('productid',$productid)->where('userid',$userid)->pluck('id');
    
    $productq=Products::where('id',$productid)->get();
    
    foreach($productq as $pro)
    {
        $product = Products::find($pro->id);
        $product->quantity = $pro->quantity + $quantityt;
        $product->save();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多