/**
  * @param \Praxigento\Odoo\Data\Odoo\Inventory\Product\Warehouse\Lot[] $lots
  * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
  */
 public function processLots($lots, $stockItem)
 {
     $qtyTotal = 0;
     $stockItemId = $stockItem->getItemId();
     foreach ($lots as $lot) {
         $qtyTotal += $this->_subLot->processLot($stockItemId, $lot);
     }
     /* update stock item qty */
     $stockItem->setQty($qtyTotal);
     $isInStock = $qtyTotal > 0;
     $stockItem->setIsInStock($isInStock);
     $this->_mageRepoStockItem->save($stockItem);
     /* cleanup extra lots */
     $this->_subLot->cleanupLots($stockItemId, $lots);
 }
 /**
  * @inheritdoc
  */
 public function updateStockItemBySku($productSku, \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem)
 {
     $productId = $this->resolveProductId($productSku);
     $websiteId = $stockItem->getWebsiteId() ?: null;
     $origStockItem = $this->getStockItem($productId, $websiteId);
     $data = $stockItem->getData();
     if ($origStockItem->getItemId()) {
         unset($data['item_id']);
     }
     $origStockItem->addData($data);
     $origStockItem->setProductId($productId);
     return $this->stockItemRepository->save($origStockItem)->getItemId();
 }
 private function _createQty($stockItemId, $lotId, $total)
 {
     $tbl = Quantity::ENTITY_NAME;
     $bind = [Quantity::ATTR_STOCK_ITEM_REF => $stockItemId, Quantity::ATTR_LOT_REF => $lotId, Quantity::ATTR_TOTAL => $total];
     $result = $this->_repoGeneric->addEntity($tbl, $bind);
     /* update qty of the stock item */
     $stockItem = $this->_repoMageStockItem->get($stockItemId);
     $qty = $stockItem->getQty();
     $qty += $total;
     $stockItem->setQty($qty);
     $stockItem->setIsInStock(true);
     $this->_repoMageStockItem->save($stockItem);
     return $result;
 }
 /**
  * Prepare stock item data for save
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 protected function saveStockItemData($product)
 {
     $stockItemData = $product->getStockData();
     $stockItemData['product_id'] = $product->getId();
     if (!isset($stockItemData['website_id'])) {
         $stockItemData['website_id'] = $this->stockConfiguration->getDefaultScopeId();
     }
     $stockItemData['stock_id'] = $this->stockRegistry->getStock($stockItemData['website_id'])->getStockId();
     foreach ($this->paramListToCheck as $dataKey => $configPath) {
         if (null !== $product->getData($configPath['item']) && null === $product->getData($configPath['config'])) {
             $stockItemData[$dataKey] = false;
         }
     }
     $originalQty = $product->getData('stock_data/original_inventory_qty');
     if (strlen($originalQty) > 0) {
         $stockItemData['qty_correction'] = (isset($stockItemData['qty']) ? $stockItemData['qty'] : 0) - $originalQty;
     }
     // todo resolve issue with builder and identity field name
     $stockItem = $this->stockRegistry->getStockItem($stockItemData['product_id'], $stockItemData['website_id']);
     $stockItem->addData($stockItemData);
     $this->stockItemRepository->save($stockItem);
     return $this;
 }