/**
  * Retrieves product options
  *
  * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
  * @return array
  */
 public function getOptions(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
 {
     $options = $this->productConfig->getOptions($item);
     $links = $this->getLinks($item);
     if ($links) {
         $linksOption = ['label' => $this->getLinksTitle($item->getProduct()), 'value' => []];
         foreach ($links as $link) {
             $linksOption['value'][] = $link->getTitle();
         }
         $options[] = $linksOption;
     }
     return $options;
 }
 public function testGetOptions()
 {
     $item = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\ItemInterface');
     $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getLinksTitle', 'getTypeInstance'])->getMock();
     $option = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface');
     $productType = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Product\\Type')->disableOriginalConstructor()->setMethods(['getLinks'])->getMock();
     $productLink = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Link')->disableOriginalConstructor()->setMethods(['getTitle'])->getMock();
     $this->productConfig->expects($this->once())->method('getOptions')->with($item);
     $item->expects($this->any())->method('getProduct')->willReturn($product);
     $item->expects($this->once())->method('getOptionByCode')->willReturn($option);
     $product->expects($this->once())->method('getTypeInstance')->willReturn($productType);
     $productType->expects($this->once())->method('getLinks')->with($product)->willReturn([1 => $productLink]);
     $option->expects($this->once())->method('getValue')->willReturn(1);
     $product->expects($this->once())->method('getLinksTitle')->willReturn('links_title');
     $productLink->expects($this->once())->method('getTitle')->willReturn('title');
     $this->assertEquals([['label' => 'links_title', 'value' => ['title']]], $this->helper->getOptions($item));
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getOptions(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getOptions');
     if (!$pluginInfo) {
         return parent::getOptions($item);
     } else {
         return $this->___callPlugins('getOptions', func_get_args(), $pluginInfo);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function isModuleOutputEnabled($moduleName = null)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'isModuleOutputEnabled');
     if (!$pluginInfo) {
         return parent::isModuleOutputEnabled($moduleName);
     } else {
         return $this->___callPlugins('isModuleOutputEnabled', func_get_args(), $pluginInfo);
     }
 }
 /**
  * Reads attributes from the item
  *
  * @param $reqdAttributeNames
  * @param $item
  * @return array
  */
 protected function populateCustomOptions($item)
 {
     $option_values = [];
     $options = $this->productConfiguration->getCustomOptions($item);
     $value = '';
     foreach ($options as $customOption) {
         $value .= $customOption['value'];
     }
     if ($value != '') {
         $option_values[] = ['name' => 'shipperhq_custom_options', 'value' => $value];
         return $option_values;
     }
     return false;
 }
 public function testGetOptions()
 {
     $optionIds = 'a:1:{i:0;i:1;}';
     $selectionIds = 'a:1:{i:0;s:1:"2";}';
     $selectionId = '2';
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getTypeInstance', '__wakeup', 'getCustomOption', 'getSelectionId', 'getName', 'getPriceModel'], [], '', false);
     $typeInstance = $this->getMock('Magento\\Bundle\\Model\\Product\\Type', ['getOptionsByIds', 'getSelectionsByIds'], [], '', false);
     $priceModel = $this->getMock('Magento\\Bundle\\Model\\Product\\Price', ['getSelectionFinalTotalPrice'], [], '', false);
     $selectionQty = $this->getMock('Magento\\Quote\\Model\\Quote\\Item\\Option', ['getValue', '__wakeup'], [], '', false);
     $bundleOption = $this->getMock('Magento\\Bundle\\Model\\Option', ['getSelections', 'getTitle', '__wakeup'], [], '', false);
     $selectionOption = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface', ['getValue']);
     $collection = $this->getMock('Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['appendSelections'], [], '', false);
     $itemOption = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface', ['getValue']);
     $collection2 = $this->getMock('Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', [], [], '', false);
     $this->escaper->expects($this->once())->method('escapeHtml')->with('name')->will($this->returnValue('name'));
     $this->pricingHelper->expects($this->once())->method('currency')->with(15)->will($this->returnValue('<span class="price">$15.00</span>'));
     $priceModel->expects($this->once())->method('getSelectionFinalTotalPrice')->will($this->returnValue(15));
     $selectionQty->expects($this->any())->method('getValue')->will($this->returnValue(1));
     $bundleOption->expects($this->any())->method('getSelections')->will($this->returnValue([$product]));
     $bundleOption->expects($this->once())->method('getTitle')->will($this->returnValue('title'));
     $selectionOption->expects($this->once())->method('getValue')->will($this->returnValue($selectionIds));
     $collection->expects($this->once())->method('appendSelections')->with($collection2, true)->will($this->returnValue([$bundleOption]));
     $itemOption->expects($this->once())->method('getValue')->will($this->returnValue($optionIds));
     $typeInstance->expects($this->once())->method('getOptionsByIds')->with(unserialize($optionIds), $product)->will($this->returnValue($collection));
     $typeInstance->expects($this->once())->method('getSelectionsByIds')->with(unserialize($selectionIds), $product)->will($this->returnValue($collection2));
     $product->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstance));
     $product->expects($this->any())->method('getCustomOption')->with('selection_qty_' . $selectionId)->will($this->returnValue($selectionQty));
     $product->expects($this->any())->method('getSelectionId')->will($this->returnValue($selectionId));
     $product->expects($this->once())->method('getName')->will($this->returnValue('name'));
     $product->expects($this->once())->method('getPriceModel')->will($this->returnValue($priceModel));
     $this->item->expects($this->any())->method('getProduct')->will($this->returnValue($product));
     $this->item->expects($this->at(1))->method('getOptionByCode')->with('bundle_option_ids')->will($this->returnValue($itemOption));
     $this->item->expects($this->at(2))->method('getOptionByCode')->with('bundle_selection_ids')->will($this->returnValue($selectionOption));
     $this->productConfiguration->expects($this->once())->method('getCustomOptions')->with($this->item)->will($this->returnValue([0 => ['label' => 'title', 'value' => 'value']]));
     $this->assertEquals([0 => ['label' => 'title', 'value' => [0 => '1 x name <span class="price">$15.00</span>']], 1 => ['label' => 'title', 'value' => 'value']], $this->helper->getOptions($this->item));
 }
 /**
  * Retrieves product options list
  *
  * @param ItemInterface $item
  * @return array
  */
 public function getOptions(ItemInterface $item)
 {
     return array_merge($this->getBundleOptions($item), $this->productConfiguration->getCustomOptions($item));
 }
Example #8
0
 /**
  * Returns formatted option value for an item
  *
  * @param \Magento\Wishlist\Model\Item\Option $option
  * @return array
  */
 protected function getFormattedOptionValue($option)
 {
     $params = ['max_length' => 55];
     return $this->_productConfig->getFormattedOptionValue($option, $params);
 }