Esempio n. 1
0
 /**
  * @param \Magento\Framework\Object $observer
  * @return \Magento\Quote\Model\Quote\Item
  */
 public function processTaxData($observer)
 {
     /** @var  \Magento\Quote\Model\Quote\Item $item */
     $item = $observer->getEvent()->getItem();
     $item->setRowTotal($this->getRowTotal($item))->setRowTotalInclTax($this->getRowTotalInclTax($item))->setPrice($this->getUnitDisplayPriceExclTax($item))->setPriceInclTax($this->getUnitDisplayPriceInclTax($item));
     return $item;
 }
Esempio n. 2
0
 /**
  * Operate with gift messages on checkout proccess
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function checkoutEventCreateGiftMessage($observer)
 {
     $giftMessages = $observer->getEvent()->getRequest()->getParam('giftmessage');
     $quote = $observer->getEvent()->getQuote();
     /* @var $quote \Magento\Sales\Model\Quote */
     if (is_array($giftMessages)) {
         foreach ($giftMessages as $entityId => $message) {
             $giftMessage = $this->_messageFactory->create();
             switch ($message['type']) {
                 case 'quote':
                     $entity = $quote;
                     break;
                 case 'quote_item':
                     $entity = $quote->getItemById($entityId);
                     break;
                 case 'quote_address':
                     $entity = $quote->getAddressById($entityId);
                     break;
                 case 'quote_address_item':
                     $entity = $quote->getAddressById($message['address'])->getItemById($entityId);
                     break;
                 default:
                     $entity = $quote;
                     break;
             }
             if ($entity->getGiftMessageId()) {
                 $giftMessage->load($entity->getGiftMessageId());
             }
             if (trim($message['message']) == '') {
                 if ($giftMessage->getId()) {
                     try {
                         $giftMessage->delete();
                         $entity->setGiftMessageId(0)->save();
                     } catch (\Exception $e) {
                     }
                 }
                 continue;
             }
             try {
                 $giftMessage->setSender($message['from'])->setRecipient($message['to'])->setMessage($message['message'])->save();
                 $entity->setGiftMessageId($giftMessage->getId())->save();
             } catch (\Exception $e) {
             }
         }
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * @param \Magento\Framework\Object $observer
  *
  * @return void
  */
 public function sendEmail($observer)
 {
     /** @var  \Magento\Quote\Model\Quote $quote */
     $quote = $observer->getEvent()->getQuote();
     /** @var  \Magento\Sales\Model\Order $order */
     $order = $observer->getEvent()->getOrder();
     /**
      * a flag to set that there will be redirect to third party after confirmation
      */
     $redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
     if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
         try {
             $this->orderSender->send($order);
         } catch (\Exception $e) {
             $this->logger->critical($e);
         }
     }
 }
Esempio n. 4
0
 /**
  * Delete Product scripts after deleting product
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function deleteProductGoogleExperimentScript($observer)
 {
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $observer->getEvent()->getProduct();
     $this->_modelCode->loadByEntityIdAndType($product->getId(), \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT, $product->getStoreId());
     if ($this->_modelCode->getId()) {
         $this->_modelCode->delete();
     }
     return $this;
 }
Esempio n. 5
0
 /**
  * Delete Product scripts after deleting product
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function deleteCmsGoogleExperimentScript($observer)
 {
     /** @var $cmsPage \Magento\Cms\Model\Page */
     $cmsPage = $observer->getEvent()->getObject();
     $this->_modelCode->loadByEntityIdAndType($cmsPage->getId(), \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PAGE);
     if ($this->_modelCode->getId()) {
         $this->_modelCode->delete();
     }
     return $this;
 }
Esempio n. 6
0
 /**
  * Delete Product scripts after deleting product
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function deleteCategoryGoogleExperimentScript($observer)
 {
     /** @var $category \Magento\Catalog\Model\Category */
     $category = $observer->getEvent()->getCategory();
     $this->_modelCode->loadByEntityIdAndType($category->getId(), \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_CATEGORY, $category->getStoreId());
     if ($this->_modelCode->getId()) {
         $this->_modelCode->delete();
     }
     return $this;
 }
Esempio n. 7
0
 /**
  * Reset validation data
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function checkoutSubmitAllAfter($observer)
 {
     $method = false;
     if ($order = $observer->getEvent()->getOrder()) {
         $method = $order->getPayment()->getMethodInstance();
     } elseif ($orders = $observer->getEvent()->getOrders()) {
         if ($order = array_shift($orders)) {
             $method = $order->getPayment()->getMethodInstance();
         }
     }
     if ($method && $method->getIsCentinelValidationEnabled()) {
         $method->getCentinelValidator()->reset();
     }
     return $this;
 }
Esempio n. 8
0
 /**
  * Delete product item from Google Content
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function deleteProductItem($observer)
 {
     $product = $observer->getEvent()->getProduct();
     $items = $this->_getItemsCollection($product);
     try {
         $this->_operationsFactory->create()->deleteItems($items);
     } catch (\Zend_Gdata_App_CaptchaRequiredException $e) {
         $this->messageManager->addError('Cannot delete Google Content Item. Google requires CAPTCHA.');
     }
     return $this;
 }
Esempio n. 9
0
 /**
  * Set status of link
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function setLinkStatus($observer)
 {
     $order = $observer->getEvent()->getOrder();
     if (!$order->getId()) {
         //order not saved in the database
         return $this;
     }
     /* @var $order \Magento\Sales\Model\Order */
     $status = '';
     $linkStatuses = array('pending' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING, 'expired' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_EXPIRED, 'avail' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE, 'payment_pending' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING_PAYMENT, 'payment_review' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PAYMENT_REVIEW);
     $downloadableItemsStatuses = array();
     $orderItemStatusToEnable = $this->_scopeConfig->getValue(\Magento\Downloadable\Model\Link\Purchased\Item::XML_PATH_ORDER_ITEM_STATUS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $order->getStoreId());
     if ($order->getState() == \Magento\Sales\Model\Order::STATE_HOLDED) {
         $status = $linkStatuses['pending'];
     } elseif ($order->isCanceled() || $order->getState() == \Magento\Sales\Model\Order::STATE_CLOSED || $order->getState() == \Magento\Sales\Model\Order::STATE_COMPLETE) {
         $expiredStatuses = array(\Magento\Sales\Model\Order\Item::STATUS_CANCELED, \Magento\Sales\Model\Order\Item::STATUS_REFUNDED);
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
                 if (in_array($item->getStatusId(), $expiredStatuses)) {
                     $downloadableItemsStatuses[$item->getId()] = $linkStatuses['expired'];
                 } else {
                     $downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail'];
                 }
             }
         }
     } elseif ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
         $status = $linkStatuses['payment_pending'];
     } elseif ($order->getState() == \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW) {
         $status = $linkStatuses['payment_review'];
     } else {
         $availableStatuses = array($orderItemStatusToEnable, \Magento\Sales\Model\Order\Item::STATUS_INVOICED);
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
                 if ($item->getStatusId() == \Magento\Sales\Model\Order\Item::STATUS_BACKORDERED && $orderItemStatusToEnable == \Magento\Sales\Model\Order\Item::STATUS_PENDING && !in_array(\Magento\Sales\Model\Order\Item::STATUS_BACKORDERED, $availableStatuses, true)) {
                     $availableStatuses[] = \Magento\Sales\Model\Order\Item::STATUS_BACKORDERED;
                 }
                 if (in_array($item->getStatusId(), $availableStatuses)) {
                     $downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail'];
                 }
             }
         }
     }
     if (!$downloadableItemsStatuses && $status) {
         foreach ($order->getAllItems() as $item) {
             if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
                 $downloadableItemsStatuses[$item->getId()] = $status;
             }
         }
     }
     if ($downloadableItemsStatuses) {
         $linkPurchased = $this->_createItemsCollection()->addFieldToFilter('order_item_id', array('in' => array_keys($downloadableItemsStatuses)));
         foreach ($linkPurchased as $link) {
             if ($link->getStatus() != $linkStatuses['expired'] && !empty($downloadableItemsStatuses[$link->getOrderItemId()])) {
                 $link->setStatus($downloadableItemsStatuses[$link->getOrderItemId()])->save();
             }
         }
     }
     return $this;
 }
Esempio n. 10
0
 /**
  * Delete Braintree customer when Magento customer is deleted
  * 
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function deleteBraintreeCustomer(\Magento\Framework\Object $observer)
 {
     if (!$this->config->isActive()) {
         return $this;
     }
     $customer = $observer->getEvent()->getCustomer();
     $customerId = $this->helper->generateCustomerId($customer->getId(), $customer->getEmail());
     if ($this->vault->exists($customerId)) {
         $this->vault->deleteCustomer($customerId);
     }
     return $this;
 }
Esempio n. 11
0
 /**
  * Setting attribute tab block for bundle
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function setAttributeTabBlock($observer)
 {
     $product = $observer->getEvent()->getProduct();
     if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
         $this->_helperCatalog->setAttributeTabBlock('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Attributes');
     }
     return $this;
 }
Esempio n. 12
0
 /**
  * Set gift messages to order from quote address
  *
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function salesEventConvertQuoteToOrder($observer)
 {
     $observer->getEvent()->getOrder()->setGiftMessageId($observer->getEvent()->getQuote()->getGiftMessageId());
     return $this;
 }