Ejemplo n.º 1
0
 /**
  *
  * @return array
  */
 public function updateAction()
 {
     if ($this->getRequest()->isPost()) {
         $productsParams = $this->getRequest()->getParam('products');
         $parentKey = $this->getRequest()->getParam('key');
         try {
             $SAPConector = new SAPConnectorClient();
             $count = 0;
             $responses = array();
             foreach ($productsParams as $product) {
                 $item = ProductQuery::create()->findByPK($product['itemCode']);
                 $status = $product['status'];
                 $vim = $status == Product::$Status['Inactive'] ? 0 : $product['vim'];
                 $itemParams = array('SWW' => $status, 'U_PCS_Individual_VIM' => $vim);
                 ProductFactory::populate($item, $itemParams);
                 $responses[] = $SAPConector->changeVIM($item->getIndex(), $item->getStatus(), $item->getIndividualVim());
             }
             foreach ($responses as $response) {
                 if ($response->changeVIMResult->code == 200) {
                     $success .= "<br>" . $this->i18n->_("Product VIM with id {$response->changeVIMResult->message} was updated correctly.");
                 } else {
                     $error .= "<br>" . $this->i18n->_("Product VIM with id {$response->changeVIMResult->message} can't be updated.");
                 }
             }
             if (strlen($success) > 0) {
                 $this->setFlash('ok', $success);
             }
             if (strlen($error) > 0) {
                 $this->setFlash('error', $error);
             }
         } catch (Exception $e) {
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('vim/sales-by-product/parent-key/' . $parentKey);
 }