예제 #1
0
 /**
  * Update default stock (switch to website #1 from website #0), add new stock and 2 warehouses; bind warehouses
  * with stocks.
  */
 private function processStocks()
 {
     /* update default stock as Baltic */
     /** @var \Magento\CatalogInventory\Model\Stock $stockBaltic */
     $stockBaltic = $this->mageRepoStock->get(self::DEF_STOCK_ID_DEFAULT);
     $stockBaltic->setStockName('Baltic');
     $stockBaltic->setWebsiteId(self::DEF_WEBSITE_ID_ADMIN);
     $this->mageRepoStock->save($stockBaltic);
     /* create new stock as Russian */
     try {
         $stockRussian = $this->mageRepoStock->get(self::DEF_STOCK_ID_RUSSIAN);
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $stockRussian = $this->_manObj->create(\Magento\CatalogInventory\Model\Stock::class);
         // $stockRussian->setStockId(self::DEF_STOCK_ID_RUSSIAN);
     } finally {
         $stockRussian->setStockName('Russian');
         $stockRussian->setWebsiteId(self::DEF_WEBSITE_ID_ADMIN);
         $this->mageRepoStock->save($stockRussian);
     }
     /* create new warehouses */
     /* Baltic */
     $wrhsBaltic = $this->repoWrhs->getById(self::DEF_STOCK_ID_BALTIC);
     $shoudCreate = is_null($wrhsBaltic->getOdooId());
     $wrhsBaltic->setCode('Baltic');
     $wrhsBaltic->setCurrency('USD');
     $wrhsBaltic->setCountryCode('LV');
     $wrhsBaltic->setNote('Warehouse for Baltic states (LV, LT, EE)');
     $wrhsBaltic->setOdooId(self::DEF_WRHS_ODOO_ID_BALTIC);
     if ($shoudCreate) {
         $this->repoWrhs->create($wrhsBaltic);
     } else {
         $this->repoWrhs->updateById($wrhsBaltic->getId(), $wrhsBaltic);
     }
     /* Russian */
     $wrhsRussian = $this->repoWrhs->getById(self::DEF_STOCK_ID_RUSSIAN);
     if (!$wrhsRussian) {
         $wrhsRussian = new \Praxigento\Odoo\Data\Agg\Warehouse();
     }
     $shoudCreate = is_null($wrhsRussian->getOdooId());
     $wrhsRussian->setCode('Russian');
     $wrhsRussian->setCurrency('USD');
     $wrhsRussian->setCountryCode('RU');
     $wrhsRussian->setNote('Warehouse for Russian Federation');
     $wrhsRussian->setOdooId(self::DEF_WRHS_ODOO_ID_RUSSIAN);
     if ($shoudCreate) {
         $wrhsRussian->setId($stockRussian->getStockId());
         $this->repoWrhs->create($wrhsRussian);
     } else {
         $this->repoWrhs->updateById($wrhsRussian->getId(), $wrhsRussian);
     }
     return;
 }
예제 #2
0
 /**
  * @param ApiWarehouse[] $warehouses
  * @throws \Exception
  */
 public function processWarehouses($warehouses)
 {
     foreach ($warehouses as $item) {
         $odooId = $item->getIdOdoo();
         $found = $this->_repoAggWrhs->getByOdooId($odooId);
         if (!$found) {
             /** @var  $aggData AggWarehouse */
             $aggData = $this->_manObj->create(AggWarehouse::class);
             $aggData->setOdooId($odooId);
             $aggData->setCurrency($item->getCurrency());
             $aggData->setWebsiteId(Cfg::DEF_WEBSITE_ID_ADMIN);
             $aggData->setCode($item->getCode());
             $aggData->setNote('replicated from Odoo');
             $created = $this->_repoAggWrhs->create($aggData);
             if (!$created->getId()) {
                 throw new \Exception('Cannot replicate warehouse.');
             }
         }
     }
 }