Ejemplo n.º 1
0
 /**
  * Ajax handler to response configuration fieldset of composite product in quote items
  *
  * @return void
  */
 public function execute()
 {
     // Prepare data
     $configureResult = new \Magento\Framework\Object();
     try {
         $quoteItemId = (int) $this->getRequest()->getParam('id');
         if (!$quoteItemId) {
             throw new \Magento\Framework\Model\Exception(__('Quote item id is not received.'));
         }
         $quoteItem = $this->_objectManager->create('Magento\\Sales\\Model\\Quote\\Item')->load($quoteItemId);
         if (!$quoteItem->getId()) {
             throw new \Magento\Framework\Model\Exception(__('Quote item is not loaded.'));
         }
         $configureResult->setOk(true);
         $optionCollection = $this->_objectManager->create('Magento\\Sales\\Model\\Quote\\Item\\Option')->getCollection()->addItemFilter(array($quoteItemId));
         $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem));
         $configureResult->setBuyRequest($quoteItem->getBuyRequest());
         $configureResult->setCurrentStoreId($quoteItem->getStoreId());
         $configureResult->setProductId($quoteItem->getProductId());
         $sessionQuote = $this->_objectManager->get('Magento\\Backend\\Model\\Session\\Quote');
         $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId());
     } catch (\Exception $e) {
         $configureResult->setError(true);
         $configureResult->setMessage($e->getMessage());
     }
     // Render page
     $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult);
 }
Ejemplo n.º 2
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testRenderConfigureResult()
 {
     $configureResult = new \Magento\Framework\Object();
     $configureResult->setOk(true)->setProductId(1)->setCurrentCustomerId(1);
     $this->helper->renderConfigureResult($configureResult);
     $customerId = $this->registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
     $this->assertEquals(1, $customerId);
     $errorMessage = $this->registry->registry('composite_configure_result_error_message');
     $this->assertNull($errorMessage);
 }
Ejemplo n.º 3
0
 /**
  * Ajax handler to response configuration fieldset of composite product in order
  *
  * @return void
  */
 public function execute()
 {
     // Prepare data
     $productId = (int) $this->getRequest()->getParam('id');
     $configureResult = new \Magento\Framework\Object();
     $configureResult->setOk(true);
     $configureResult->setProductId($productId);
     $sessionQuote = $this->_objectManager->get('Magento\\Backend\\Model\\Session\\Quote');
     $configureResult->setCurrentStoreId($sessionQuote->getStore()->getId());
     $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId());
     // Render page
     $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult);
 }
Ejemplo n.º 4
0
 /**
  * Ajax handler to response configuration fieldset of composite product in customer's wishlist.
  *
  * @return void
  */
 public function execute()
 {
     $configureResult = new \Magento\Framework\Object();
     try {
         $this->_initData();
         $configureResult->setProductId($this->_wishlistItem->getProductId());
         $configureResult->setBuyRequest($this->_wishlistItem->getBuyRequest());
         $configureResult->setCurrentStoreId($this->_wishlistItem->getStoreId());
         $configureResult->setCurrentCustomerId($this->_wishlist->getCustomerId());
         $configureResult->setOk(true);
     } catch (Exception $e) {
         $configureResult->setError(true);
         $configureResult->setMessage($e->getMessage());
     }
     $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult);
 }
Ejemplo n.º 5
0
 /**
  * IFrame handler for submitted configuration for wishlist item.
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     // Update wishlist item
     $updateResult = new \Magento\Framework\Object();
     try {
         $this->_initData();
         $buyRequest = new \Magento\Framework\Object($this->getRequest()->getParams());
         $this->_wishlist->updateItem($this->_wishlistItem->getId(), $buyRequest)->save();
         $updateResult->setOk(true);
     } catch (Exception $e) {
         $updateResult->setError(true);
         $updateResult->setMessage($e->getMessage());
     }
     $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname'));
     $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCompositeProductResult($updateResult);
     return $this->resultRedirectFactory->create()->setPath('catalog/product/showUpdateResult');
 }
Ejemplo n.º 6
0
 /**
  * IFrame handler for submitted configuration for quote item
  *
  * @return void
  */
 public function execute()
 {
     $updateResult = new \Magento\Framework\Object();
     try {
         $this->_initData();
         $buyRequest = new \Magento\Framework\Object($this->getRequest()->getParams());
         $this->_quote->updateItem($this->_quoteItem->getId(), $buyRequest);
         $this->_quote->collectTotals()->save();
         $updateResult->setOk(true);
     } catch (\Exception $e) {
         $updateResult->setError(true);
         $updateResult->setMessage($e->getMessage());
     }
     $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname'));
     $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCompositeProductResult($updateResult);
     $this->_redirect('catalog/product/showUpdateResult');
 }
Ejemplo n.º 7
0
 /**
  * Ajax handler to response configuration fieldset of composite product in customer's cart
  *
  * @return void
  */
 public function execute()
 {
     $configureResult = new \Magento\Framework\Object();
     try {
         $this->_initData();
         $quoteItem = $this->_quoteItem;
         $optionCollection = $this->_objectManager->create('Magento\\Sales\\Model\\Quote\\Item\\Option')->getCollection()->addItemFilter($quoteItem);
         $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem));
         $configureResult->setOk(true);
         $configureResult->setProductId($quoteItem->getProductId());
         $configureResult->setBuyRequest($quoteItem->getBuyRequest());
         $configureResult->setCurrentStoreId($quoteItem->getStoreId());
         $configureResult->setCurrentCustomerId($this->_customerId);
     } catch (\Exception $e) {
         $configureResult->setError(true);
         $configureResult->setMessage($e->getMessage());
     }
     $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult);
 }
Ejemplo n.º 8
0
 /**
  * Create shipping label action for specific shipment
  *
  * @return void
  */
 public function execute()
 {
     $response = new \Magento\Framework\Object();
     try {
         $shipment = $this->shipmentLoader->load($this->_request);
         if ($this->labelGenerator->create($shipment, $this->_request)) {
             $shipment->save();
             $this->messageManager->addSuccess(__('You created the shipping label.'));
             $response->setOk(true);
         }
     } catch (\Magento\Framework\Model\Exception $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (\Exception $e) {
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         $response->setError(true);
         $response->setMessage(__('An error occurred while creating shipping label.'));
     }
     $this->getResponse()->representJson($response->toJson());
 }
Ejemplo n.º 9
0
 /**
  * Adds configured product to quote
  *
  * @return void
  */
 public function execute()
 {
     $errorMessage = null;
     try {
         $this->_initSession()->_processData();
     } catch (\Exception $e) {
         $this->_reloadQuote();
         $errorMessage = $e->getMessage();
     }
     // Form result for client javascript
     $updateResult = new \Magento\Framework\Object();
     if ($errorMessage) {
         $updateResult->setError(true);
         $updateResult->setMessage($errorMessage);
     } else {
         $updateResult->setOk(true);
     }
     $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname'));
     $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCompositeProductResult($updateResult);
     $this->_redirect('catalog/product/showUpdateResult');
 }
Ejemplo n.º 10
0
 /**
  * Create shipping label action for specific shipment
  *
  * @return void
  */
 public function execute()
 {
     $response = new \Magento\Framework\Object();
     try {
         $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
         $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
         $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
         $shipment = $this->shipmentLoader->load();
         $this->labelGenerator->create($shipment, $this->_request);
         $shipment->save();
         $this->messageManager->addSuccess(__('You created the shipping label.'));
         $response->setOk(true);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $response->setError(true);
         $response->setMessage(__('An error occurred while creating shipping label.'));
     }
     $this->getResponse()->representJson($response->toJson());
 }
Ejemplo n.º 11
0
 /**
  * Save shipment
  * We can save only new shipment. Existing shipments are not editable
  *
  * @return void
  */
 public function execute()
 {
     $data = $this->getRequest()->getParam('shipment');
     if (!empty($data['comment_text'])) {
         $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCommentText($data['comment_text']);
     }
     try {
         $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
         $this->shipmentLoader->setShipment($data);
         $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
         $shipment = $this->shipmentLoader->load();
         if (!$shipment) {
             $this->_forward('noroute');
             return;
         }
         $shipment->register();
         $comment = '';
         if (!empty($data['comment_text'])) {
             $shipment->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front']));
             if (isset($data['comment_customer_notify'])) {
                 $comment = $data['comment_text'];
             }
         }
         if (!empty($data['send_email'])) {
             $shipment->setEmailSent(true);
         }
         $shipment->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
         $responseAjax = new \Magento\Framework\Object();
         $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label'];
         if ($isNeedCreateLabel) {
             $this->labelGenerator->create($shipment, $this->_request);
             $responseAjax->setOk(true);
         }
         $this->_saveShipment($shipment);
         $this->shipmentSender->send($shipment, !empty($data['send_email']), $comment);
         $shipmentCreatedMessage = __('The shipment has been created.');
         $labelCreatedMessage = __('You created the shipping label.');
         $this->messageManager->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage);
         $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getCommentText(true);
     } catch (\Magento\Framework\Model\Exception $e) {
         if ($isNeedCreateLabel) {
             $responseAjax->setError(true);
             $responseAjax->setMessage($e->getMessage());
         } else {
             $this->messageManager->addError($e->getMessage());
             $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id')));
         }
     } catch (\Exception $e) {
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         if ($isNeedCreateLabel) {
             $responseAjax->setError(true);
             $responseAjax->setMessage(__('An error occurred while creating shipping label.'));
         } else {
             $this->messageManager->addError(__('Cannot save shipment.'));
             $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id')));
         }
     }
     if ($isNeedCreateLabel) {
         $this->getResponse()->representJson($responseAjax->toJson());
     } else {
         $this->_redirect('sales/order/view', ['order_id' => $shipment->getOrderId()]);
     }
 }