/**
  * Set up
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->rowCustomizerMock = $this->objectManagerHelper->getObject('\\Magento\\BundleImportExport\\Model\\Export\\RowCustomizer');
     $this->productResourceCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addAttributeToFilter', 'getIterator'], [], '', false);
     $this->product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'getPriceType', 'getSkuType', 'getPriceView', 'getWeightType', 'getTypeInstance', 'getOptionsCollection', 'getSelectionsCollection'], [], '', false);
     $this->product->expects($this->any())->method('getId')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceType')->willReturn(1);
     $this->product->expects($this->any())->method('getSkuType')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceView')->willReturn(1);
     $this->product->expects($this->any())->method('getWeightType')->willReturn(1);
     $this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
     $this->optionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['setOrder', 'getIterator'], [], '', false);
     $this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
     $this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
     $this->option = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getId', 'getTitle', 'getType', 'getRequired'], [], '', false);
     $this->option->expects($this->any())->method('getId')->willReturn(1);
     $this->option->expects($this->any())->method('getTitle')->willReturn('title');
     $this->option->expects($this->any())->method('getType')->willReturn(1);
     $this->option->expects($this->any())->method('getRequired')->willReturn(1);
     $this->optionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->option])));
     $this->selection = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'], [], '', false);
     $this->selection->expects($this->any())->method('getSku')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
     $this->selectionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', ['getIterator', 'addAttributeToSort'], [], '', false);
     $this->selectionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->selection])));
     $this->selectionsCollection->expects($this->any())->method('addAttributeToSort')->willReturnSelf();
     $this->product->expects($this->any())->method('getSelectionsCollection')->willReturn($this->selectionsCollection);
     $this->productResourceCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
     $this->productResourceCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->product])));
 }
 public function getRemoveOptions()
 {
     $this->product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->productType));
     $this->product->expects($this->once())->method('getStoreId')->will($this->returnValue(1));
     $this->productType->expects($this->once())->method('setStoreFilter');
     $this->productType->expects($this->once())->method('getOptionsCollection')->with($this->equalTo($this->product))->will($this->returnValue($this->optionCollection));
     $this->productType->expects($this->once())->method('getOptionsIds')->with($this->equalTo($this->product))->will($this->returnValue([1, 2, 3]));
     $this->productType->expects($this->once())->method('getSelectionsCollection')->will($this->returnValue([]));
     $this->optionCollection->expects($this->any())->method('appendSelections')->with($this->equalTo([]))->will($this->returnValue([$this->option]));
 }
Пример #3
0
 /**
  * @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $selections
  * @param bool $skipSaleableCheck
  * @param \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection
  * @param int[] $options
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function checkSelectionsIsSale($selections, $skipSaleableCheck, $optionsCollection, $options)
 {
     foreach ($selections->getItems() as $selection) {
         if (!$selection->isSalable() && !$skipSaleableCheck) {
             $_option = $optionsCollection->getItemById($selection->getOptionId());
             $optionId = $_option->getId();
             if (is_array($options[$optionId]) && count($options[$optionId]) > 1) {
                 $moreSelections = true;
             } else {
                 $moreSelections = false;
             }
             $isMultiSelection = $_option->isMultiSelection();
             if ($_option->getRequired() && (!$isMultiSelection || !$moreSelections)) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('The required options you selected are not available.'));
             }
         }
     }
 }