/** * @param \Praxigento\Odoo\Data\Odoo\Inventory\Product $product */ public function processProductItem($product) { assert($product instanceof \Praxigento\Odoo\Data\Odoo\Inventory\Product); $idOdoo = $product->getIdOdoo(); $sku = $product->getSku(); $name = $product->getName(); $isActive = $product->getIsActive(); $skipReplication = false; // skip replication for inactive products are missed in Mage $priceWholesale = $product->getPriceWholesale(); $weight = $product->getWeight(); $pvWholesale = $product->getPvWholesale(); /* check does product item is already registered in Magento */ if (!$this->_repoRegistry->isProductRegisteredInMage($idOdoo)) { if ($isActive) { /* create new product in Magento */ $idMage = $this->_subProduct->create($sku, $name, $isActive, $priceWholesale, $weight); $this->_repoRegistry->registerProduct($idMage, $idOdoo); $this->_repoPv->registerProductWholesalePv($idMage, $pvWholesale); } else { /* skip product replication for not active and not existing products */ $skipReplication = true; } } else { /* update attributes for magento product */ $idMage = $this->_repoRegistry->getProductMageIdByOdooId($idOdoo); $this->_subProduct->update($idMage, $name, $isActive, $priceWholesale, $weight); $this->_repoPv->updateProductWholesalePv($idMage, $pvWholesale); } if (!$skipReplication) { /* check that categories are registered in Magento */ $categories = $product->getCategories(); $this->_subProdCategory->checkCategoriesExistence($categories); /* check product to categories links (add/remove) */ $this->_subProdCategory->replicateCategories($idMage, $categories); /* update warehouse/lot/qty data */ $warehouses = $product->getWarehouses(); $this->_subProdWarehouse->processWarehouses($idMage, $warehouses); } }
/** * Create existing warehouse data for the stock item in Magento. * * @param int $stockItemRef Mage ID for related stock item * @param double $price warehouse price for stock item * @param double $pv warehouse PV for stock item */ public function updateWarehouseData($stockItemRef, $price, $pv) { /* update or create warehouse entry */ $bind = [EntityWarehouseStockItem::ATTR_PRICE => $price]; $exist = $this->_repoWarehouseEntityStockItem->getById($stockItemRef); if (!$exist) { /* create new entry */ $bind[EntityWarehouseStockItem::ATTR_STOCK_ITEM_REF] = $stockItemRef; $this->_repoWarehouseEntityStockItem->create($bind); } else { $this->_repoWarehouseEntityStockItem->updateById($stockItemRef, $bind); } /* update or create warehouse PV */ $registered = $this->_repoPvMod->getWarehousePv($stockItemRef); if (is_null($registered)) { /* create PV */ $this->_repoPvMod->registerWarehousePv($stockItemRef, $pv); } else { /* update PV */ $this->_repoPvMod->updateWarehousePv($stockItemRef, $pv); } }