/**
  * Retrieve Value HTML
  *
  * @param \Magento\Sales\Model\Order\Item $item
  * @return string
  */
 public function getValueHtml($item)
 {
     $result = $this->filterManager->stripTags($item->getName());
     if (!$this->isShipmentSeparately($item)) {
         $attributes = $this->getSelectionAttributes($item);
         if ($attributes) {
             $result = $this->filterManager->sprintf($attributes['qty'], ['format' => '%d']) . ' x ' . $result;
         }
     }
     if (!$this->isChildCalculated($item)) {
         $attributes = $this->getSelectionAttributes($item);
         if ($attributes) {
             $result .= " " . $this->filterManager->stripTags($this->getOrderItem()->getOrder()->formatPrice($attributes['price']));
         }
     }
     return $result;
 }
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
 /**
  * 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 #4
0
 /**
  * Returns the name for a sales item.
  * Configurable products will have their chosen options added to their name.
  * Bundle products will have their chosen child product names added.
  * Grouped products will have their parents name prepended.
  * All others will have their own name only.
  *
  * @param Item $item the sales item model.
  *
  * @return string
  */
 protected function buildItemName(Item $item)
 {
     $name = $item->getName();
     $optNames = array();
     if ($item->getProductType() === Type::TYPE_SIMPLE) {
         $type = $item->getProduct()->getTypeInstance();
         $parentIds = $type->getParentIdsByChild($item->getProductId());
         // If the product has a configurable parent, we assume we should tag
         // the parent. If there are many parent IDs, we are safer to tag the
         // products own name alone.
         if (count($parentIds) === 1) {
             $attributes = $item->getBuyRequest()->getData('super_attribute');
             if (is_array($attributes)) {
                 foreach ($attributes as $id => $value) {
                     /** @var Attribute $attribute */
                     $attribute = $this->_objectManager->get('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->load($id);
                     $label = $attribute->getSource()->getOptionText($value);
                     if (!empty($label)) {
                         $optNames[] = $label;
                     }
                 }
             }
         }
     } elseif ($item->getProductType() === Configurable::TYPE_CODE) {
         $opts = $item->getProductOptionByCode('attributes_info');
         if (is_array($opts)) {
             foreach ($opts as $opt) {
                 if (isset($opt['value']) && is_string($opt['value'])) {
                     $optNames[] = $opt['value'];
                 }
             }
         }
     } elseif ($item->getProductType() === Type::TYPE_BUNDLE) {
         $opts = $item->getProductOptionByCode('bundle_options');
         if (is_array($opts)) {
             foreach ($opts as $opt) {
                 if (isset($opt['value']) && is_array($opt['value'])) {
                     foreach ($opt['value'] as $val) {
                         $qty = '';
                         if (isset($val['qty']) && is_int($val['qty'])) {
                             $qty .= $val['qty'] . ' x ';
                         }
                         if (isset($val['title']) && is_string($val['title'])) {
                             $optNames[] = $qty . $val['title'];
                         }
                     }
                 }
             }
         }
     } elseif ($item->getProductType() === Grouped::TYPE_CODE) {
         $config = $item->getProductOptionByCode('super_product_config');
         if (isset($config['product_id'])) {
             /** @var Product $parent */
             $parent = $this->_objectManager->get('Magento\\Catalog\\Model\\Product')->load($config['product_id']);
             $parentName = $parent->getName();
             if (!empty($parentName)) {
                 $name = $parentName . ' - ' . $name;
             }
         }
     }
     if (!empty($optNames)) {
         $name .= ' (' . implode(', ', $optNames) . ')';
     }
     return $name;
 }
Example #5
0
 /**
  * Get item name
  *
  * @param \Magento\Sales\Model\Order\Item $item
  *
  * @return string
  */
 public function getName(\Magento\Sales\Model\Order\Item $item)
 {
     return $item->getName();
 }