public function testGetChildrenException() { $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $product->expects($this->any())->method('getTypeId')->will($this->returnValue('same')); $this->productRepository->expects($this->any())->method('get')->with('sd')->will($this->returnValue($product)); $this->assertCount(0, $this->object->getChildren('sd')); }
public function testCreateCreatesProductInEditMode() { $this->productMock->expects($this->once())->method('getIdBySku')->with('test_sku')->will($this->returnValue('test_id')); $this->productMock->expects($this->once())->method('setData')->with('_edit_mode', true); $this->productMock->expects($this->once())->method('load')->with('test_id'); $this->assertSame($this->productMock, $this->model->get('test_sku', true)); }
/** * {@inheritdoc} */ public function load($id, \Magento\Catalog\Service\V1\Data\ProductBuilder $productBuilder) { /** @var \Magento\Catalog\Model\Product */ $product = $this->productRepository->get($id); if ($product->getTypeId() != ProductType::TYPE_BUNDLE) { return; } $productBuilder->setCustomAttribute('bundle_product_options', $this->optionReadService->getList($product->getSku())); }
/** * @return array */ protected function prepareProducts($price) { $this->product = $this->productRepository->get('simple'); $productSecond = clone $this->product; $productSecond->setId(null)->setUrlKey(null)->setSku(uniqid($this->product->getSku() . '-'))->setName(uniqid($this->product->getName() . '-'))->setWebsiteIds([1]); $productSecond->save(); $productSecond->setPrice($price)->save(); $productThird = clone $this->product; $productThird->setId(null)->setUrlKey(null)->setSku(uniqid($this->product->getSku() . '-'))->setName(uniqid($this->product->getName() . '-'))->setWebsiteIds([1])->save(); $productThird->setPrice($price)->save(); return [$productSecond->getEntityId(), $productThird->getEntityId()]; }
public function testLoadBundleProduct() { $productId = 'test_id'; $productSku = 'test_sku'; $this->productRepository->expects($this->once())->method('get')->with($productId)->will($this->returnValue($this->product)); $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)); $this->product->expects($this->once())->method('getSku')->will($this->returnValue($productSku)); $optionCustomAttributeValue = ['a', 'b']; $this->optionReadService->expects($this->once())->method('getList')->with($productSku)->will($this->returnValue($optionCustomAttributeValue)); $this->productBuilder->expects($this->at(0))->method('setCustomAttribute')->with('bundle_product_options', $optionCustomAttributeValue); $this->model->load($productId, $this->productBuilder); }
/** * {@inheritdoc} */ public function getChildren($productId) { $product = $this->productRepository->get($productId); if ($product->getTypeId() != \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) { return []; } $childrenList = []; /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productTypeInstance */ $productTypeInstance = $product->getTypeInstance(); $productTypeInstance->setStoreFilter($product->getStoreId(), $product); foreach ($productTypeInstance->getUsedProducts($product) as $child) { $childrenList[] = $this->productConverter->createProductDataFromModel($child); } return $childrenList; }
/** * @inheritdoc */ public function getChildren($productId) { $product = $this->productRepository->get($productId); if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { throw new Exception('Only implemented for bundle product', Exception::HTTP_FORBIDDEN); } $childrenList = []; foreach ($this->getOptions($product) as $option) { /** @var \Magento\Catalog\Model\Product $selection */ foreach ($option->getSelections() as $selection) { $childrenList[] = $this->linkConverter->createDataFromModel($selection, $product); } } return $childrenList; }
/** * @expectedException \Magento\Webapi\Exception * @expectedExceptionCode 403 */ public function testGetChildrenException() { $productSku = 'productSku'; $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('simple')); $this->assertEquals([$this->link], $this->model->getChildren($productSku)); }
/** * @expectedException \Magento\Webapi\Exception * @expectedExceptionCode 403 * @expectedExceptionMessage Only implemented for configurable product: oneSku */ public function testGetListWebApiException() { $productSku = 'oneSku'; $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_SIMPLE)); $this->model->getList($productSku); }
/** * {@inheritdoc} */ public function update($productSku, $linkId, DownloadableLinkContent $linkContent, $isGlobalScopeContent = false) { $product = $this->productRepository->get($productSku, true); /** @var $link \Magento\Downloadable\Model\Link */ $link = $this->linkFactory->create()->load($linkId); if (!$link->getId()) { throw new NoSuchEntityException('There is no downloadable link with provided ID.'); } if ($link->getProductId() != $product->getId()) { throw new InputException('Provided downloadable link is not related to given product.'); } if (!$this->linkContentValidator->isValid($linkContent)) { throw new InputException('Provided link information is invalid.'); } if ($isGlobalScopeContent) { $product->setStoreId(0); } $title = $linkContent->getTitle(); if (empty($title)) { if ($isGlobalScopeContent) { throw new InputException('Link title cannot be empty.'); } // use title from GLOBAL scope $link->setTitle(null); } else { $link->setTitle($linkContent->getTitle()); } $link->setProductId($product->getId())->setStoreId($product->getStoreId())->setWebsiteId($product->getStore()->getWebsiteId())->setProductWebsiteIds($product->getWebsiteIds())->setSortOrder($linkContent->getSortOrder())->setPrice($linkContent->getPrice())->setIsShareable($linkContent->isShareable())->setNumberOfDownloads($linkContent->getNumberOfDownloads())->save(); return true; }
/** * @magentoDataFixture Magento/Bundle/_files/product.php * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php * @magentoAppIsolation enabled */ public function testUpdateBundleProduct() { // get existing bundle product $savedProduct = $this->productService->get('bundle-product'); /** @var Link $newLink */ $newLink = $this->linkBuilder->setSku('simple2')->create(); /** @var Link[] $links */ $links = array($newLink); /** @var Option $newOption */ $newOption = $this->optionBuilder->setProductLinks($links)->create(); /** @var Product bundleProduct */ $updatedBundleProduct = $this->productBuilder->populate($savedProduct)->setCustomAttribute('bundle_product_options', array($newOption))->setCustomAttribute('price_view', 'test')->setCustomAttribute('price', 10)->create(); $this->assertEquals('bundle-product', $this->productService->update('bundle-product', $updatedBundleProduct)); $this->productRepository->get('bundle-product')->unsetData('_cache_instance_options_collection'); // load and confirm number of links and options $savedProduct = $this->productService->get('bundle-product'); /** @var Option[] $updatedOptions */ $savedOptions = $savedProduct->getCustomAttribute('bundle_product_options')->getValue(); $this->assertTrue(is_array($savedOptions)); $this->assertEquals(1, count($savedOptions)); $option = $savedOptions[0]; $linkedProducts = $option->getProductLinks(); $this->assertTrue(is_array($linkedProducts)); $this->assertEquals(1, count($linkedProducts)); $link = $linkedProducts[0]; $this->assertEquals('simple2', $link->getSku()); }
/** * Test execute add success critical exception * * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteAddSuccessCriticalException() { $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false); $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false); $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false); $exception = new \Exception(); $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true); $helper->expects($this->exactly(2))->method('calculate')->willReturn(true); $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item); $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf(); $wishlist->expects($this->once())->method('save')->willReturn(null); $wishlist->expects($this->once())->method('getId')->willReturn(56); $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true); $product->expects($this->once())->method('getName')->willReturn('Test name'); $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2); $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3); $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product); $item->expects($this->once())->method('load')->with(3)->willReturnSelf(); $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12); $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist); $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item); $this->request->expects($this->once())->method('getParams')->willReturn([]); $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper); $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper); $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger); $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true); $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception); $this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->getController()->execute()); }
/** * @inheritdoc */ public function removeChild($productSku, $optionId, $childSku) { $product = $this->productRepository->get($productSku); if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { throw new Exception(sprintf('Product with specified sku: %s is not a bundle product', $productSku), Exception::HTTP_FORBIDDEN); } $excludeSelectionIds = array(); $usedProductIds = array(); $removeSelectionIds = array(); foreach ($this->getOptions($product) as $option) { foreach ($option->getSelections() as $selection) { if (strcasecmp($selection->getSku(), $childSku) == 0 && $selection->getOptionId() == $optionId) { $removeSelectionIds[] = $selection->getSelectionId(); continue; } $excludeSelectionIds[] = $selection->getSelectionId(); $usedProductIds[] = $selection->getProductId(); } } if (empty($removeSelectionIds)) { throw new NoSuchEntityException('Requested bundle option product doesn\'t exist'); } /* @var $resource \Magento\Bundle\Model\Resource\Bundle */ $resource = $this->bundleFactory->create(); $resource->dropAllUnneededSelections($product->getId(), $excludeSelectionIds); $resource->saveProductRelations($product->getId(), array_unique($usedProductIds)); return true; }
/** * {@inheritdoc} */ public function update($productSku, $sampleId, DownloadableSampleContent $sampleContent, $isGlobalScopeContent = false) { $product = $this->productRepository->get($productSku, true); /** @var $sample \Magento\Downloadable\Model\Sample */ $sample = $this->sampleFactory->create()->load($sampleId); if (!$sample->getId()) { throw new NoSuchEntityException('There is no downloadable sample with provided ID.'); } if ($sample->getProductId() != $product->getId()) { throw new InputException('Provided downloadable sample is not related to given product.'); } if (!$this->contentValidator->isValid($sampleContent)) { throw new InputException('Provided sample information is invalid.'); } if ($isGlobalScopeContent) { $product->setStoreId(0); } $title = $sampleContent->getTitle(); if (empty($title)) { if ($isGlobalScopeContent) { throw new InputException('Sample title cannot be empty.'); } // use title from GLOBAL scope $sample->setTitle(null); } else { $sample->setTitle($sampleContent->getTitle()); } $sample->setProductId($product->getId())->setStoreId($product->getStoreId())->setSortOrder($sampleContent->getSortOrder())->save(); return true; }
/** * @param string $productSku * @return \Magento\Catalog\Model\Product * @throws \Magento\Webapi\Exception */ private function getProduct($productSku) { $product = $this->productRepository->get($productSku); if (ConfigurableType::TYPE_CODE !== $product->getTypeId()) { throw new Exception('Product with specified sku: "%1" is not a configurable product', Exception::HTTP_FORBIDDEN, Exception::HTTP_FORBIDDEN, [$product->getSku()]); } return $product; }
/** * Retrieve product instance by sku * * @param string $productSku * @return \Magento\Catalog\Model\Product * @throws \Magento\Webapi\Exception */ private function getProduct($productSku) { $product = $this->productRepository->get($productSku); if (ConfigurableType::TYPE_CODE !== $product->getTypeId()) { throw new Exception(sprintf('Only implemented for configurable product: %s', $productSku), Exception::HTTP_FORBIDDEN); } return $product; }
/** * @param string $productSku * @return Product * @throws Exception */ private function getProduct($productSku) { $product = $this->productRepository->get($productSku); if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { throw new Exception('Product with specified sku: "%1" is not a bundle product', Exception::HTTP_FORBIDDEN, Exception::HTTP_FORBIDDEN, [$product->getSku()]); } return $product; }
/** * @param string $productSku * @return Product * @throws Exception */ private function getProduct($productSku) { $product = $this->productRepository->get($productSku); if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { throw new Exception('Only implemented for bundle product', Exception::HTTP_FORBIDDEN); } return $product; }
/** * @expectedException \Magento\Webapi\Exception */ public function testRemoveWebApiException() { $productSku = 'productSku'; $this->productRepositoryMock->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->productMock)); $this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(ProductType::TYPE_SIMPLE)); $this->productMock->expects($this->once())->method('getSku')->will($this->returnValue($productSku)); $this->writeService->remove($productSku, 3); }
/** * {@inheritdoc} */ public function get($productSku, $optionId) { $product = $this->productRepository->get($productSku); $option = $product->getOptionById($optionId); if ($option === null) { throw new NoSuchEntityException(); } return $this->_createOptionDataObject($option); }
/** * {@inheritdoc} */ public function deleteById($sku) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'deleteById'); if (!$pluginInfo) { return parent::deleteById($sku); } else { return $this->___callPlugins('deleteById', func_get_args(), $pluginInfo); } }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getList'); if (!$pluginInfo) { return parent::getList($searchCriteria); } else { return $this->___callPlugins('getList', func_get_args(), $pluginInfo); } }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteProductAddedToWishlistAfterObjectManagerThrowException() { $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['isVisibleInCatalog', 'getName'], [], '', false); $product->expects($this->once())->method('isVisibleInCatalog')->will($this->returnValue(true)); $product->expects($this->once())->method('getName')->will($this->returnValue('Product test name')); $this->productRepository->expects($this->once())->method('getById')->with(2)->will($this->returnValue($product)); $exception = new \Exception('Exception'); $wishListItem = new \stdClass(); $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['addNewItem', 'save', 'getId'], [], '', false); $wishlist->expects($this->once())->method('addNewItem')->will($this->returnValue($wishListItem)); $wishlist->expects($this->once())->method('getId')->will($this->returnValue(2)); $wishlist->expects($this->once())->method('save')->will($this->returnValue(true)); $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist)); $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParams'], [], '', false); $request->expects($this->once())->method('getParams')->will($this->returnValue(['product' => 2])); $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', ['calculate'], [], '', false); $wishlistHelper->expects($this->once())->method('calculate')->will($this->returnSelf()); $escaper = $this->getMock('Magento\\Framework\\Escaper', ['escapeHtml', 'escapeUrl'], [], '', false); $escaper->expects($this->once())->method('escapeHtml')->with('Product test name')->will($this->returnValue('Product test name')); $escaper->expects($this->once())->method('escapeUrl')->with('http://test-url.com')->will($this->returnValue('http://test-url.com')); $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', ['critical'], [], '', false); $logger->expects($this->once())->method('critical')->with($exception)->will($this->returnValue(true)); $om = $this->getMock('Magento\\Framework\\App\\ObjectManager', ['get'], [], '', false); $om->expects($this->at(0))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper)); $om->expects($this->at(1))->method('get')->with('Magento\\Framework\\Escaper')->will($this->returnValue($escaper)); $om->expects($this->at(2))->method('get')->with('Magento\\Framework\\Escaper')->will($this->returnValue($escaper)); $om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->will($this->returnValue($logger)); $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', null, [], '', false); $eventManager = $this->getMock('Magento\\Framework\\Event\\Manager', ['dispatch'], [], '', false); $eventManager->expects($this->once())->method('dispatch')->with('wishlist_add_product', ['wishlist' => $wishlist, 'product' => $product, 'item' => $wishListItem])->will($this->returnValue(true)); $url = $this->getMock('Magento\\Framework\\Url', null, [], '', false); $actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', null, [], '', false); $redirect = $this->getMock('\\Magento\\Store\\App\\Response\\Redirect', ['redirect'], [], '', false); $redirect->expects($this->once())->method('redirect')->with($response, '*', ['wishlist_id' => 2])->will($this->returnValue(null)); $view = $this->getMock('Magento\\Framework\\App\\View', null, [], '', false); $messageManager = $this->getMock('Magento\\Framework\\Message\\Manager', ['addError', 'addSuccess'], [], '', false); $messageManager->expects($this->once())->method('addError')->with('An error occurred while adding item to wish list.')->will($this->returnValue(null)); $messageManager->expects($this->once())->method('addSuccess')->will($this->throwException($exception)); $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($om)); $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($request)); $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($response)); $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager)); $this->context->expects($this->any())->method('getUrl')->will($this->returnValue($url)); $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlag)); $this->context->expects($this->any())->method('getRedirect')->will($this->returnValue($redirect)); $this->context->expects($this->any())->method('getView')->will($this->returnValue($view)); $this->context->expects($this->any())->method('getMessageManager')->will($this->returnValue($messageManager)); $this->customerSession->expects($this->exactly(1))->method('getBeforeWishlistRequest')->will($this->returnValue(false)); $this->customerSession->expects($this->never())->method('unsBeforeWishlistRequest')->will($this->returnValue(null)); $this->customerSession->expects($this->once())->method('getBeforeWishlistUrl')->will($this->returnValue('http://test-url.com')); $this->customerSession->expects($this->once())->method('setBeforeWishlistUrl')->with(null)->will($this->returnValue(null)); $this->createController(); $this->controller->execute(); }
/** * {@inheritdoc} */ public function getSamples($productSku) { $sampleList = []; /** @var \Magento\Catalog\Model\Product $product */ $product = $this->productRepository->get($productSku); $samples = $this->downloadableType->getSamples($product); /** @var \Magento\Downloadable\Model\Sample $sample */ foreach ($samples as $sample) { $sampleList[] = $this->buildSample($sample); } return $sampleList; }
/** * {@inheritdoc} */ public function removeChild($productSku, $childSku) { $product = $this->productRepository->get($productSku); if ($product->getTypeId() != \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) { throw new Exception(sprintf('Product with specified sku: %s is not a configurable product', $productSku), Exception::HTTP_FORBIDDEN); } $options = $product->getTypeInstance()->getUsedProducts($product); $ids = array(); foreach ($options as $option) { if ($option->getSku() == $childSku) { continue; } $ids[] = $option->getId(); } if (count($options) == count($ids)) { throw new NoSuchEntityException('Requested option doesn\'t exist'); } $product->addData(['associated_product_ids' => $ids]); $product->save(); return true; }
/** * @expectedException \Magento\Framework\Exception\StateException * @expectedExceptionMessage Product has been already attached */ public function testAddChildStateException() { $productSku = 'configurable-sku'; $childSku = 'simple-sku'; $configurable = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $configurable->expects($this->any())->method('getId')->will($this->returnValue(666)); $simplee = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $simplee->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->productRepository->expects($this->at(0))->method('get')->with($productSku)->will($this->returnValue($configurable)); $this->productRepository->expects($this->at(1))->method('get')->with($childSku)->will($this->returnValue($simplee)); $this->configurableType->expects($this->once())->method('getChildrenIds')->with(666)->will($this->returnValue([0 => [1, 2, 3]])); $this->assertTrue(true, $this->service->addChild($productSku, $childSku)); }
/** * {@inheritdoc} */ public function getList($productSku) { $product = $this->productRepository->get($productSku, true); $priceKey = 'website_price'; if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) == 0) { $priceKey = 'price'; } $prices = array(); foreach ($product->getData('group_price') as $price) { $this->groupPriceBuilder->populateWithArray(array(Product\GroupPrice::CUSTOMER_GROUP_ID => $price['all_groups'] ? 'all' : $price['cust_group'], Product\GroupPrice::VALUE => $price[$priceKey])); $prices[] = $this->groupPriceBuilder->create(); } return $prices; }
public function testGetList() { $searchCriteriaMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteriaInterface', [], [], '', false); $attributeCode = 'attribute_code'; $collectionMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Collection', [], [], '', false); $filterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false); $searchCriteriaBuilderMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteriaBuilder', [], [], '', false); $extendedSearchCriteriaMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $productAttributeSearchResultsMock = $this->getMockForAbstractClass('\\Magento\\Catalog\\Api\\Data\\ProductAttributeInterface', [], '', false, false, false, ['getItems']); $productAttributeMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeInterface', [], [], '', false); $filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false); $filterGroupFilterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false); $sortOrderMock = $this->getMock('\\Magento\\Framework\\Api\\SortOrder', [], [], '', false); $itemsMock = $this->getMock('\\Magento\\Framework\\Object', [], [], '', false); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock); $this->filterBuilderMock->expects($this->any())->method('setField')->with('attribute_set_id')->will($this->returnSelf()); $this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock); $this->filterBuilderMock->expects($this->once())->method('setValue')->with(4)->willReturn($this->filterBuilderMock); $this->searchCriteriaBuilderMock->expects($this->once())->method('addFilter')->with([$filterMock])->willReturn($searchCriteriaBuilderMock); $searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($extendedSearchCriteriaMock); $this->metadataServiceMock->expects($this->once())->method('getList')->with($extendedSearchCriteriaMock)->willReturn($productAttributeSearchResultsMock); $productAttributeSearchResultsMock->expects($this->once())->method('getItems')->willReturn([$productAttributeMock]); $productAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode); $collectionMock->expects($this->once())->method('addAttributeToSelect')->with($attributeCode); $collectionMock->expects($this->exactly(2))->method('joinAttribute')->withConsecutive(['status', 'catalog_product/status', 'entity_id', null, 'inner'], ['visibility', 'catalog_product/visibility', 'entity_id', null, 'inner']); $searchCriteriaMock->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroupMock]); $filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterGroupFilterMock]); $filterGroupFilterMock->expects($this->exactly(2))->method('getConditionType')->willReturn('eq'); $filterGroupFilterMock->expects($this->once())->method('getField')->willReturn('field'); $filterGroupFilterMock->expects($this->once())->method('getValue')->willReturn('value'); $collectionMock->expects($this->once())->method('addFieldToFilter')->with([['attribute' => 'field', 'eq' => 'value']]); $searchCriteriaMock->expects($this->once())->method('getSortOrders')->willReturn([$sortOrderMock]); $sortOrderMock->expects($this->once())->method('getField')->willReturn('field'); $sortOrderMock->expects($this->once())->method('getDirection')->willReturn(\Magento\Framework\Api\SearchCriteriaInterface::SORT_ASC); $collectionMock->expects($this->once())->method('addOrder')->with('field', 'ASC'); $searchCriteriaMock->expects($this->once())->method('getCurrentPage')->willReturn(4); $collectionMock->expects($this->once())->method('setCurPage')->with(4); $searchCriteriaMock->expects($this->once())->method('getPageSize')->willReturn(42); $collectionMock->expects($this->once())->method('setPageSize')->with(42); $collectionMock->expects($this->once())->method('load'); $collectionMock->expects($this->once())->method('getItems')->willReturn([$itemsMock]); $collectionMock->expects($this->once())->method('getSize')->willReturn(128); $searchResultsMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductSearchResultsInterface', [], [], '', false); $searchResultsMock->expects($this->once())->method('setSearchCriteria')->with($searchCriteriaMock); $searchResultsMock->expects($this->once())->method('setItems')->with([$itemsMock]); $this->searchResultsFactoryMock->expects($this->once())->method('create')->willReturn($searchResultsMock); $this->assertEquals($searchResultsMock, $this->model->getList($searchCriteriaMock)); }
/** * @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); }
/** * {@inheritdoc} */ public function getList($productSku, $customerGroupId) { $product = $this->productRepository->get($productSku, true); $priceKey = 'website_price'; if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) == 0) { $priceKey = 'price'; } $prices = array(); foreach ($product->getData('tier_price') as $price) { if (is_numeric($customerGroupId) && intval($price['cust_group']) === intval($customerGroupId) || $customerGroupId === 'all' && $price['all_groups']) { $this->priceBuilder->populateWithArray(array(Product\TierPrice::VALUE => $price[$priceKey], Product\TierPrice::QTY => $price['price_qty'])); $prices[] = $this->priceBuilder->create(); } } return $prices; }