/**
  * 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])));
 }
Exemplo n.º 2
0
 /**
  * Append selection to options
  * stripBefore - indicates to reload
  * appendAll - indicates do we need to filter by saleable and required custom options
  *
  * @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $selectionsCollection
  * @param bool $stripBefore
  * @param bool $appendAll
  * @return \Magento\Framework\DataObject[]
  */
 public function appendSelections($selectionsCollection, $stripBefore = false, $appendAll = true)
 {
     if ($stripBefore) {
         $this->_stripSelections();
     }
     if (!$this->_selectionsAppended) {
         foreach ($selectionsCollection->getItems() as $key => $selection) {
             $option = $this->getItemById($selection->getOptionId());
             if ($option) {
                 if ($appendAll || $selection->isSalable() && !$selection->getRequiredOptions()) {
                     $selection->setOption($option);
                     $option->addSelection($selection);
                 } else {
                     $selectionsCollection->removeItemByKey($key);
                 }
             }
         }
         $this->_selectionsAppended = true;
     }
     return $this->getItems();
 }
Exemplo n.º 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.'));
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Retrieve formatted bundle selections
  *
  * @param string $optionValues
  * @param SelectionCollection $selections
  * @return string
  */
 protected function getFormattedBundleSelections($optionValues, SelectionCollection $selections)
 {
     $bundleData = '';
     $selections->addAttributeToSort('position');
     foreach ($selections as $selection) {
         $selectionData = ['sku' => $selection->getSku(), 'price' => $selection->getSelectionPriceValue(), 'default' => $selection->getIsDefault(), 'default_qty' => $selection->getSelectionQty(), 'price_type' => $this->getPriceTypeValue($selection->getSelectionPriceType())];
         $bundleData .= $optionValues . ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . implode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, array_map(function ($value, $key) {
             return $key . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR . $value;
         }, $selectionData, array_keys($selectionData))) . ImportProductModel::PSEUDO_MULTI_LINE_SEPARATOR;
     }
     return $bundleData;
 }