public function getOptions() { $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])); }
/** * @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)); }
/** * @param \Magento\Bundle\Model\Resource\Selection\Collection $selections * @param bool $skipSaleableCheck * @param \Magento\Bundle\Model\Resource\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.')); } } } }