Пример #1
0
 /**
  *
  * @param int $product
  * @return array $status
  */
 private function updateProductInSAP($idProduct)
 {
     $product = ProductQuery::create()->findByPK($idProduct);
     $connectorClient = new SAPConnectorClient();
     $status = array();
     try {
         $productSapExists = SapProductQuery::create()->whereAdd(SapProduct::ITEMCODE, $product->getItemCode())->count();
         //     		echo SapProductQuery::create()->whereAdd(SapProduct::ITEMCODE, $product->getItemCode())->createSql();
         //     		echo $productSapExists;
         //     		die;
         if (!$productSapExists) {
             $result = $connectorClient->createProduct($product);
         } else {
             $result = $connectorClient->updateProduct($product);
         }
     } catch (Exception $e) {
         $status['code'] = 500;
         $status['message'] = $e->getMessage();
         return $status;
     }
     if ($result->SapProductoResult->code == 200) {
         $status['code'] = $result->SapProductoResult->code;
         $status['message'] = $this->i18n->_('The product ') . $product->getIdProduct() . $this->i18n->_(' has been syncronized with SAP');
     } else {
         $status['code'] = $result->SapProductoResult->code;
         $this->setFlash('warning', $result->SapProductoResult->message);
         $status['message'] = $this->i18n->_($result->SapProductoResult->message);
     }
     return $status;
 }
Пример #2
0
 /**
  *
  * Gets all Products from SAP, searches the DB for the itemcode, then updates or creates
  */
 public function syncProductsAction()
 {
     $r = SapProductQuery::create()->whereAdd(SapProduct::INVNTITEM, "Y")->find();
     $errors = 0;
     $new = 0;
     $updated = 0;
     echo "<pre>";
     echo "Name, itemcode, clave madre, resultado, mensaje \n";
     while ($r->valid()) {
         $save = 0;
         $sapProduct = $r->read();
         echo "\"" . trim($sapProduct->getItemname()) . "\", " . $sapProduct->getItemcode() . ", " . $sapProduct->getUMadre9() . ", ";
         if (strlen($sapProduct->getItemcode()) != 11) {
             echo "1, Error! ItemCode invalido: len " . strlen($sapProduct->getItemcode()) . "\n";
             $errors++;
             continue;
         }
         $product = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $sapProduct->getItemcode(), ProductQuery::EQUAL)->findOne();
         if (!$product instanceof Product) {
             $product = new Product();
             $save = 1;
         }
         $brand = BrandQuery::create()->whereAdd(Brand::CODE, substr($sapProduct->getItemcode(), 7, 2))->findOne();
         if (!$brand instanceof Brand) {
             echo "2, Error! No Brand: " . substr($sapProduct->getItemcode(), 7, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdBrand($brand->getIdBrand());
         $color = ColorQuery::create()->whereAdd(Color::CODE, substr($sapProduct->getItemcode(), 9, 2))->findOne();
         if (!$color instanceof Color) {
             echo "3, Error! No Color: " . substr($sapProduct->getItemcode(), 9, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdColor($color->getIdColor());
         $customsTariffCode = CustomsTariffCodeQuery::create()->whereAdd(CustomsTariffCode::CODE, $sapProduct->getCstGrpCode())->findOne();
         if (!$customsTariffCode instanceof CustomsTariffCode) {
             echo "4, Error! No Tax Code: " . $sapProduct->getCstGrpCode() . "\n";
             $errors++;
             continue;
         }
         $product->setIdCustomsTariffCode($customsTariffCode->getIdCustomsTariffCode());
         $productGroup = ProductGroupQuery::create()->whereAdd(ProductGroup::CODE, substr($sapProduct->getItemcode(), 0, 2))->findOne();
         if (!$productGroup instanceof ProductGroup) {
             echo "5, Error! No ProductGroup: " . substr($sapProduct->getItemcode(), 0, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdProductGroup($productGroup->getIdProductGroup());
         $family = FamilyQuery::create()->whereAdd(Family::CODE, substr($sapProduct->getItemcode(), 2, 1))->whereAdd(Family::ID_PRODUCT_GROUP, $productGroup->getIdProductGroup())->findOne();
         if (!$family instanceof Family) {
             echo "6, Error! No Family: " . substr($sapProduct->getItemcode(), 2, 1) . "\n";
             $errors++;
             continue;
         }
         $product->setIdFamily($family->getIdFamily());
         $subfamily = SubfamilyQuery::create()->whereAdd(Subfamily::CODE, substr($sapProduct->getItemcode(), 3, 1))->whereAdd(Subfamily::ID_FAMILY, $family->getIdFamily())->findOne();
         if (!$subfamily instanceof Subfamily) {
             echo "7, Error! No SubFamily: " . substr($sapProduct->getItemcode(), 3, 1) . "\n";
             $errors++;
             continue;
         }
         $product->setIdSubfamily($subfamily->getIdSubfamily());
         $product->setBuyUnit($sapProduct->getBuyUnitMsr());
         $product->setCost(0);
         $product->setIdCurrency(1);
         $product->setIdIncoterm(1);
         $product->setImportant(0);
         $product->setInventaryItem($sapProduct->getInvntItem() == 'Y' ? 1 : 0);
         $product->setInventoryUnit($sapProduct->getInvntryUom());
         $product->setItemCode($sapProduct->getItemcode());
         $product->setItemName($sapProduct->getItemname());
         $product->setKeyMother(substr($sapProduct->getItemcode(), 0, 7));
         $product->setMcDepth($sapProduct->getUMCProfundida());
         $product->setMcFront($sapProduct->getUMCFrente());
         $product->setMcHeight($sapProduct->getUMCAltura());
         $product->setMcParts($sapProduct->getUPzasXCaja());
         $product->setMcWeight($sapProduct->getUMCPeso());
         $product->setNumBuy($sapProduct->getNumInBuy());
         $product->setNumSales($sapProduct->getNumInSales());
         $product->setPurchaseItem($sapProduct->getPrchseItem() == 'Y' ? 1 : 0);
         $product->setPzaDepth($sapProduct->getUPzaprofu());
         $product->setPzaDiameter($sapProduct->getUPzadiametro());
         $product->setPzaFront($sapProduct->getUPzafrente());
         $product->setPzaHeight($sapProduct->getUPpzaaltura());
         $product->setPzaWeight($sapProduct->getUPesoXPza());
         $product->setRescue(0);
         $product->setSaiUnit($sapProduct->getSAlUnitMsr());
         $product->setSellItem($sapProduct->getSellItem() == 'Y' ? 1 : 0);
         $product->setStatus($sapProduct->getSWW());
         if ($save) {
             $this->getProductCatalog()->create($product);
             $new++;
         } else {
             $this->getProductCatalog()->update($product);
             $updated++;
         }
         echo "0, Ok! \n";
     }
     echo "\n\nTotals:\nErrors: " . $errors . "\nNew: " . $new . "\nUpdated: " . $updated;
     die;
 }