public function testSuggestQty()
 {
     $productId = 143;
     $qty = 3.5;
     $result = true;
     $stockItemModel = $this->getStockItemModel($productId);
     $stockItemModel->expects($this->once())->method('suggestQty')->with($qty)->will($this->returnValue($result));
     $this->assertEquals($result, $this->model->suggestQty($productId, $qty));
 }
Esempio n. 2
0
 /**
  * Returns suggested quantities for items.
  * Can be used to automatically fix user entered quantities before updating cart
  * so that cart contains valid qty values
  *
  * The $data is an array of ($quoteItemId => (item info array with 'qty' key), ...)
  *
  * @param   array $data
  * @return  array
  */
 public function suggestItemsQty($data)
 {
     foreach ($data as $itemId => $itemInfo) {
         if (!isset($itemInfo['qty'])) {
             continue;
         }
         $qty = (double) $itemInfo['qty'];
         if ($qty <= 0) {
             continue;
         }
         $quoteItem = $this->getQuote()->getItemById($itemId);
         if (!$quoteItem) {
             continue;
         }
         $product = $quoteItem->getProduct();
         if (!$product) {
             continue;
         }
         $data[$itemId]['before_suggest_qty'] = $qty;
         $data[$itemId]['qty'] = $this->stockItemService->suggestQty($product->getId(), $qty);
     }
     return $data;
 }