コード例 #1
0
 public function testGetOptionsByIds()
 {
     $optionsIds = [1, 2, 3];
     $usedOptionsIds = [4, 5, 6];
     $productId = 3;
     $storeId = 2;
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $usedOptionsMock = $this->getMockBuilder('Magento\\Bundle\\Model\\Resource\\Option\\Collection')->setMethods(['getResourceCollection'])->disableOriginalConstructor()->getMock();
     $dbResourceMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Collection\\AbstractCollection')->setMethods(['setProductIdFilter', 'setPositionOrder', 'joinValues', 'setIdFilter'])->disableOriginalConstructor()->getMock();
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $productMock->expects($this->at(0))->method('getData')->with('_cache_instance_used_options')->will($this->returnValue(null));
     $productMock->expects($this->at(1))->method('getData')->with('_cache_instance_used_options_ids')->will($this->returnValue($usedOptionsIds));
     $productMock->expects($this->once())->method('getId')->will($this->returnValue($productId));
     $this->bundleOptionFactory->expects($this->once())->method('create')->will($this->returnValue($usedOptionsMock));
     $usedOptionsMock->expects($this->once())->method('getResourceCollection')->will($this->returnValue($dbResourceMock));
     $dbResourceMock->expects($this->once())->method('setProductIdFilter')->with($productId)->will($this->returnSelf());
     $dbResourceMock->expects($this->once())->method('setPositionOrder')->will($this->returnSelf());
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
     $storeMock->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $dbResourceMock->expects($this->once())->method('joinValues')->will($this->returnSelf());
     $dbResourceMock->expects($this->once())->method('setIdFilter')->with($optionsIds)->will($this->returnSelf());
     $productMock->expects($this->at(3))->method('setData')->with('_cache_instance_used_options', $dbResourceMock)->will($this->returnSelf());
     $productMock->expects($this->at(4))->method('setData')->with('_cache_instance_used_options_ids', $optionsIds)->will($this->returnSelf());
     $this->model->getOptionsByIds($optionsIds, $productMock);
 }
コード例 #2
0
ファイル: TypeTest.php プロジェクト: kid17/magento2
 public function testSave()
 {
     $options = ['some_option' => ['option_id' => '', 'delete' => false]];
     $selections = ['some_option' => [123 => ['selection_id' => '', 'delete' => false]]];
     $resource = $this->getMockBuilder('Magento\\Bundle\\Model\\Resource\\Bundle')->disableOriginalConstructor()->getMock();
     $this->bundleFactory->expects($this->once())->method('create')->willReturn($resource);
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getStoreId', 'getOrigData', 'getData', 'getBundleOptionsData', 'getBundleSelectionsData'])->disableOriginalConstructor()->getMock();
     $product->expects($this->once())->method('getBundleOptionsData')->willReturn($options);
     $product->expects($this->once())->method('getBundleSelectionsData')->willReturn($selections);
     $option = $this->getMockBuilder('Magento\\Bundle\\Model\\Resource\\Option\\Collection')->setMethods(['setData', 'setParentId', 'setStoreId', 'isDeleted', 'save', 'getOptionId'])->disableOriginalConstructor()->getMock();
     $option->expects($this->once())->method('setData')->willReturnSelf();
     $option->expects($this->once())->method('setParentId')->willReturnSelf();
     $option->expects($this->once())->method('setStoreId')->willReturnSelf();
     $this->bundleOptionFactory->expects($this->once())->method('create')->will($this->returnValue($option));
     $selection = $this->getMockBuilder('Magento\\Bundle\\Model\\Selection')->setMethods(['setData', 'setOptionId', 'setParentProductId', 'setWebsiteId', 'save'])->disableOriginalConstructor()->getMock();
     $selection->expects($this->once())->method('setData')->willReturnSelf();
     $selection->expects($this->once())->method('setOptionId')->willReturnSelf();
     $selection->expects($this->once())->method('setParentProductId')->willReturnSelf();
     $selection->expects($this->once())->method('setWebsiteId')->willReturnSelf();
     $selection->expects($this->once())->method('setParentProductId')->willReturnSelf();
     $this->bundleModelSelection->expects($this->once())->method('create')->willReturn($selection);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getWebsiteId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue(10));
     $this->model->save($product);
 }
コード例 #3
0
 public function testGetSearchableData()
 {
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getHasOptions', 'getId', 'getStoreId'])->getMock();
     $option = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Option')->disableOriginalConstructor()->setMethods(['getSearchableData'])->getMock();
     $product->expects($this->once())->method('getHasOptions')->willReturn(false);
     $product->expects($this->once())->method('getId')->willReturn('productId');
     $product->expects($this->once())->method('getStoreId')->willReturn('storeId');
     $this->bundleOptionFactory->expects($this->once())->method('create')->willReturn($option);
     $option->expects($this->once())->method('getSearchableData')->willReturn(['optionSearchdata']);
     $this->assertEquals(['optionSearchdata'], $this->model->getSearchableData($product));
 }
コード例 #4
0
ファイル: Type.php プロジェクト: rafaelstz/magento2
 /**
  * Retrieve additional searchable data from type instance
  * Using based on product id and store_id data
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return array
  */
 public function getSearchableData($product)
 {
     $searchData = parent::getSearchableData($product);
     $optionSearchData = $this->_bundleOption->create()->getSearchableData($product->getId(), $product->getStoreId());
     if ($optionSearchData) {
         $searchData = array_merge($searchData, $optionSearchData);
     }
     return $searchData;
 }
コード例 #5
0
ファイル: OptionConverter.php プロジェクト: aiesh/magento2
 /**
  * @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;
 }