コード例 #1
0
ファイル: Plugin.php プロジェクト: pradeep-wagento/magento2
 /**
  * Retrieve configuration options for configurable product
  *
  * @param \Magento\Catalog\Helper\Product\Configuration $subject
  * @param callable $proceed
  * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
  *
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetOptions(\Magento\Catalog\Helper\Product\Configuration $subject, \Closure $proceed, \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
 {
     $product = $item->getProduct();
     $typeId = $product->getTypeId();
     if ($typeId == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
         $attributes = $product->getTypeInstance()->getSelectedAttributesInfo($product);
         return array_merge($attributes, $proceed($item));
     }
     return $proceed($item);
 }
コード例 #2
0
 /**
  * Retrieves item links options
  *
  * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
  * @return array
  */
 public function getLinks(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
 {
     $product = $item->getProduct();
     $itemLinks = [];
     $linkIds = $item->getOptionByCode('downloadable_link_ids');
     if ($linkIds) {
         $productLinks = $product->getTypeInstance()->getLinks($product);
         foreach (explode(',', $linkIds->getValue()) as $linkId) {
             if (isset($productLinks[$linkId])) {
                 $itemLinks[] = $productLinks[$linkId];
             }
         }
     }
     return $itemLinks;
 }
コード例 #3
0
 /**
  * Get value of configured options
  *
  * @return array
  */
 protected function getOptionsValue()
 {
     $product = $this->item->getProduct();
     $value = 0.0;
     $basePrice = parent::getValue();
     $optionIds = $this->item->getOptionByCode('option_ids');
     if ($optionIds) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $option = $product->getOptionById($optionId);
             if ($option) {
                 $itemOption = $this->item->getOptionByCode('option_' . $option->getId());
                 /** @var $group \Magento\Catalog\Model\Product\Option\Type\DefaultType */
                 $group = $option->groupFactory($option->getType())->setOption($option)->setConfigurationItem($this->item)->setConfigurationItemOption($itemOption);
                 $value += $group->getOptionPrice($itemOption->getValue(), $basePrice);
             }
         }
     }
     return $value;
 }
コード例 #4
0
 /**
  * Get Options with attached Selections collection
  *
  * @return array|\Magento\Bundle\Model\ResourceModel\Option\Collection
  */
 public function getOptions()
 {
     $bundleProduct = $this->product;
     $bundleOptions = [];
     /** @var \Magento\Bundle\Model\Product\Type $typeInstance */
     $typeInstance = $bundleProduct->getTypeInstance();
     // get bundle options
     $optionsQuoteItemOption = $this->item->getOptionByCode('bundle_option_ids');
     $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : [];
     if ($bundleOptionsIds) {
         /** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */
         $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $bundleProduct);
         // get and add bundle selections collection
         $selectionsQuoteItemOption = $this->item->getOptionByCode('bundle_selection_ids');
         $bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());
         if ($bundleSelectionIds) {
             $selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $bundleProduct);
             $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
         }
     }
     return $bundleOptions;
 }
コード例 #5
0
 /**
  * Retrieves product configuration options
  *
  * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
  * @return array
  */
 public function getCustomOptions(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
 {
     $product = $item->getProduct();
     $options = [];
     $optionIds = $item->getOptionByCode('option_ids');
     if ($optionIds) {
         $options = [];
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $option = $product->getOptionById($optionId);
             if ($option) {
                 $itemOption = $item->getOptionByCode('option_' . $option->getId());
                 /** @var $group \Magento\Catalog\Model\Product\Option\Type\DefaultType */
                 $group = $option->groupFactory($option->getType())->setOption($option)->setConfigurationItem($item)->setConfigurationItemOption($itemOption);
                 if ('file' == $option->getType()) {
                     $downloadParams = $item->getFileDownloadParams();
                     if ($downloadParams) {
                         $url = $downloadParams->getUrl();
                         if ($url) {
                             $group->setCustomOptionDownloadUrl($url);
                         }
                         $urlParams = $downloadParams->getUrlParams();
                         if ($urlParams) {
                             $group->setCustomOptionUrlParams($urlParams);
                         }
                     }
                 }
                 $options[] = ['label' => $option->getTitle(), 'value' => $group->getFormattedOptionValue($itemOption->getValue()), 'print_value' => $group->getPrintableOptionValue($itemOption->getValue()), 'option_id' => $option->getId(), 'option_type' => $option->getType(), 'custom_view' => $group->isCustomizedView()];
             }
         }
     }
     $addOptions = $item->getOptionByCode('additional_options');
     if ($addOptions) {
         $options = array_merge($options, unserialize($addOptions->getValue()));
     }
     return $options;
 }
コード例 #6
0
 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));
 }
コード例 #7
0
 /**
  * Get bundled selections (slections-products collection)
  *
  * Returns array of options objects.
  * Each option object will contain array of selections objects
  *
  * @param ItemInterface $item
  * @return array
  */
 public function getBundleOptions(ItemInterface $item)
 {
     $options = [];
     $product = $item->getProduct();
     /** @var \Magento\Bundle\Model\Product\Type $typeInstance */
     $typeInstance = $product->getTypeInstance();
     // get bundle options
     $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
     $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : [];
     if ($bundleOptionsIds) {
         /** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */
         $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);
         // get and add bundle selections collection
         $selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');
         $bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());
         if (!empty($bundleSelectionIds)) {
             $selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $product);
             $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
             foreach ($bundleOptions as $bundleOption) {
                 if ($bundleOption->getSelections()) {
                     $option = ['label' => $bundleOption->getTitle(), 'value' => []];
                     $bundleSelections = $bundleOption->getSelections();
                     foreach ($bundleSelections as $bundleSelection) {
                         $qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
                         if ($qty) {
                             $option['value'][] = $qty . ' x ' . $this->escaper->escapeHtml($bundleSelection->getName()) . ' ' . $this->pricingHelper->currency($this->getSelectionFinalPrice($item, $bundleSelection));
                         }
                     }
                     if ($option['value']) {
                         $options[] = $option;
                     }
                 }
             }
         }
     }
     return $options;
 }
コード例 #8
-1
ファイル: Grouped.php プロジェクト: aiesh/magento2
 /**
  * Retrieves grouped product options list
  *
  * @param \Magento\Catalog\Helper\Product\Configuration $subject
  * @param callable $proceed
  * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
  *
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetOptions(\Magento\Catalog\Helper\Product\Configuration $subject, \Closure $proceed, \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
 {
     $product = $item->getProduct();
     $typeId = $product->getTypeId();
     if ($typeId == \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE) {
         $options = array();
         /** @var \Magento\GroupedProduct\Model\Product\Type\Grouped $typeInstance */
         $typeInstance = $product->getTypeInstance();
         $associatedProducts = $typeInstance->getAssociatedProducts($product);
         if ($associatedProducts) {
             foreach ($associatedProducts as $associatedProduct) {
                 $qty = $item->getOptionByCode('associated_product_' . $associatedProduct->getId());
                 $option = array('label' => $associatedProduct->getName(), 'value' => $qty && $qty->getValue() ? $qty->getValue() : 0);
                 $options[] = $option;
             }
         }
         $options = array_merge($options, $proceed($item));
         $isUnConfigured = true;
         foreach ($options as &$option) {
             if ($option['value']) {
                 $isUnConfigured = false;
                 break;
             }
         }
         return $isUnConfigured ? array() : $options;
     }
     return $proceed($item);
 }