/**
  * 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])));
 }
 /**
  * @param \Magento\Bundle\Model\Option $value
  * @return void
  * @throws Zend_Validate_Exception
  * @throws \Exception
  */
 protected function validateRequiredFields($value)
 {
     $messages = [];
     $requiredFields = ['title' => $value->getTitle(), 'type' => $value->getType()];
     foreach ($requiredFields as $requiredField => $requiredValue) {
         if (!$this->notEmpty->isValid(trim($requiredValue))) {
             $messages[$requiredField] = __(InputException::REQUIRED_FIELD, ['fieldName' => $requiredField]);
         }
     }
     $this->_addMessages($messages);
 }
Beispiel #3
0
 public function testGetSelectionByIdNegative()
 {
     $selectionId = 15;
     $this->selectionFirst->expects($this->any())->method('getSelectionId')->will($this->returnValue(16));
     $this->selectionSecond->expects($this->any())->method('getSelectionId')->will($this->returnValue(17));
     $this->model->setSelections([$this->selectionFirst, $this->selectionSecond]);
     $this->assertNull($this->model->getSelectionById($selectionId));
 }
Beispiel #4
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testGetNoSuchEntityException()
 {
     $productSku = 'oneSku';
     $optionId = 3;
     $this->productRepository->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->optionCollection->expects($this->once())->method('setIdFilter')->with($this->equalTo($optionId));
     $this->optionCollection->expects($this->once())->method('getFirstItem')->will($this->returnValue($this->optionModel));
     $this->productType->expects($this->once())->method('getOptionsCollection')->with($this->equalTo($this->product))->will($this->returnValue($this->optionCollection));
     $this->optionModel->expects($this->once())->method('getId');
     $this->model->get($productSku, $optionId);
 }
 public function testGetChildren()
 {
     $productSku = 'productSku';
     $this->getOptions();
     $this->productRepository->expects($this->any())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('bundle'));
     $this->productType->expects($this->once())->method('setStoreFilter')->with($this->equalTo($this->storeId), $this->product);
     $this->productType->expects($this->once())->method('getSelectionsCollection')->with($this->equalTo($this->optionIds), $this->equalTo($this->product))->will($this->returnValue($this->selectionCollection));
     $this->productType->expects($this->once())->method('getOptionsIds')->with($this->equalTo($this->product))->will($this->returnValue($this->optionIds));
     $this->optionCollection->expects($this->once())->method('appendSelections')->with($this->equalTo($this->selectionCollection))->will($this->returnValue([$this->option]));
     $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$this->product]));
     $this->linkConverter->expects($this->once())->method('createDataFromModel')->with($this->equalTo($this->product), $this->equalTo($this->product))->will($this->returnValue($this->link));
     $this->assertEquals([$this->link], $this->model->getChildren($productSku));
 }
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testRemoveChildInvalidChildSku()
 {
     $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product));
     $productSku = 'productSku';
     $optionId = 1;
     $childSku = 'childSku';
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->getRemoveOptions();
     $selection = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Selection')->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku . '_invalid'));
     $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId));
     $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55));
     $selection->expects($this->any())->method('getProductId')->will($this->returnValue(1));
     $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection]));
     $this->model->removeChild($productSku, $optionId, $childSku);
 }
Beispiel #7
0
 /**
  * Retrieve option value of bundle product
  *
  * @param \Magento\Bundle\Model\Option $option
  * @return string
  */
 protected function getFormattedOptionValues($option)
 {
     return 'name' . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR . $option->getTitle() . ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'type' . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR . $option->getType() . ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'required' . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR . $option->getRequired();
 }
Beispiel #8
0
 /**
  * @param Option $option
  * @param OptionModel $optionModel
  * @return OptionModel
  */
 public function getModelFromData(Option $option, OptionModel $optionModel)
 {
     $newOptionModel = $this->optionFactory->create();
     $newOptionModel->setData($optionModel->getData())->addData($option->__toArray())->setId($optionModel->getId())->setDefaultTitle(is_null($option->getTitle()) ? $optionModel->getTitle() : $option->getTitle());
     return $newOptionModel;
 }
Beispiel #9
0
 /**
  * Get html for option
  *
  * @param \Magento\Bundle\Model\Option $option
  * @return string
  */
 public function getOptionHtml($option)
 {
     $optionBlock = $this->getChildBlock($option->getType());
     if (!$optionBlock) {
         return __('There is no defined renderer for "%1" option type.', $option->getType());
     }
     return $optionBlock->setOption($option)->toHtml();
 }
Beispiel #10
0
 /**
  * Find minimal or maximal price for existing options
  *
  * @param \Magento\Bundle\Model\Option $option
  * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
  * @param bool $searchMin
  * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
  */
 public function processOptions($option, $selectionPriceList, $searchMin = true)
 {
     $result = [];
     foreach ($selectionPriceList as $current) {
         $currentValue = $current->getAmount()->getValue();
         if (empty($result)) {
             $result = [$current];
         } elseif ($searchMin && end($result)->getAmount()->getValue() > $currentValue) {
             $result = [$current];
         } elseif (!$searchMin && $option->isMultiSelection()) {
             $result[] = $current;
         } elseif (!$searchMin && !$option->isMultiSelection() && end($result)->getAmount()->getValue() < $currentValue) {
             $result = [$current];
         }
     }
     return $result;
 }
Beispiel #11
0
 /**
  * Find minimal or maximal price for existing options
  *
  * @param \Magento\Bundle\Model\Option $option
  * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
  * @param bool $searchMin
  * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function processOptions($option, $selectionPriceList, $searchMin = true)
 {
     $result = [];
     foreach ($selectionPriceList as $current) {
         $qty = $current->getQuantity();
         $currentValue = $current->getAmount()->getValue() * $qty;
         if (empty($result)) {
             $result = [$current];
         } else {
             $lastSelectionPrice = end($result);
             $lastValue = $lastSelectionPrice->getAmount()->getValue() * $lastSelectionPrice->getQuantity();
             if ($searchMin && $lastValue > $currentValue) {
                 $result = [$current];
             } elseif (!$searchMin && $option->isMultiSelection()) {
                 $result[] = $current;
             } elseif (!$searchMin && !$option->isMultiSelection() && $lastValue < $currentValue) {
                 $result = [$current];
             }
         }
     }
     return $result;
 }
Beispiel #12
0
 /**
  * Get formed data from selections of option
  *
  * @param Option $option
  * @param Product $product
  * @return array
  */
 private function getSelections(Option $option, Product $product)
 {
     $selections = [];
     $selectionCount = count($option->getSelections());
     foreach ($option->getSelections() as $selectionItem) {
         /* @var $selectionItem Product */
         $selectionId = $selectionItem->getSelectionId();
         $selections[$selectionId] = $this->getSelectionItemData($product, $selectionItem);
         if (($selectionItem->getIsDefault() || $selectionCount == 1 && $option->getRequired()) && $selectionItem->isSalable()) {
             $this->selectedOptions[$option->getId()][] = $selectionId;
         }
     }
     return $selections;
 }