Exemplo n.º 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetSelectionsByIds()
 {
     $selectionIds = [1, 2, 3];
     $usedSelectionsIds = [4, 5, 6];
     $storeId = 2;
     $websiteId = 1;
     $storeFilter = 'store_filter';
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $usedSelectionsMock = $this->getMockBuilder('Magento\\Bundle\\Model\\Resource\\Selection\\Collection')->setMethods(['addAttributeToSelect', 'setFlag', 'addStoreFilter', 'setStoreId', 'setPositionOrder', 'addFilterByRequiredOptions', 'setSelectionIdsFilter', 'joinPrices'])->disableOriginalConstructor()->getMock();
     $productGetMap = [['_cache_instance_used_selections', null, null], ['_cache_instance_used_selections_ids', null, $usedSelectionsIds], ['_cache_instance_store_filter', null, $storeFilter]];
     $productMock->expects($this->any())->method('getData')->will($this->returnValueMap($productGetMap));
     $productSetMap = [['_cache_instance_used_selections', $usedSelectionsMock, $productMock], ['_cache_instance_used_selections_ids', $selectionIds, $productMock]];
     $productMock->expects($this->any())->method('setData')->will($this->returnValueMap($productSetMap));
     $productMock->expects($this->once())->method('getStoreId')->will($this->returnValue($storeId));
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getWebsiteId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($storeMock));
     $storeMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $this->bundleCollection->expects($this->once())->method('create')->will($this->returnValue($usedSelectionsMock));
     $usedSelectionsMock->expects($this->once())->method('addAttributeToSelect')->with('*')->will($this->returnSelf());
     $flagMap = [['require_stock_items', true, $usedSelectionsMock], ['product_children', true, $usedSelectionsMock]];
     $usedSelectionsMock->expects($this->any())->method('setFlag')->will($this->returnValueMap($flagMap));
     $usedSelectionsMock->expects($this->once())->method('addStoreFilter')->with($storeFilter)->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('setPositionOrder')->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('addFilterByRequiredOptions')->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('setSelectionIdsFilter')->with($selectionIds)->will($this->returnSelf());
     $usedSelectionsMock->expects($this->once())->method('joinPrices')->with($websiteId)->will($this->returnSelf());
     $this->catalogData->expects($this->once())->method('isPriceGlobal')->will($this->returnValue(false));
     $this->model->getSelectionsByIds($selectionIds, $productMock);
 }
Exemplo n.º 2
0
 public function testGetSelectionsCollection()
 {
     $optionIds = [1, 2, 3];
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getStoreId', 'getData', 'hasData', 'setData', 'getId'])->getMock();
     $selectionCollection = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Resource\\Selection\\Collection')->disableOriginalConstructor()->setMethods(['addAttributeToSelect', 'setFlag', 'setPositionOrder', 'addStoreFilter', 'setStoreId', 'addFilterByRequiredOptions', 'setOptionIdsFilter', 'joinPrices'])->getMock();
     $store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getWebsiteId'])->getMock();
     $product->expects($this->once())->method('hasData')->with('_cache_instance_selections_collection1_2_3')->willReturn(false);
     $product->expects($this->once())->method('getStoreId')->willReturn('store_id');
     $product->expects($this->at(2))->method('getData')->with('_cache_instance_store_filter')->willReturn($selectionCollection);
     $this->bundleCollection->expects($this->once())->method('create')->willReturn($selectionCollection);
     $selectionCollection->expects($this->any())->method('addAttributeToSelect')->willReturnSelf();
     $selectionCollection->expects($this->any())->method('setFlag')->willReturnSelf();
     $selectionCollection->expects($this->any())->method('setPositionOrder')->willReturnSelf();
     $selectionCollection->expects($this->any())->method('addStoreFilter')->willReturnSelf();
     $selectionCollection->expects($this->any())->method('setStoreId')->willReturnSelf();
     $selectionCollection->expects($this->any())->method('addFilterByRequiredOptions')->willReturnSelf();
     $selectionCollection->expects($this->any())->method('setOptionIdsFilter')->willReturnSelf();
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $store->expects($this->once())->method('getWebsiteId')->willReturn('website_id');
     $selectionCollection->expects($this->any())->method('joinPrices')->with('website_id')->willReturnSelf();
     $product->expects($this->once())->method('setData')->with('_cache_instance_selections_collection1_2_3', $selectionCollection)->willReturnSelf();
     $product->expects($this->at(4))->method('getData')->with('_cache_instance_selections_collection1_2_3')->willReturn($selectionCollection);
     $this->assertEquals($selectionCollection, $this->model->getSelectionsCollection($optionIds, $product));
 }
Exemplo n.º 3
0
 /**
  * Retrieve bundle selections collection based on ids
  *
  * @param array $selectionIds
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Bundle\Model\Resource\Selection\Collection
  */
 public function getSelectionsByIds($selectionIds, $product)
 {
     sort($selectionIds);
     $usedSelections = $product->getData($this->_keyUsedSelections);
     $usedSelectionsIds = $product->getData($this->_keyUsedSelectionsIds);
     if (!$usedSelections || serialize($usedSelectionsIds) != serialize($selectionIds)) {
         $storeId = $product->getStoreId();
         $usedSelections = $this->_bundleCollection->create()->addAttributeToSelect('*')->setFlag('require_stock_items', true)->setFlag('product_children', true)->addStoreFilter($this->getStoreFilter($product))->setStoreId($storeId)->setPositionOrder()->addFilterByRequiredOptions()->setSelectionIdsFilter($selectionIds);
         if (!$this->_catalogData->isPriceGlobal() && $storeId) {
             $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
             $usedSelections->joinPrices($websiteId);
         }
         $product->setData($this->_keyUsedSelections, $usedSelections);
         $product->setData($this->_keyUsedSelectionsIds, $selectionIds);
     }
     return $usedSelections;
 }