Beispiel #1
0
 /**
  * Delete stock with or not writing-off products
  *
  * @param int $stock_id
  * @param int|null $dst_stock If null than writing-off products else move products to $dst_stock
  * @return bool
  */
 public function delete($stock_id, $dst_stock = null)
 {
     $stock = $this->getById($stock_id);
     if (!$stock) {
         return false;
     }
     $stock_counts = $this->countAll();
     $product_stocks_model = new shopProductStocksModel();
     if (!$dst_stock) {
         if (!$product_stocks_model->deleteStock($stock_id, $stock_counts > 1)) {
             return false;
         }
     } else {
         if ($stock_counts <= 1) {
             return false;
         }
         if (!$product_stocks_model->move($stock_id, $dst_stock)) {
             return false;
         }
     }
     return $this->deleteById($stock_id);
 }