コード例 #1
0
ファイル: VimController.php プロジェクト: Eximagen/sochi
 public function changeItemsPriceAction()
 {
     $products = $this->getRequest()->getParam('product');
     // 		echo '<pre>';
     // 		print_r($products );
     // 		die;
     $SAPConnector = new SAPConnectorClient();
     foreach ($products as $product) {
         $productCostLog = new ProductCostLog();
         $originalProduct = ProductQuery::create()->findByPK($product['ItemCode']);
         $productCostLog->setIdCurrencyFrom($originalProduct->getCurrency());
         $productCostLog->setIdCurrencyTo($originalProduct->getCurrency());
         $productCostLog->setPriceFrom($originalProduct->getCost());
         $productCostLog->setPriceTo($product['Price']);
         $productCostLog->setIdProduct($product['ItemCode']);
         $productCostLog->setNotes($product['notes']);
         $result = $SAPConnector->changeProductPrice($product['ItemCode'], $product['Price'], $product['freight'], $product['customsCode']);
         if ($result->changeProductPriceResult->success) {
             try {
                 $this->newLogForUpdateProductCost($productCostLog);
             } catch (Exception $e) {
                 $errors .= $this->i18n->_("The log for {$product['ItemCode']} cannot be created. ") . '<br>';
                 echo $e->getMessage();
                 die;
             }
             $oks .= "The product {$product['ItemCode']} has been updated<br>";
         } else {
             $errors .= $result->changeProductPriceResult->message . "<br>";
         }
     }
     if (!empty($oks)) {
         $this->setFlash('ok', $oks);
     }
     if (!empty($errors)) {
         $this->setFlash('error', $errors);
     }
     $parentKey = ProductQuery::create()->findByPK($product['ItemCode'])->getKeyMother();
     $this->_redirect('vim/sales-by-product/parent-key/' . $parentKey);
 }