Example #1
0
 /**
  * Convert order item to quote item
  *
  * @param \Magento\Sales\Model\Order\Item $orderItem
  * @param true|null $qtyFlag if is null set product qty like in order
  * @return $this
  */
 public function addOrderItem($orderItem, $qtyFlag = null)
 {
     /* @var $orderItem \Magento\Sales\Model\Order\Item */
     if ($orderItem->getParentItem() === null) {
         $storeId = $this->_storeManager->getStore()->getId();
         try {
             $product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId);
         } catch (NoSuchEntityException $e) {
             return $this;
         }
         $info = $orderItem->getProductOptionByCode('info_buyRequest');
         $info = new \Magento\Framework\Object($info);
         if ($qtyFlag === null) {
             $info->setQty($orderItem->getQtyOrdered());
         } else {
             $info->setQty(1);
         }
         $this->addProduct($product, $info);
     }
     return $this;
 }
Example #2
0
 /**
  * @param Item $item
  * @return Product
  */
 protected function makeProduct(Item $item)
 {
     $product = SignifydModel::Make("\\Signifyd\\Models\\Product");
     $product->itemId = $item->getSku();
     $product->itemName = $item->getName();
     $product->itemPrice = $item->getPrice();
     $product->itemQuantity = (int) $item->getQtyOrdered();
     $product->itemUrl = $item->getProduct()->getProductUrl();
     $product->itemWeight = $item->getProduct()->getWeight();
     return $product;
 }
Example #3
0
 /**
  * Convert order item to quote item
  *
  * @param \Magento\Sales\Model\Order\Item $orderItem
  * @param true|null $qtyFlag if is null set product qty like in order
  * @return $this
  */
 public function addOrderItem($orderItem, $qtyFlag = null)
 {
     /* @var $orderItem \Magento\Sales\Model\Order\Item */
     if (is_null($orderItem->getParentItem())) {
         $product = $this->_productFactory->create()->setStoreId($this->_storeManager->getStore()->getId())->load($orderItem->getProductId());
         if (!$product->getId()) {
             return $this;
         }
         $info = $orderItem->getProductOptionByCode('info_buyRequest');
         $info = new \Magento\Framework\Object($info);
         if (is_null($qtyFlag)) {
             $info->setQty($orderItem->getQtyOrdered());
         } else {
             $info->setQty(1);
         }
         $this->addProduct($product, $info);
     }
     return $this;
 }
Example #4
0
 /**
  * Retrieve tracking variables for an order item
  *
  * @param \Magento\Sales\Model\Order\Item $item The order item
  *
  * @return array
  */
 private function getOrderItemVariables($item)
 {
     $variables = [];
     if (!$item->isDummy()) {
         $itemId = $item->getId();
         $prefix = "order.items.{$itemId}";
         $variables[$prefix . '.sku'] = $item->getSku();
         $variables[$prefix . '.product_id'] = $item->getProductId();
         $variables[$prefix . '.qty'] = $item->getQtyOrdered();
         $variables[$prefix . '.price'] = $item->getBasePrice();
         $variables[$prefix . '.row_total'] = $item->getRowTotal();
         $variables[$prefix . '.label'] = $item->getName();
         $variables[$prefix . '.salesrules'] = $item->getAppliedRuleIds();
         if ($product = $item->getProduct()) {
             $categoriesId = $product->getCategoryIds();
             if (count($categoriesId)) {
                 $variables[$prefix . '.category_ids'] = implode(",", $categoriesId);
             }
         }
     }
     return $variables;
 }
Example #5
0
 /**
  * Convert order item to quote item
  *
  * @param \Magento\Sales\Model\Order\Item $orderItem
  * @param true|null $qtyFlag if is null set product qty like in order
  * @return $this
  */
 public function addOrderItem($orderItem, $qtyFlag = null)
 {
     /* @var $orderItem \Magento\Sales\Model\Order\Item */
     if ($orderItem->getParentItem() === null) {
         $storeId = $this->_storeManager->getStore()->getId();
         try {
             /**
              * We need to reload product in this place, because products
              * with the same id may have different sets of order attributes.
              */
             $product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId, true);
         } catch (NoSuchEntityException $e) {
             return $this;
         }
         $info = $orderItem->getProductOptionByCode('info_buyRequest');
         $info = new \Magento\Framework\DataObject($info);
         if ($qtyFlag === null) {
             $info->setQty($orderItem->getQtyOrdered());
         } else {
             $info->setQty(1);
         }
         $this->addProduct($product, $info);
     }
     return $this;
 }