2017-03-29 4 views
1

私はPrestaShopで全く新しいです。私は問題を抱えています、PrestaShopが在庫から商品を引くコードで見つけることができません。Stock PrestaShop

お客様が注文を作成して支払いを選択すると、商品は在庫から差し引かれますが、顧客が支払いをして元に戻っても商品が在庫に戻らない場合。ですから、私はコード内でどこで起こっているのか、それを自動的に行う関数を書くために理解する必要があります。私たちは、リスト内の$this->create foreachの製品への呼び出しを持ってOrderDetail->createList

// 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; 

PaymentModule::validateOrder

答えて

6

OrderDetail->createListへの呼び出しがあります。そのための詳細データは「計算された」であり、そこに注文がキャンセルされていないかどうかを確認$this->checkProductStock($product, $id_order_state);ないエラーで、これはどこでその製品在庫に依存している場合:あなたがキャンセルした場合、

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']); 
    } 
} 

ところでその注文金額で在庫がリセットされます。

しかし、あなたは唯一の支払い後の在庫を減らしたい場合は確認されていない、そして支払い

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']); 
    } 
} 
を待っている状態を追加するには、この最後の関数をオーバーライドする場合は、あなたのケースで、私は値と設定PS_WAITING_PAYMENTを追加する注文が持っています

あなたがlogableないのを待って支払指図の状態を設定し、あなたが確認の支払いに状態を変更したときOrderHistory-> changeIdOrderStateに存在するため、新しい状態は、それが株価を下げる必要があり、logableの場合:

... 
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); 
      } 
     } 
    ...