From 16ffff6b4679ead2dbd70e4c6ba4fb279f40709a Mon Sep 17 00:00:00 2001 From: glo82145 Date: Tue, 15 Mar 2022 12:12:52 +0530 Subject: [PATCH 01/22] AC-1955 Attribute is returned as aggregation in products query even if Use in Search Results Layered Navigation is set to no --- .../Product/SearchCriteriaBuilder.php | 31 +++- .../Product/SearchCriteriaBuilderTest.php | 152 ++++++++++++++++++ 2 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 app/code/Magento/CatalogGraphQl/Test/Unit/DataProvider/Product/SearchCriteriaBuilderTest.php diff --git a/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php b/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php index 52443172db27c..5368dceb79bbf 100644 --- a/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php +++ b/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php @@ -8,18 +8,23 @@ namespace Magento\CatalogGraphQl\DataProvider\Product; use Magento\Catalog\Api\Data\EavAttributeInterface; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Visibility; +use Magento\Eav\Model\Config; use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\Search\FilterGroupBuilder; use Magento\Framework\Api\Search\SearchCriteriaInterface; use Magento\Framework\Api\SortOrder; +use Magento\Framework\Api\SortOrderBuilder; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder; -use Magento\Catalog\Model\Product\Visibility; -use Magento\Framework\Api\SortOrderBuilder; /** * Build search criteria + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ + class SearchCriteriaBuilder { /** @@ -51,6 +56,11 @@ class SearchCriteriaBuilder */ private $sortOrderBuilder; + /** + * @var Config + */ + private Config $eavConfig; + /** * @param Builder $builder * @param ScopeConfigInterface $scopeConfig @@ -58,6 +68,7 @@ class SearchCriteriaBuilder * @param FilterGroupBuilder $filterGroupBuilder * @param Visibility $visibility * @param SortOrderBuilder $sortOrderBuilder + * @param Config $eavConfig */ public function __construct( Builder $builder, @@ -65,14 +76,16 @@ public function __construct( FilterBuilder $filterBuilder, FilterGroupBuilder $filterGroupBuilder, Visibility $visibility, - SortOrderBuilder $sortOrderBuilder + SortOrderBuilder $sortOrderBuilder = null, + Config $eavConfig = null ) { $this->scopeConfig = $scopeConfig; $this->filterBuilder = $filterBuilder; $this->filterGroupBuilder = $filterGroupBuilder; $this->builder = $builder; $this->visibility = $visibility; - $this->sortOrderBuilder = $sortOrderBuilder; + $this->sortOrderBuilder = $sortOrderBuilder ?? ObjectManager::getInstance()->get(SortOrderBuilder::class); + $this->eavConfig = $eavConfig ?? ObjectManager::getInstance()->get(Config::class); } /** @@ -87,9 +100,13 @@ public function build(array $args, bool $includeAggregation): SearchCriteriaInte $searchCriteria = $this->builder->build('products', $args); $isSearch = !empty($args['search']); $this->updateRangeFilters($searchCriteria); - if ($includeAggregation) { - $this->preparePriceAggregation($searchCriteria); + $attributeData = $this->eavConfig->getAttribute(Product::ENTITY, 'price'); + $priceOptions = $attributeData->getData(); + + if ($priceOptions['is_filterable'] != 0) { + $this->preparePriceAggregation($searchCriteria); + } $requestName = 'graphql_product_search_with_aggregation'; } else { $requestName = 'graphql_product_search'; @@ -178,7 +195,7 @@ private function preparePriceAggregation(SearchCriteriaInterface $searchCriteria private function addFilter( SearchCriteriaInterface $searchCriteria, string $field, - $value, + $value, ?string $condition = null ): void { $filter = $this->filterBuilder diff --git a/app/code/Magento/CatalogGraphQl/Test/Unit/DataProvider/Product/SearchCriteriaBuilderTest.php b/app/code/Magento/CatalogGraphQl/Test/Unit/DataProvider/Product/SearchCriteriaBuilderTest.php new file mode 100644 index 0000000000000..59970335d3d10 --- /dev/null +++ b/app/code/Magento/CatalogGraphQl/Test/Unit/DataProvider/Product/SearchCriteriaBuilderTest.php @@ -0,0 +1,152 @@ +builder = $this->createMock(Builder::class); + $this->scopeConfig = $this->createMock(ScopeConfigInterface::class); + $this->filterBuilder = $this->createMock(FilterBuilder::class); + $this->filterGroupBuilder = $this->createMock(FilterGroupBuilder::class); + $this->sortOrderBuilder = $this->createMock(SortOrderBuilder::class); + $this->visibility = $this->createMock(Visibility::class); + $this->eavConfig = $this->createMock(Config::class); + $this->model = new SearchCriteriaBuilder( + $this->builder, + $this->scopeConfig, + $this->filterBuilder, + $this->filterGroupBuilder, + $this->visibility, + $this->sortOrderBuilder, + $this->eavConfig + ); + } + + public function testBuild(): void + { + $args = ['search' => '', 'pageSize' => 20, 'currentPage' => 1]; + + $filter = $this->createMock(Filter::class); + + $searchCriteria = $this->getMockBuilder(SearchCriteriaInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $attributeInterface = $this->getMockBuilder(Attribute::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $attributeInterface->setData(['is_filterable' => 0]); + + $this->builder->expects($this->any()) + ->method('build') + ->with('products', $args) + ->willReturn($searchCriteria); + $searchCriteria->expects($this->any())->method('getFilterGroups')->willReturn([]); + $this->eavConfig->expects($this->any()) + ->method('getAttribute') + ->with(Product::ENTITY, 'price') + ->willReturn($attributeInterface); + + $this->sortOrderBuilder->expects($this->once()) + ->method('setField') + ->with('_id') + ->willReturnSelf(); + $this->sortOrderBuilder->expects($this->once()) + ->method('setDirection') + ->with('DESC') + ->willReturnSelf(); + $this->sortOrderBuilder->expects($this->any()) + ->method('create') + ->willReturn([]); + + $this->filterBuilder->expects($this->once()) + ->method('setField') + ->with('visibility') + ->willReturnSelf(); + $this->filterBuilder->expects($this->once()) + ->method('setValue') + ->with("") + ->willReturnSelf(); + $this->filterBuilder->expects($this->once()) + ->method('setConditionType') + ->with('in') + ->willReturnSelf(); + + $this->filterBuilder->expects($this->once())->method('create')->willReturn($filter); + + $this->filterGroupBuilder->expects($this->any()) + ->method('addFilter') + ->with($filter) + ->willReturnSelf(); + + $this->model->build($args, true); + } +} From 54ee6a31bcb263d1069e1b84bc67e8dc597dfce2 Mon Sep 17 00:00:00 2001 From: glo82145 Date: Tue, 15 Mar 2022 13:43:44 +0530 Subject: [PATCH 02/22] fixing --- .../DataProvider/Product/SearchCriteriaBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php b/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php index 5368dceb79bbf..8b9930076f298 100644 --- a/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php +++ b/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php @@ -195,7 +195,7 @@ private function preparePriceAggregation(SearchCriteriaInterface $searchCriteria private function addFilter( SearchCriteriaInterface $searchCriteria, string $field, - $value, + $value, ?string $condition = null ): void { $filter = $this->filterBuilder From e8acb0869139de3889646d5d3113b5c744a965cc Mon Sep 17 00:00:00 2001 From: Aparna Sreekumar Date: Wed, 16 Mar 2022 17:13:33 +0530 Subject: [PATCH 03/22] WIP: BUG#AC-2641 --- app/code/Magento/Catalog/Model/ResourceModel/Product.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product.php b/app/code/Magento/Catalog/Model/ResourceModel/Product.php index b72bd8c441588..c950b49348dc3 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product.php @@ -656,11 +656,7 @@ public function getProductsIdsBySkus(array $productSkuList) */ private function getResultKey(string $sku, array $productSkuList): string { - $key = array_search(strtolower($sku), array_map('strtolower', $productSkuList)); - if ($key !== false) { - $sku = $productSkuList[$key]; - } - return $sku; + return in_array(strtolower($sku), array_map('strtolower', $productSkuList)) ? $sku : ''; } /** From e5624735c140b8a89559e9e33ba6b0af34febde3 Mon Sep 17 00:00:00 2001 From: Rajesh Kumar Date: Thu, 17 Mar 2022 18:41:21 +0530 Subject: [PATCH 04/22] AC-2630 :: Getting error while adding product type Gift Card through Order By SKU in Customer Account --- .../frontend/templates/cart/item/configure/updatecart.phtml | 6 +----- app/code/Magento/SalesRule/etc/extension_attributes.xml | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml index 3b09512eb505b..7dccfbdd1859f 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml @@ -40,11 +40,7 @@ diff --git a/app/code/Magento/SalesRule/etc/extension_attributes.xml b/app/code/Magento/SalesRule/etc/extension_attributes.xml index c69c309d8741b..8cdf0fd7cd39c 100644 --- a/app/code/Magento/SalesRule/etc/extension_attributes.xml +++ b/app/code/Magento/SalesRule/etc/extension_attributes.xml @@ -12,4 +12,7 @@ - \ No newline at end of file + + + + From 7f47c10f6a81e18d35e30096a9225791e66f36a2 Mon Sep 17 00:00:00 2001 From: Rajesh Kumar Date: Thu, 17 Mar 2022 22:44:55 +0530 Subject: [PATCH 05/22] Fixed static tests --- .../frontend/templates/cart/item/configure/updatecart.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml index 7dccfbdd1859f..5b0bad49ba425 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml @@ -8,10 +8,10 @@ ?> getProduct(); ?> -isSaleable()) :?> +isSaleable()):?>
- shouldRenderQuantity()) :?> + shouldRenderQuantity()):?>
From e7ba7af64a3e4efe0c66d759a271486c92dbba42 Mon Sep 17 00:00:00 2001 From: Faizan Shaikh Date: Tue, 22 Mar 2022 09:58:42 +0530 Subject: [PATCH 06/22] [BUG#AC-2445] - Error: Call to a member function getCustomerName() on null - Issue fixed --- app/code/Magento/Wishlist/Block/Rss/Link.php | 2 +- ...omerWishlistWithRssFeedLinkActionGroup.xml | 23 +++++++ .../Wishlist/Test/Mftf/Data/WishlistData.xml | 16 +++++ ...StorefrontCustomerWishlistShareSection.xml | 1 + ...efrontShareWishlistWithRssFeedLinkTest.xml | 67 +++++++++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontShareCustomerWishlistWithRssFeedLinkActionGroup.xml create mode 100644 app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithRssFeedLinkTest.xml diff --git a/app/code/Magento/Wishlist/Block/Rss/Link.php b/app/code/Magento/Wishlist/Block/Rss/Link.php index 28affa8d3372d..179950efef884 100644 --- a/app/code/Magento/Wishlist/Block/Rss/Link.php +++ b/app/code/Magento/Wishlist/Block/Rss/Link.php @@ -44,7 +44,7 @@ public function __construct( \Magento\Framework\Url\EncoderInterface $urlEncoder, array $data = [] ) { - $data['wishlistHelper'] = $this->wishlistHelper; + $data['wishlistHelper'] = $wishlistHelper; parent::__construct($context, $data); $this->wishlistHelper = $wishlistHelper; $this->rssUrlBuilder = $rssUrlBuilder; diff --git a/app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontShareCustomerWishlistWithRssFeedLinkActionGroup.xml b/app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontShareCustomerWishlistWithRssFeedLinkActionGroup.xml new file mode 100644 index 0000000000000..6664242951e3d --- /dev/null +++ b/app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontShareCustomerWishlistWithRssFeedLinkActionGroup.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Wishlist/Test/Mftf/Data/WishlistData.xml b/app/code/Magento/Wishlist/Test/Mftf/Data/WishlistData.xml index cf87432b3ba79..cc6e9c489a652 100755 --- a/app/code/Magento/Wishlist/Test/Mftf/Data/WishlistData.xml +++ b/app/code/Magento/Wishlist/Test/Mftf/Data/WishlistData.xml @@ -45,4 +45,20 @@ wishlist/general/show_in_sidebar 0 + + rss/config/active + 0 + + + rss/wishlist/active + 0 + + + rss/config/active + 1 + + + rss/wishlist/active + 1 + diff --git a/app/code/Magento/Wishlist/Test/Mftf/Section/StorefrontCustomerWishlistShareSection.xml b/app/code/Magento/Wishlist/Test/Mftf/Section/StorefrontCustomerWishlistShareSection.xml index 3f16133be96a9..1db9f5754638a 100644 --- a/app/code/Magento/Wishlist/Test/Mftf/Section/StorefrontCustomerWishlistShareSection.xml +++ b/app/code/Magento/Wishlist/Test/Mftf/Section/StorefrontCustomerWishlistShareSection.xml @@ -11,6 +11,7 @@
+
diff --git a/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithRssFeedLinkTest.xml b/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithRssFeedLinkTest.xml new file mode 100644 index 0000000000000..75bc9263c199e --- /dev/null +++ b/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithRssFeedLinkTest.xml @@ -0,0 +1,67 @@ + + + + + + + + + + <description value="Customer should be able to share wishlist with RSS feed link"/> + <severity value="AVERAGE"/> + <testCaseId value="AC-2445"/> + <group value="wishlist"/> + </annotations> + <before> + <magentoCLI command="config:set {{EnableRssConfig.path}} {{EnableRssConfig.value}}" + stepKey="enableRssConfig"/> + <magentoCLI command="config:set {{EnableWishlistRssConfig.path}} {{EnableWishlistRssConfig.value}}" + stepKey="enableWishlistRssConfig"/> + <magentoCLI command="cache:clean config full_page block_html" stepKey="cleanCache"/> + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <createData entity="SimpleProduct" stepKey="createProduct"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <createData entity="Simple_US_Customer" stepKey="createCustomer"/> + </before> + <after> + <magentoCLI command="config:set {{DisableRssConfig.path}} {{DisableRssConfig.value}}" + stepKey="disableRssConfig"/> + <magentoCLI command="config:set {{DisableWishlistRssConfig.path}} {{DisableWishlistRssConfig.value}}" + stepKey="disableWishlistRssConfig"/> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <deleteData createDataKey="createProduct" stepKey="deleteProduct"/> + <!-- Customer logout --> + <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/> + <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + </after> + + <!-- Sign in as customer --> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount"> + <argument name="Customer" value="$createCustomer$"/> + </actionGroup> + + <actionGroup ref="OpenProductFromCategoryPageActionGroup" stepKey="openProductFromCategory"> + <argument name="category" value="$createCategory$"/> + <argument name="product" value="$createProduct$"/> + </actionGroup> + + <actionGroup ref="StorefrontCustomerAddProductToWishlistActionGroup" stepKey="addToWishlistProduct"> + <argument name="productVar" value="$createProduct$"/> + </actionGroup> + + <actionGroup ref="StorefrontShareCustomerWishlistWithRssFeedLinkActionGroup" stepKey="shareWishlistWithRssFeed"> + <argument name="email" value="{{Wishlist.shareInfo_emails}}"/> + <argument name="message" value="{{Wishlist.shareInfo_message}}"/> + </actionGroup> + <actionGroup ref="AssertStorefrontCustomerMessagesActionGroup" stepKey="assertSuccessMessage"> + <argument name="message" value="Your wish list has been shared."/> + </actionGroup> + </test> +</tests> From d04f38a1b0fa6f5678e318db4fe611615258e8da Mon Sep 17 00:00:00 2001 From: Faizan Shaikh <glo88465@adobe.com> Date: Tue, 22 Mar 2022 12:43:04 +0530 Subject: [PATCH 07/22] [TASK] - Code improvements --- app/code/Magento/Wishlist/Block/Rss/Link.php | 36 ++++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Wishlist/Block/Rss/Link.php b/app/code/Magento/Wishlist/Block/Rss/Link.php index 179950efef884..4f24d2d118fbd 100644 --- a/app/code/Magento/Wishlist/Block/Rss/Link.php +++ b/app/code/Magento/Wishlist/Block/Rss/Link.php @@ -9,39 +9,45 @@ */ namespace Magento\Wishlist\Block\Rss; +use Magento\Framework\App\Rss\UrlBuilderInterface; +use Magento\Framework\Url\EncoderInterface; +use Magento\Framework\View\Element\Template; +use Magento\Framework\View\Element\Template\Context; +use Magento\Wishlist\Helper\Data; + /** * @api * @since 100.0.2 */ -class Link extends \Magento\Framework\View\Element\Template +class Link extends Template { /** - * @var \Magento\Wishlist\Helper\Data + * @var Data */ - protected $wishlistHelper; + protected Data $wishlistHelper; /** - * @var \Magento\Framework\App\Rss\UrlBuilderInterface + * @var UrlBuilderInterface */ - protected $rssUrlBuilder; + protected UrlBuilderInterface $rssUrlBuilder; /** - * @var \Magento\Framework\Url\EncoderInterface + * @var EncoderInterface */ - protected $urlEncoder; + protected EncoderInterface $urlEncoder; /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Wishlist\Helper\Data $wishlistHelper - * @param \Magento\Framework\App\Rss\UrlBuilderInterface $rssUrlBuilder - * @param \Magento\Framework\Url\EncoderInterface $urlEncoder + * @param Context $context + * @param Data $wishlistHelper + * @param UrlBuilderInterface $rssUrlBuilder + * @param EncoderInterface $urlEncoder * @param array $data */ public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Wishlist\Helper\Data $wishlistHelper, - \Magento\Framework\App\Rss\UrlBuilderInterface $rssUrlBuilder, - \Magento\Framework\Url\EncoderInterface $urlEncoder, + Context $context, + Data $wishlistHelper, + UrlBuilderInterface $rssUrlBuilder, + EncoderInterface $urlEncoder, array $data = [] ) { $data['wishlistHelper'] = $wishlistHelper; From 6b9b50c72e75fe35e6b819606881bbcf1c0c7c77 Mon Sep 17 00:00:00 2001 From: Rajesh Kumar <glo71317@adobe.com> Date: Tue, 22 Mar 2022 20:42:02 +0530 Subject: [PATCH 08/22] Roll back the changes --- .../templates/cart/item/configure/updatecart.phtml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml index 5b0bad49ba425..3b09512eb505b 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml @@ -8,10 +8,10 @@ ?> <?php $_product = $block->getProduct(); ?> <?php $buttonTitle = __('Update Cart'); ?> -<?php if ($_product->isSaleable()):?> +<?php if ($_product->isSaleable()) :?> <div class="box-tocart update"> <fieldset class="fieldset"> - <?php if ($block->shouldRenderQuantity()):?> + <?php if ($block->shouldRenderQuantity()) :?> <div class="field qty"> <label class="label" for="qty"><span><?= $block->escapeHtml(__('Qty')) ?></span></label> <div class="control"> @@ -40,7 +40,11 @@ <script type="text/x-magento-init"> { "#product_addtocart_form": { - "Magento_Catalog/js/validate-product": {} + "validation": {}, + "addToCart": { + "cartButtonId": "#product-updatecart-button", + "cartForm": "#product_addtocart_form" + } } } </script> From b88dcf072a5c3d94248f84e1121ab9f8466dc37c Mon Sep 17 00:00:00 2001 From: Faizan Shaikh <glo88465@adobe.com> Date: Mon, 28 Mar 2022 17:02:53 +0530 Subject: [PATCH 09/22] [BUG#AC-2441] - Setting an invalid Cookie domain crash the website --- .../Model/Config/Backend/DomainTest.php | 21 +++++++++++-------- .../Validator/CookieDomainValidator.php | 19 +++++++++++++++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php b/dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php index 392bb9f7f1bad..34585d65d029c 100644 --- a/dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php +++ b/dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php @@ -6,13 +6,15 @@ namespace Magento\Cookie\Model\Config\Backend; use Magento\Framework\Exception\LocalizedException; +use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\TestCase; /** * Test \Magento\Cookie\Model\Config\Backend\Domain * * @magentoAppArea adminhtml */ -class DomainTest extends \PHPUnit\Framework\TestCase +class DomainTest extends TestCase { /** * @param string $value @@ -22,9 +24,9 @@ class DomainTest extends \PHPUnit\Framework\TestCase */ public function testBeforeSave($value, $exceptionMessage = null) { - /** @var $domain \Magento\Cookie\Model\Config\Backend\Domain */ - $domain = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Cookie\Model\Config\Backend\Domain::class + /** @var $domain Domain */ + $domain = Bootstrap::getObjectManager()->create( + Domain::class ); $domain->setValue($value); $domain->setPath('path'); @@ -45,18 +47,19 @@ public function testBeforeSave($value, $exceptionMessage = null) /** * @return array */ - public function beforeSaveDataProvider() + public function beforeSaveDataProvider(): array { return [ - 'not string' => [['array'], 'Invalid domain name: must be a string'], - 'invalid hostname' => [ + 'notString' => [['array'], 'Invalid domain name: must be a string'], + 'invalidHostname' => [ 'http://', 'Invalid domain name: The input does not match the expected structure for a DNS hostname; ' . 'The input does not appear to be a valid URI hostname; ' . 'The input does not appear to be a valid local network name', ], - 'valid hostname' => ['hostname.com'], - 'empty string' => [''], + 'validHostname' => ['hostname.com'], + 'emptyString' => [''], + 'invalidCharacter' => ['hostname,com', 'Invalid domain name: invalid character in cookie domain'], ]; } } diff --git a/lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php b/lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php index e145484d22a43..62d327bb10c95 100644 --- a/lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php +++ b/lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php @@ -6,10 +6,13 @@ namespace Magento\Framework\Session\Config\Validator; +use Laminas\Validator\Hostname; +use Magento\Framework\Validator\AbstractValidator; + /** * Session cookie domain validator */ -class CookieDomainValidator extends \Magento\Framework\Validator\AbstractValidator +class CookieDomainValidator extends AbstractValidator { /** * @inheritDoc @@ -17,17 +20,29 @@ class CookieDomainValidator extends \Magento\Framework\Validator\AbstractValidat public function isValid($value) { $this->_clearMessages(); + if (!is_string($value)) { $this->_addMessages(['must be a string']); + return false; } - $validator = new \Laminas\Validator\Hostname(\Laminas\Validator\Hostname::ALLOW_ALL); + //Hostname validator allows [;,] and returns the validator as true but these are unacceptable cookie domain + //characters hence need explicit validation for the same + if (preg_match('/[;,]/', $value)) { + $this->_addMessages(['invalid character in cookie domain']); + + return false; + } + + $validator = new Hostname(Hostname::ALLOW_ALL); if (!empty($value) && !$validator->isValid($value)) { $this->_addMessages($validator->getMessages()); + return false; } + return true; } } From 738bf47ea7210d3d0e9ffb9d93583efdcab368f1 Mon Sep 17 00:00:00 2001 From: Faizan Shaikh <glo88465@adobe.com> Date: Tue, 29 Mar 2022 15:01:22 +0530 Subject: [PATCH 10/22] [TASK]-Code imporovements --- .../Magento/Cookie/Model/Config/Backend/DomainTest.php | 4 +--- .../Session/Config/Validator/CookieDomainValidator.php | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php b/dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php index 34585d65d029c..8b56c9f94e733 100644 --- a/dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php +++ b/dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php @@ -25,9 +25,7 @@ class DomainTest extends TestCase public function testBeforeSave($value, $exceptionMessage = null) { /** @var $domain Domain */ - $domain = Bootstrap::getObjectManager()->create( - Domain::class - ); + $domain = Bootstrap::getObjectManager()->create(Domain::class); $domain->setValue($value); $domain->setPath('path'); try { diff --git a/lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php b/lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php index 62d327bb10c95..5b794c26b2dda 100644 --- a/lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php +++ b/lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php @@ -27,8 +27,8 @@ public function isValid($value) return false; } - //Hostname validator allows [;,] and returns the validator as true but these are unacceptable cookie domain - //characters hence need explicit validation for the same + //Hostname validator allows [;,] and returns the validator as true but, + //these are unacceptable cookie domain characters hence need explicit validation for the same if (preg_match('/[;,]/', $value)) { $this->_addMessages(['invalid character in cookie domain']); From f4066868f3ec96ec320b1cd2ff1694552c45ea84 Mon Sep 17 00:00:00 2001 From: Aparna Sreekumar <glo80326@adobe.com> Date: Tue, 29 Mar 2022 18:19:45 +0530 Subject: [PATCH 11/22] BUG#AC-2664: The store that was requested wasnt found on creditmemo grid page - issue fixed --- .../Ui/Component/Listing/Column/PriceTest.php | 16 ++++++++++++++-- .../Sales/Ui/Component/Listing/Column/Price.php | 10 +++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/PriceTest.php b/app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/PriceTest.php index 449ab230b568d..c2639c8bb5664 100644 --- a/app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/PriceTest.php +++ b/app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/PriceTest.php @@ -76,8 +76,7 @@ public function testPrepareDataSource( array $dataSource, string $currencyCode, ?int $expectedStoreId = null - ): void - { + ): void { $itemName = 'itemName'; $oldItemValue = 'oldItemValue'; $newItemValue = 'newItemValue'; @@ -159,11 +158,24 @@ public function testPrepareDataSourceDataProvider(): array ] ] ]; + $dataSource5 = [ + 'data' => [ + 'items' => [ + [ + 'itemName' => 'oldItemValue', + 'store_id' => '123Test', + 'base_currency_code' => '', + ] + ] + ] + ]; + return [ [true, $dataSource1, 'US'], [false, $dataSource2, 'SAR'], [false, $dataSource3, 'SAR', 2], [false, $dataSource4, 'SAR'], + [false, $dataSource5, 'INR'], ]; } } diff --git a/app/code/Magento/Sales/Ui/Component/Listing/Column/Price.php b/app/code/Magento/Sales/Ui/Component/Listing/Column/Price.php index cc323730f14b4..38655cf4a69d8 100644 --- a/app/code/Magento/Sales/Ui/Component/Listing/Column/Price.php +++ b/app/code/Magento/Sales/Ui/Component/Listing/Column/Price.php @@ -76,13 +76,13 @@ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { - $currencyCode = isset($item['base_currency_code']) ? $item['base_currency_code'] : null; + $currencyCode = $item['base_currency_code'] ?? null; + if (!$currencyCode) { - $storeId = isset($item['store_id']) && (int)$item['store_id'] !== 0 ? $item['store_id'] : + $itemStoreId = $item['store_id'] ?? ''; + $storeId = $itemStoreId && is_numeric($itemStoreId) ? $itemStoreId : $this->context->getFilterParam('store_id', Store::DEFAULT_STORE_ID); - $store = $this->storeManager->getStore( - $storeId - ); + $store = $this->storeManager->getStore($storeId); $currencyCode = $store->getBaseCurrency()->getCurrencyCode(); } $basePurchaseCurrency = $this->currency->load($currencyCode); From 63757729b9910b216669091ed50d3c29f7bba9cf Mon Sep 17 00:00:00 2001 From: Aparna Sreekumar <glo80326@adobe.com> Date: Fri, 1 Apr 2022 17:37:58 +0530 Subject: [PATCH 12/22] BUG#AC-2535: Url rewrites are all removed when mass updating visibility on store view when set to not visible indivudually --- .../AdaptUrlRewritesToVisibilityAttribute.php | 2 ++ ...rocessUrlRewriteOnChangeVisibilityObserverTest.php | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php index d329bdf0200a4..96e3564ae2760 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php @@ -70,6 +70,7 @@ public function __construct( */ public function execute(array $productIds, int $visibility, int $storeId): void { + echo'afdsdv'; var_dump($storeId); $products = $this->getProductsByIds($productIds, $storeId); /** @var Product $product */ @@ -79,6 +80,7 @@ public function execute(array $productIds, int $visibility, int $storeId): void [ UrlRewrite::ENTITY_ID => $product->getId(), UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, + UrlRewrite::STORE_ID => $storeId, ] ); } elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) { diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php index 7eb7400837f81..1730f5c335756 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php @@ -67,8 +67,7 @@ public function testMakeProductInvisibleViaMassAction() /** @var StoreManagerInterface $storeManager */ $storeManager = $this->objectManager->get(StoreManagerInterface::class); - $storeManager->setCurrentStore(0); - + $firstStore = current($product->getStoreIds()); $testStore = $storeManager->getStore('test'); $productFilter = [ UrlRewrite::ENTITY_TYPE => 'product', @@ -80,7 +79,7 @@ public function testMakeProductInvisibleViaMassAction() 'target_path' => "catalog/product/view/id/" . $product->getId(), 'is_auto_generated' => 1, 'redirect_type' => 0, - 'store_id' => '1', + 'store_id' => $firstStore, ], [ 'request_path' => "product-1.html", @@ -100,12 +99,14 @@ public function testMakeProductInvisibleViaMassAction() 'catalog_product_attribute_update_before', [ 'attributes_data' => [ ProductInterface::VISIBILITY => Visibility::VISIBILITY_NOT_VISIBLE ], - 'product_ids' => [$product->getId()] + 'product_ids' => [$product->getId()], + 'store_id' => $firstStore ] ); $actual = $this->getActualResults($productFilter); - $this->assertCount(0, $actual); + //Initially count was 2, when visibility of 1 store view is set to not visible individually, the new count is 1 + $this->assertCount(1, $actual); } /** From 861cb3bbd984844170b5fb7ad6325dc4de650c86 Mon Sep 17 00:00:00 2001 From: Aparna Sreekumar <glo80326@adobe.com> Date: Fri, 1 Apr 2022 17:48:34 +0530 Subject: [PATCH 13/22] BUG#AC-2535: Url rewrites are all removed when mass updating visibility on store view when set to not visible indivudually --- .../Model/Products/AdaptUrlRewritesToVisibilityAttribute.php | 1 - .../ProcessUrlRewriteOnChangeVisibilityObserverTest.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php index 96e3564ae2760..629fedde8caa1 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php @@ -70,7 +70,6 @@ public function __construct( */ public function execute(array $productIds, int $visibility, int $storeId): void { - echo'afdsdv'; var_dump($storeId); $products = $this->getProductsByIds($productIds, $storeId); /** @var Product $product */ diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php index 1730f5c335756..3554a6c72a77f 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php @@ -100,7 +100,7 @@ public function testMakeProductInvisibleViaMassAction() [ 'attributes_data' => [ ProductInterface::VISIBILITY => Visibility::VISIBILITY_NOT_VISIBLE ], 'product_ids' => [$product->getId()], - 'store_id' => $firstStore + 'store_id' => $firstStore, ] ); From 91182c7b14c16fc9c02d1888fa4cebb5c15b2449 Mon Sep 17 00:00:00 2001 From: Faizan Shaikh <glo88465@adobe.com> Date: Mon, 4 Apr 2022 10:35:39 +0530 Subject: [PATCH 14/22] [BUG#AC-2621] - Shipping costs not calculated correctly with table rates and virtual/physical products in cart --- .../Model/Carrier/Tablerate.php | 3 + .../Model/ShippingMethodManagementTest.php | 43 ++++++- .../quote_with_simple_and_virtual_product.php | 115 ++++++++++++++++++ ...th_simple_and_virtual_product_rollback.php | 52 ++++++++ 4 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php create mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php index b4351e6c5727d..c28864fc56ec4 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php @@ -111,6 +111,9 @@ public function collectRates(RateRequest $request) } } elseif ($item->getProduct()->isVirtual()) { $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal()); + $request->setPackageValueWithDiscount( + $request->getPackageValueWithDiscount() - $item->getBaseRowTotal() + ); } } } diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php index e938945f2c411..206e39a173aa0 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php @@ -11,7 +11,6 @@ use Magento\Customer\Api\Data\GroupInterface; use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Customer\Model\Vat; -use Magento\Customer\Observer\AfterAddressSaveObserver; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\App\Config\MutableScopeConfigInterface; use Magento\Framework\DataObject; @@ -23,7 +22,6 @@ use Magento\Quote\Api\GuestShippingMethodManagementInterface; use Magento\Quote\Api\ShippingMethodManagementInterface; use Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver; -use Magento\Quote\Observer\Frontend\Quote\Address\VatValidator; use Magento\Store\Model\ScopeInterface; use Magento\Tax\Api\Data\TaxClassInterface; use Magento\Tax\Api\TaxClassRepositoryInterface; @@ -127,6 +125,47 @@ public function testTableRateFreeShipping() } } + /** + * @magentoConfigFixture default_store carriers/tablerate/active 1 + * @magentoConfigFixture default_store carriers/flatrate/active 0 + * @magentoConfigFixture current_store carriers/tablerate/condition_name package_value_with_discount + * @magentoConfigFixture default_store carriers/tablerate/include_virtual_price 0 + * @magentoDataFixture Magento/Sales/_files/quote_with_simple_and_virtual_product.php + * @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php + * @return void + */ + public function testTableRateWithoutIncludingVirtualProduct() + { + $quote = $this->getQuote('quoteWithVirtualProduct'); + $cartId = $quote->getId(); + + if (!$cartId) { + $this->fail('quote fixture failed'); + } + + /** @var QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager + ->create(QuoteIdMaskFactory::class) + ->create() + ->load($cartId, 'quote_id'); + + /** @var GuestShippingMethodManagementInterface $shippingEstimation */ + $shippingEstimation = $this->objectManager->get(GuestShippingMethodManagementInterface::class); + $result = $shippingEstimation->estimateByExtendedAddress( + $quoteIdMask->getMaskedId(), + $quote->getShippingAddress() + ); + + $this->assertCount(1, $result); + $rate = reset($result); + $expectedResult = [ + 'method_code' => 'bestway', + 'amount' => 15, + ]; + $this->assertEquals($expectedResult['method_code'], $rate->getMethodCode()); + $this->assertEquals($expectedResult['amount'], $rate->getAmount()); + } + /** * Test table rate amount for the cart that contains some items with free shipping applied. * diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php new file mode 100644 index 0000000000000..2755508f1d379 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php @@ -0,0 +1,115 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Attribute\Source\Status; +use Magento\Catalog\Model\Product\Type; +use Magento\Catalog\Model\Product\Visibility; +use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\Quote\Address; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Store\Model\StoreManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; + +Bootstrap::getInstance()->loadArea('frontend'); +$objectManager = Bootstrap::getObjectManager(); +$productRepository = $objectManager + ->create(ProductRepositoryInterface::class); +$firstProduct = $objectManager->create(Product::class); +$firstProduct->setTypeId(Type::TYPE_SIMPLE) + ->setCategoryIds([3]) + ->setId(123) + ->setAttributeSetId(4) + ->setName('First Test Product For TableRate') + ->setSku('tableRate-1') + ->setPrice(40) + ->setTaxClassId(0) + ->setMetaTitle('meta title') + ->setMetaKeyword('meta keyword') + ->setMetaDescription('meta description') + ->setVisibility(Visibility::VISIBILITY_BOTH) + ->setStatus(Status::STATUS_ENABLED) + ->setStockData( + [ + 'qty' => 100, + 'is_in_stock' => 1, + 'manage_stock' => 1, + ] + ) + ->save(); + +/** @var ProductRepositoryInterface $productRepository */ +$firstProduct = $productRepository->save($firstProduct); + +$secondProduct = $objectManager->create(Product::class); +$secondProduct->setTypeId(Type::TYPE_VIRTUAL) + ->setCategoryIds([6]) + ->setId(124) + ->setAttributeSetId(4) + ->setName('Second Test Product For TableRate') + ->setSku('tableRate-2') + ->setPrice(20) + ->setTaxClassId(0) + ->setMetaTitle('meta title') + ->setMetaKeyword('meta keyword') + ->setMetaDescription('meta description') + ->setVisibility(Visibility::VISIBILITY_BOTH) + ->setStatus(Status::STATUS_ENABLED) + ->setStockData( + [ + 'qty' => 100, + 'is_in_stock' => 1, + 'manage_stock' => 1, + ] + ) + ->save(); + +/** @var ProductRepositoryInterface $productRepository */ +$secondProduct = $productRepository->save($secondProduct); + +$addressData = include __DIR__ . '/address_data.php'; +$billingAddress = $objectManager->create( + Address::class, + ['data' => $addressData] +); +$billingAddress->setAddressType('billing'); + +$shippingAddress = $objectManager->create( + Address::class, + ['data' => $addressData] +); +$shippingAddress->setAddressType('shipping'); + +$store = $objectManager + ->get(StoreManagerInterface::class) + ->getStore(); + +/** @var Quote $quote */ +$quote = $objectManager->create(Quote::class); +$quote->setCustomerIsGuest(true) + ->setStoreId($store->getId()) + ->setReservedOrderId('quoteWithVirtualProduct') + ->setBillingAddress($billingAddress) + ->setShippingAddress($shippingAddress); +$quote->getPayment()->setMethod('checkmo'); +$quote->addProduct($firstProduct); +$quote->addProduct($secondProduct); +$quote->setIsMultiShipping(0); + +$quoteRepository = $objectManager->get(CartRepositoryInterface::class); +$quoteRepository->save($quote); + +/** @var QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager + ->create(QuoteIdMaskFactory::class) + ->create(); +$quoteIdMask->setQuoteId($quote->getId()) + ->setDataChanges(true) + ->save(); diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php new file mode 100644 index 0000000000000..fd6bb0e8c20fc --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php @@ -0,0 +1,52 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\CatalogInventory\Model\StockRegistryStorage; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Registry; +use Magento\Quote\Model\Quote; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\ObjectManager; + +/** @var $objectManager ObjectManager */ +$objectManager = Bootstrap::getObjectManager(); + +/** @var Registry $registry */ +$registry = $objectManager->get(Registry::class); +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +$quote = $objectManager->create(Quote::class); +$quote->load('quoteWithVirtualProduct', 'reserved_order_id')->delete(); + +/** + * @var ProductRepositoryInterface $productRepository + */ +$productRepository = Bootstrap::getObjectManager() + ->get(ProductRepositoryInterface::class); +try { + $product = $productRepository->get('tableRate-1', false, null, true); + $productRepository->delete($product); +} catch (NoSuchEntityException $e) { + //Product already removed +} + +try { + $customDesignProduct = $productRepository->get('tableRate-2', false, null, true); + $productRepository->delete($customDesignProduct); +} catch (NoSuchEntityException $e) { + //Product already removed +} + +/** @var StockRegistryStorage $stockRegistryStorage */ +$stockRegistryStorage = Bootstrap::getObjectManager() + ->get(StockRegistryStorage::class); +$stockRegistryStorage->clean(); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); From 371da06655c23592b79438236b699618b02bc22c Mon Sep 17 00:00:00 2001 From: Faizan Shaikh <glo88465@adobe.com> Date: Mon, 4 Apr 2022 14:54:35 +0530 Subject: [PATCH 15/22] [BUGFIX] - Fixed integrstion and static test failures --- .../Model/Carrier/Tablerate.php | 3 +- .../quote_with_simple_and_virtual_product.php | 112 ++++++++---------- ...th_simple_and_virtual_product_rollback.php | 4 +- 3 files changed, 50 insertions(+), 69 deletions(-) diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php index c28864fc56ec4..e7a6203d8d15b 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php @@ -136,8 +136,7 @@ public function collectRates(RateRequest $request) $freeQty += $item->getQty() * ($child->getQty() - $freeShipping); } } - } elseif ( - ($item->getFreeShipping() || $item->getAddress()->getFreeShipping()) && + } elseif (($item->getFreeShipping() || $item->getAddress()->getFreeShipping()) && ($item->getFreeShippingMethod() == null || $item->getFreeShippingMethod() && $item->getFreeShippingMethod() == 'tablerate_bestway') ) { diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php index 2755508f1d379..93b0224348ba1 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php @@ -20,96 +20,78 @@ Bootstrap::getInstance()->loadArea('frontend'); $objectManager = Bootstrap::getObjectManager(); -$productRepository = $objectManager - ->create(ProductRepositoryInterface::class); -$firstProduct = $objectManager->create(Product::class); -$firstProduct->setTypeId(Type::TYPE_SIMPLE) - ->setCategoryIds([3]) - ->setId(123) + +$simpleProduct = $objectManager->create(Product::class) + ->setTypeId(Type::TYPE_SIMPLE) ->setAttributeSetId(4) - ->setName('First Test Product For TableRate') - ->setSku('tableRate-1') - ->setPrice(40) - ->setTaxClassId(0) - ->setMetaTitle('meta title') - ->setMetaKeyword('meta keyword') - ->setMetaDescription('meta description') + ->setWebsiteIds([1]) + ->setName('Simple Product') + ->setSku('simple-1') + ->setPrice(10) ->setVisibility(Visibility::VISIBILITY_BOTH) ->setStatus(Status::STATUS_ENABLED) - ->setStockData( - [ - 'qty' => 100, - 'is_in_stock' => 1, - 'manage_stock' => 1, - ] - ) + ->setCategoryIds([2]) + ->setStockData([ + 'use_config_manage_stock' => 1, + 'qty' => 100, + 'is_qty_decimal' => 0, + 'is_in_stock' => 1, + ]) ->save(); -/** @var ProductRepositoryInterface $productRepository */ -$firstProduct = $productRepository->save($firstProduct); +$productRepository = $objectManager->get(ProductRepositoryInterface::class); +$productRepository->save($simpleProduct); -$secondProduct = $objectManager->create(Product::class); -$secondProduct->setTypeId(Type::TYPE_VIRTUAL) - ->setCategoryIds([6]) - ->setId(124) +$virtualProduct = $objectManager->create(Product::class) + ->setTypeId(Type::TYPE_VIRTUAL) ->setAttributeSetId(4) - ->setName('Second Test Product For TableRate') - ->setSku('tableRate-2') - ->setPrice(20) - ->setTaxClassId(0) - ->setMetaTitle('meta title') - ->setMetaKeyword('meta keyword') - ->setMetaDescription('meta description') + ->setWebsiteIds([1]) + ->setName('Virtual Product') + ->setSku('virtual-1') + ->setPrice(10) ->setVisibility(Visibility::VISIBILITY_BOTH) ->setStatus(Status::STATUS_ENABLED) - ->setStockData( - [ - 'qty' => 100, - 'is_in_stock' => 1, - 'manage_stock' => 1, - ] - ) + ->setCategoryIds([2]) + ->setStockData([ + 'use_config_manage_stock' => 1, + 'qty' => 100, + 'is_qty_decimal' => 0, + 'is_in_stock' => 1, + ]) ->save(); -/** @var ProductRepositoryInterface $productRepository */ -$secondProduct = $productRepository->save($secondProduct); +$productRepository->save($virtualProduct); $addressData = include __DIR__ . '/address_data.php'; -$billingAddress = $objectManager->create( - Address::class, - ['data' => $addressData] -); +$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]); $billingAddress->setAddressType('billing'); -$shippingAddress = $objectManager->create( - Address::class, - ['data' => $addressData] -); -$shippingAddress->setAddressType('shipping'); - -$store = $objectManager - ->get(StoreManagerInterface::class) - ->getStore(); +/** @var Address $shippingAddress */ +$shippingAddress = clone $billingAddress; +$shippingAddress->setId(null)->setAddressType('shipping'); /** @var Quote $quote */ $quote = $objectManager->create(Quote::class); -$quote->setCustomerIsGuest(true) - ->setStoreId($store->getId()) +$quote + ->setCustomerIsGuest(true) + ->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId()) ->setReservedOrderId('quoteWithVirtualProduct') ->setBillingAddress($billingAddress) - ->setShippingAddress($shippingAddress); + ->setShippingAddress($shippingAddress) + ->setCustomerEmail('test@test.magento.com'); +$quote->addProduct($simpleProduct); +$quote->addProduct($virtualProduct); + +$quote->getShippingAddress()->setShippingMethod('tablerate_bestway'); $quote->getPayment()->setMethod('checkmo'); -$quote->addProduct($firstProduct); -$quote->addProduct($secondProduct); -$quote->setIsMultiShipping(0); +$quote->collectTotals(); $quoteRepository = $objectManager->get(CartRepositoryInterface::class); $quoteRepository->save($quote); /** @var QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager - ->create(QuoteIdMaskFactory::class) - ->create(); -$quoteIdMask->setQuoteId($quote->getId()) +$quoteIdMask = $objectManager->create(QuoteIdMaskFactory::class)->create(); +$quoteIdMask + ->setQuoteId($quote->getId()) ->setDataChanges(true) ->save(); diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php index fd6bb0e8c20fc..2f4cfaab31da2 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php @@ -30,14 +30,14 @@ $productRepository = Bootstrap::getObjectManager() ->get(ProductRepositoryInterface::class); try { - $product = $productRepository->get('tableRate-1', false, null, true); + $product = $productRepository->get('simple-1', false, null, true); $productRepository->delete($product); } catch (NoSuchEntityException $e) { //Product already removed } try { - $customDesignProduct = $productRepository->get('tableRate-2', false, null, true); + $customDesignProduct = $productRepository->get('virtual-1', false, null, true); $productRepository->delete($customDesignProduct); } catch (NoSuchEntityException $e) { //Product already removed From bd149447d03f30dfd7cbda19c28a8140a87e0c9f Mon Sep 17 00:00:00 2001 From: Aparna Sreekumar <glo80326@adobe.com> Date: Wed, 6 Apr 2022 15:09:54 +0530 Subject: [PATCH 16/22] BUG#AC-2583: Wrong parameter are passed to setFreeShipping method-issue fixed --- .../Quote/Model/Quote/Address/Total/Shipping.php | 2 +- .../Unit/Model/Quote/Address/Total/ShippingTest.php | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php b/app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php index aef9fb04c19ae..64725d8d40a1c 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php +++ b/app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php @@ -73,7 +73,7 @@ public function collect( $address->setFreeMethodWeight($data['freeMethodWeight']); $isFreeShipping = $this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems()); - $address->setFreeShipping($isFreeShipping); + $address->setFreeShipping((int)$isFreeShipping); // recalculate weights $data = $this->getAssignmentWeightData($address, $shippingAssignment->getItems()); $address->setItemQty($data['addressQty']); diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/ShippingTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/ShippingTest.php index d889240de5b02..495a19c97b3ef 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/ShippingTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/ShippingTest.php @@ -209,11 +209,16 @@ public function testCollect(): void $this->shippingAssignment->expects($this->atLeastOnce()) ->method('getItems') ->willReturn([$this->cartItem]); - $this->freeShipping->method('isFreeShipping') + $isFreeShipping = true; + $this->freeShipping + ->expects($this->once()) + ->method('isFreeShipping') ->with($this->quote, [$this->cartItem]) - ->willReturn(true); - $this->address->method('setFreeShipping') - ->with(true); + ->willReturn($isFreeShipping); + $this->address + ->expects($this->once()) + ->method('setFreeShipping') + ->with((int)$isFreeShipping); $this->total->expects($this->atLeastOnce()) ->method('setTotalAmount'); $this->total->expects($this->atLeastOnce()) From f026c3afc065a867bbbc4832148ceda58debdf71 Mon Sep 17 00:00:00 2001 From: Aparna Sreekumar <glo80326@adobe.com> Date: Fri, 8 Apr 2022 13:04:05 +0530 Subject: [PATCH 17/22] BUG#AC-2583 --- .../SalesRule/_files/cart_rule_free_shipping_by_cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/cart_rule_free_shipping_by_cart.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/cart_rule_free_shipping_by_cart.php index 21dcae2c6de38..1c2c297fba4c0 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/_files/cart_rule_free_shipping_by_cart.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/cart_rule_free_shipping_by_cart.php @@ -64,7 +64,7 @@ 'is_rss' => 1, 'use_auto_generation' => 0, 'uses_per_coupon' => 0, - 'simple_free_shipping' => 2, + 'simple_free_shipping' => 1, 'website_ids' => [ $objectManager->get(StoreManagerInterface::class)->getWebsite()->getId() From 0a9148c294f80d0b12b6f4b4ebb9542b7fd0da5c Mon Sep 17 00:00:00 2001 From: glo82145 <glo82145@adobe.com> Date: Wed, 20 Apr 2022 19:35:09 +0530 Subject: [PATCH 18/22] fixed testcase --- .../Product/SearchCriteriaBuilder.php | 2 +- ...em_with_bundle_and_options_with_price2.php | 105 ++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 dev/tests/integration/testsuite/Magento/Bundle/_files/order_item_with_bundle_and_options_with_price2.php diff --git a/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php b/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php index c3c58088ecc00..d67a50875b81d 100644 --- a/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php +++ b/app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php @@ -159,7 +159,7 @@ private function addEntityIdSort(SearchCriteriaInterface $searchCriteria): void { $sortOrderArray = $searchCriteria->getSortOrders(); $sortDir = SortOrder::SORT_DESC; - if (count($sortOrderArray) > 0) { + if (is_array($sortOrderArray) && count($sortOrderArray) > 0) { $sortOrder = end($sortOrderArray); // in the case the last sort order is by position, sort IDs in descendent order $sortDir = $sortOrder->getField() === EavAttributeInterface::POSITION diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/order_item_with_bundle_and_options_with_price2.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/order_item_with_bundle_and_options_with_price2.php new file mode 100644 index 0000000000000..eacd077485f7b --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Bundle/_files/order_item_with_bundle_and_options_with_price2.php @@ -0,0 +1,105 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +use Magento\Bundle\Model\Option; +use Magento\Catalog\Model\Product; +use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Address; +use Magento\Sales\Model\Order\Item; +use Magento\Sales\Model\Order\Payment; +use Magento\Store\Model\StoreManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\Workaround\Override\Fixture\Resolver; + +Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_with_multiple_options_with_price.php'); + +$objectManager = Bootstrap::getObjectManager(); + +$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php'; + + +$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]); +$billingAddress->setAddressType('billing'); + +$shippingAddress = clone $billingAddress; +$shippingAddress->setId(null)->setAddressType('shipping'); + +$payment = $objectManager->create(Payment::class); +$payment->setMethod('checkmo'); + +/** @var $product Product */ +$product = $objectManager->create(Product::class); +$product->load(3); + +/** @var $typeInstance \Magento\Bundle\Model\Product\Type */ +$typeInstance = $product->getTypeInstance(); +$typeInstance->setStoreFilter($product->getStoreId(), $product); + +$optionCollection = $typeInstance->getOptionsCollection($product); + +/** @var $storeManager StoreManagerInterface */ +$storeManager = $objectManager->get(StoreManagerInterface::class); +$storeCurrency = $storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode(); + +$bundleOptions = $bundleOptionsQty = []; +foreach ($optionCollection as $option) { + /** @var $option Option */ + $selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product); + $bundleOptions[$option->getId()] = $option->isMultiSelection() ? + array_column($selectionsCollection->toArray(), 'selection_id') : + $selectionsCollection->getFirstItem()->getSelectionId(); + $bundleOptionsQty[$option->getId()] = 1; +} + +$requestInfo = [ + 'product' => $product->getId(), + 'bundle_option' => $bundleOptions, + 'bundle_option_qty' => $bundleOptionsQty, + 'qty' => 1, + 'custom_price' => 300, +]; + +/** @var Item $orderItem */ +$orderItem = $objectManager->create(Item::class); +$orderItem->setProductId($product->getId()); +$orderItem->setQtyOrdered(1); +$orderItem->setBasePrice($product->getPrice()); +$orderItem->setPrice($product->getPrice()); +$orderItem->setRowTotal($product->getPrice()); +$orderItem->setProductType($product->getTypeId()); +$orderItem->setProductOptions([ + 'info_buyRequest' => $requestInfo, + 'bundle_options' => [ + [ + 'value' => [ + ['title' => $product->getName()] + ], + ], + ], + 'bundle_selection_attributes' => '{"qty":5,"price":99}' +]); + +/** @var Order $order */ +$order = $objectManager->create(Order::class); +$order->setOrderCurrencyCode($storeCurrency); +$order->setIncrementId('100000001'); +$order->setState(Order::STATE_NEW); +$order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_NEW)); +$order->setCustomerIsGuest(true); +$order->setCustomerEmail('customer@null.com'); +$order->setCustomerFirstname('firstname'); +$order->setCustomerLastname('lastname'); +$order->setBillingAddress($billingAddress); +$order->setShippingAddress($shippingAddress); +$order->setAddresses([$billingAddress, $shippingAddress]); +$order->setPayment($payment); +$order->addItem($orderItem); + +$order->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId()); +$order->setSubtotal(100); +$order->setBaseSubtotal(100); +$order->setBaseGrandTotal(100); +$order->save(); From 4afe14c0d6826a0b316819fb76335955633dee75 Mon Sep 17 00:00:00 2001 From: glo82145 <glo82145@adobe.com> Date: Wed, 20 Apr 2022 20:32:31 +0530 Subject: [PATCH 19/22] fixing wrong commit --- ...em_with_bundle_and_options_with_price2.php | 105 ------------------ 1 file changed, 105 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Bundle/_files/order_item_with_bundle_and_options_with_price2.php diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/order_item_with_bundle_and_options_with_price2.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/order_item_with_bundle_and_options_with_price2.php deleted file mode 100644 index eacd077485f7b..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Bundle/_files/order_item_with_bundle_and_options_with_price2.php +++ /dev/null @@ -1,105 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -use Magento\Bundle\Model\Option; -use Magento\Catalog\Model\Product; -use Magento\Sales\Model\Order; -use Magento\Sales\Model\Order\Address; -use Magento\Sales\Model\Order\Item; -use Magento\Sales\Model\Order\Payment; -use Magento\Store\Model\StoreManagerInterface; -use Magento\TestFramework\Helper\Bootstrap; -use Magento\TestFramework\Workaround\Override\Fixture\Resolver; - -Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_with_multiple_options_with_price.php'); - -$objectManager = Bootstrap::getObjectManager(); - -$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php'; - - -$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]); -$billingAddress->setAddressType('billing'); - -$shippingAddress = clone $billingAddress; -$shippingAddress->setId(null)->setAddressType('shipping'); - -$payment = $objectManager->create(Payment::class); -$payment->setMethod('checkmo'); - -/** @var $product Product */ -$product = $objectManager->create(Product::class); -$product->load(3); - -/** @var $typeInstance \Magento\Bundle\Model\Product\Type */ -$typeInstance = $product->getTypeInstance(); -$typeInstance->setStoreFilter($product->getStoreId(), $product); - -$optionCollection = $typeInstance->getOptionsCollection($product); - -/** @var $storeManager StoreManagerInterface */ -$storeManager = $objectManager->get(StoreManagerInterface::class); -$storeCurrency = $storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode(); - -$bundleOptions = $bundleOptionsQty = []; -foreach ($optionCollection as $option) { - /** @var $option Option */ - $selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product); - $bundleOptions[$option->getId()] = $option->isMultiSelection() ? - array_column($selectionsCollection->toArray(), 'selection_id') : - $selectionsCollection->getFirstItem()->getSelectionId(); - $bundleOptionsQty[$option->getId()] = 1; -} - -$requestInfo = [ - 'product' => $product->getId(), - 'bundle_option' => $bundleOptions, - 'bundle_option_qty' => $bundleOptionsQty, - 'qty' => 1, - 'custom_price' => 300, -]; - -/** @var Item $orderItem */ -$orderItem = $objectManager->create(Item::class); -$orderItem->setProductId($product->getId()); -$orderItem->setQtyOrdered(1); -$orderItem->setBasePrice($product->getPrice()); -$orderItem->setPrice($product->getPrice()); -$orderItem->setRowTotal($product->getPrice()); -$orderItem->setProductType($product->getTypeId()); -$orderItem->setProductOptions([ - 'info_buyRequest' => $requestInfo, - 'bundle_options' => [ - [ - 'value' => [ - ['title' => $product->getName()] - ], - ], - ], - 'bundle_selection_attributes' => '{"qty":5,"price":99}' -]); - -/** @var Order $order */ -$order = $objectManager->create(Order::class); -$order->setOrderCurrencyCode($storeCurrency); -$order->setIncrementId('100000001'); -$order->setState(Order::STATE_NEW); -$order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_NEW)); -$order->setCustomerIsGuest(true); -$order->setCustomerEmail('customer@null.com'); -$order->setCustomerFirstname('firstname'); -$order->setCustomerLastname('lastname'); -$order->setBillingAddress($billingAddress); -$order->setShippingAddress($shippingAddress); -$order->setAddresses([$billingAddress, $shippingAddress]); -$order->setPayment($payment); -$order->addItem($orderItem); - -$order->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId()); -$order->setSubtotal(100); -$order->setBaseSubtotal(100); -$order->setBaseGrandTotal(100); -$order->save(); From c659356a1d7e89c6032c0576d3da61b705e817ac Mon Sep 17 00:00:00 2001 From: Aparna Sreekumar <glo80326@adobe.com> Date: Thu, 21 Apr 2022 11:34:02 +0530 Subject: [PATCH 20/22] Added Source Item fixture --- .../Test/Fixture/SourceItem.php | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.php diff --git a/app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.php b/app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.php new file mode 100644 index 0000000000000..f6f8cef180c30 --- /dev/null +++ b/app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.php @@ -0,0 +1,94 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\CatalogInventory\Test\Fixture; + +use Magento\Framework\DataObject; +use Magento\InventoryApi\Api\Data\SourceItemInterface; +use Magento\InventoryApi\Api\SourceItemsDeleteInterface; +use Magento\InventoryApi\Api\SourceItemsSaveInterface; +use Magento\TestFramework\Fixture\Api\DataMerger; +use Magento\TestFramework\Fixture\Api\ServiceFactory; +use Magento\TestFramework\Fixture\Data\ProcessorInterface; +use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface; + +class SourceItem implements RevertibleDataFixtureInterface +{ + private const DEFAULT_DATA = [ + 'sku' => 'SKU-%uniqid%', + 'source_code' => 'Source%uniqid%', + 'quantity' => 5, + 'status' => SourceItemInterface::STATUS_IN_STOCK, + ]; + + /** + * @var ServiceFactory + */ + private ServiceFactory $serviceFactory; + + /** + * @var ProcessorInterface + */ + private ProcessorInterface $dataProcessor; + + /** + * @var DataMerger + */ + private DataMerger $dataMerger; + + /** + * @param ServiceFactory $serviceFactory + * @param ProcessorInterface $dataProcessor + * @param DataMerger $dataMerger + */ + public function __construct( + ServiceFactory $serviceFactory, + ProcessorInterface $dataProcessor, + DataMerger $dataMerger + ) { + $this->serviceFactory = $serviceFactory; + $this->dataProcessor = $dataProcessor; + $this->dataMerger = $dataMerger; + } + + /** + * @param array $data + * @return DataObject|null + */ + public function apply(array $data = []): ?DataObject + { + $service = $this->serviceFactory->create(SourceItemsSaveInterface::class, 'execute'); + + return $service->execute(['sourceItems' => [$this->prepareData($data)]]); + } + + /** + * @inheritdoc + */ + public function revert(DataObject $data): void + { + $service = $this->serviceFactory->create(SourceItemsDeleteInterface::class, 'execute'); + $service->execute( + [ + 'sourceItems' => [$this->prepareData($data->getData())] + ] + ); + } + + /** + * Prepare product data + * + * @param array $data + * @return array + */ + private function prepareData(array $data): array + { + $data = $this->dataMerger->merge(self::DEFAULT_DATA, $data, false); + + return $this->dataProcessor->process($this, $data); + } +} From b09aa29d359343fe5c73f05ea6fd51feab6ceab0 Mon Sep 17 00:00:00 2001 From: Aparna Sreekumar <glo80326@adobe.com> Date: Thu, 21 Apr 2022 11:37:30 +0530 Subject: [PATCH 21/22] Added Source Item fixture --- .../Magento/CatalogInventory/Test/Fixture/SourceItem.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.php b/app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.php index f6f8cef180c30..68a887c580860 100644 --- a/app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.php +++ b/app/code/Magento/CatalogInventory/Test/Fixture/SourceItem.php @@ -72,11 +72,7 @@ public function apply(array $data = []): ?DataObject public function revert(DataObject $data): void { $service = $this->serviceFactory->create(SourceItemsDeleteInterface::class, 'execute'); - $service->execute( - [ - 'sourceItems' => [$this->prepareData($data->getData())] - ] - ); + $service->execute(['sourceItems' => [$this->prepareData($data->getData())]]); } /** From 953f776cd30bb3d52b3ea944582bf2da2916a61b Mon Sep 17 00:00:00 2001 From: Faizan Shaikh <glo88465@adobe.com> Date: Thu, 21 Apr 2022 13:31:12 +0530 Subject: [PATCH 22/22] [TASK] - Reworked on Integration tests to fix newly introduced legacy static test failures --- .../Model/ShippingMethodManagementTest.php | 37 +++++-- .../quote_with_simple_and_virtual_product.php | 97 ------------------- ...th_simple_and_virtual_product_rollback.php | 52 ---------- 3 files changed, 27 insertions(+), 159 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php delete mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php index 206e39a173aa0..b88eccd69f2de 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php @@ -27,6 +27,8 @@ use Magento\Tax\Api\TaxClassRepositoryInterface; use Magento\Tax\Model\ClassModel; use Magento\Tax\Model\Config as TaxConfig; +use Magento\TestFramework\Fixture\DataFixtureStorage; +use Magento\TestFramework\Fixture\DataFixtureStorageManager; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId; use PHPUnit\Framework\TestCase; @@ -48,6 +50,11 @@ class ShippingMethodManagementTest extends TestCase /** @var TaxClassRepositoryInterface $taxClassRepository */ private $taxClassRepository; + /** + * @var DataFixtureStorage + */ + private $fixtures; + /** * @inheritdoc */ @@ -56,6 +63,7 @@ protected function setUp(): void $this->objectManager = Bootstrap::getObjectManager(); $this->groupRepository = $this->objectManager->get(GroupRepositoryInterface::class); $this->taxClassRepository = $this->objectManager->get(TaxClassRepositoryInterface::class); + $this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage(); } /** @@ -126,33 +134,42 @@ public function testTableRateFreeShipping() } /** + * phpcs:disable Generic.Files.LineLength.TooLong + * * @magentoConfigFixture default_store carriers/tablerate/active 1 * @magentoConfigFixture default_store carriers/flatrate/active 0 * @magentoConfigFixture current_store carriers/tablerate/condition_name package_value_with_discount * @magentoConfigFixture default_store carriers/tablerate/include_virtual_price 0 - * @magentoDataFixture Magento/Sales/_files/quote_with_simple_and_virtual_product.php + * @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"sku":"simple", "type_id":"simple"} as:p1 + * @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"sku":"virtual", "type_id":"virtual", "weight":0} as:p2 + * @magentoDataFixture Magento\Quote\Test\Fixture\GuestCart as:cart + * @magentoDataFixture Magento\Quote\Test\Fixture\AddProductToCart with:{"cart_id":"$cart.id$", "product_id":"$p1.id$"} + * @magentoDataFixture Magento\Quote\Test\Fixture\AddProductToCart with:{"cart_id":"$cart.id$", "product_id":"$p2.id$"} + * @magentoDataFixture Magento\Quote\Test\Fixture\SetBillingAddress with:{"cart_id":"$cart.id$"} + * @magentoDataFixture Magento\Quote\Test\Fixture\SetShippingAddress with:{"cart_id":"$cart.id$"} * @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php * @return void + * @throws NoSuchEntityException */ public function testTableRateWithoutIncludingVirtualProduct() { - $quote = $this->getQuote('quoteWithVirtualProduct'); - $cartId = $quote->getId(); + $cartId = (int)$this->fixtures->get('cart')->getId(); if (!$cartId) { $this->fail('quote fixture failed'); } - /** @var QuoteIdMask $quoteIdMask */ - $quoteIdMask = $this->objectManager - ->create(QuoteIdMaskFactory::class) - ->create() - ->load($cartId, 'quote_id'); + /** @var QuoteRepository $quoteRepository */ + $quoteRepository = $this->objectManager->get(QuoteRepository::class); + $quote = $quoteRepository->get($cartId); - /** @var GuestShippingMethodManagementInterface $shippingEstimation */ + /** @var QuoteIdToMaskedQuoteIdInterface $maskedQuoteId */ + $maskedQuoteId = $this->objectManager->get(QuoteIdToMaskedQuoteIdInterface::class)->execute($cartId); + + /** @var GuestShippingMethodManagementInterface $shippingEstimation */ $shippingEstimation = $this->objectManager->get(GuestShippingMethodManagementInterface::class); $result = $shippingEstimation->estimateByExtendedAddress( - $quoteIdMask->getMaskedId(), + $maskedQuoteId, $quote->getShippingAddress() ); diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php deleted file mode 100644 index 93b0224348ba1..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\Catalog\Model\Product; -use Magento\Catalog\Model\Product\Attribute\Source\Status; -use Magento\Catalog\Model\Product\Type; -use Magento\Catalog\Model\Product\Visibility; -use Magento\Quote\Api\CartRepositoryInterface; -use Magento\Quote\Model\Quote; -use Magento\Quote\Model\Quote\Address; -use Magento\Quote\Model\QuoteIdMask; -use Magento\Quote\Model\QuoteIdMaskFactory; -use Magento\Store\Model\StoreManagerInterface; -use Magento\TestFramework\Helper\Bootstrap; - -Bootstrap::getInstance()->loadArea('frontend'); -$objectManager = Bootstrap::getObjectManager(); - -$simpleProduct = $objectManager->create(Product::class) - ->setTypeId(Type::TYPE_SIMPLE) - ->setAttributeSetId(4) - ->setWebsiteIds([1]) - ->setName('Simple Product') - ->setSku('simple-1') - ->setPrice(10) - ->setVisibility(Visibility::VISIBILITY_BOTH) - ->setStatus(Status::STATUS_ENABLED) - ->setCategoryIds([2]) - ->setStockData([ - 'use_config_manage_stock' => 1, - 'qty' => 100, - 'is_qty_decimal' => 0, - 'is_in_stock' => 1, - ]) - ->save(); - -$productRepository = $objectManager->get(ProductRepositoryInterface::class); -$productRepository->save($simpleProduct); - -$virtualProduct = $objectManager->create(Product::class) - ->setTypeId(Type::TYPE_VIRTUAL) - ->setAttributeSetId(4) - ->setWebsiteIds([1]) - ->setName('Virtual Product') - ->setSku('virtual-1') - ->setPrice(10) - ->setVisibility(Visibility::VISIBILITY_BOTH) - ->setStatus(Status::STATUS_ENABLED) - ->setCategoryIds([2]) - ->setStockData([ - 'use_config_manage_stock' => 1, - 'qty' => 100, - 'is_qty_decimal' => 0, - 'is_in_stock' => 1, - ]) - ->save(); - -$productRepository->save($virtualProduct); - -$addressData = include __DIR__ . '/address_data.php'; -$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]); -$billingAddress->setAddressType('billing'); - -/** @var Address $shippingAddress */ -$shippingAddress = clone $billingAddress; -$shippingAddress->setId(null)->setAddressType('shipping'); - -/** @var Quote $quote */ -$quote = $objectManager->create(Quote::class); -$quote - ->setCustomerIsGuest(true) - ->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId()) - ->setReservedOrderId('quoteWithVirtualProduct') - ->setBillingAddress($billingAddress) - ->setShippingAddress($shippingAddress) - ->setCustomerEmail('test@test.magento.com'); -$quote->addProduct($simpleProduct); -$quote->addProduct($virtualProduct); - -$quote->getShippingAddress()->setShippingMethod('tablerate_bestway'); -$quote->getPayment()->setMethod('checkmo'); -$quote->collectTotals(); - -$quoteRepository = $objectManager->get(CartRepositoryInterface::class); -$quoteRepository->save($quote); - -/** @var QuoteIdMask $quoteIdMask */ -$quoteIdMask = $objectManager->create(QuoteIdMaskFactory::class)->create(); -$quoteIdMask - ->setQuoteId($quote->getId()) - ->setDataChanges(true) - ->save(); diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php deleted file mode 100644 index 2f4cfaab31da2..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_simple_and_virtual_product_rollback.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\CatalogInventory\Model\StockRegistryStorage; -use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Framework\Registry; -use Magento\Quote\Model\Quote; -use Magento\TestFramework\Helper\Bootstrap; -use Magento\TestFramework\ObjectManager; - -/** @var $objectManager ObjectManager */ -$objectManager = Bootstrap::getObjectManager(); - -/** @var Registry $registry */ -$registry = $objectManager->get(Registry::class); -$registry->unregister('isSecureArea'); -$registry->register('isSecureArea', true); - -$quote = $objectManager->create(Quote::class); -$quote->load('quoteWithVirtualProduct', 'reserved_order_id')->delete(); - -/** - * @var ProductRepositoryInterface $productRepository - */ -$productRepository = Bootstrap::getObjectManager() - ->get(ProductRepositoryInterface::class); -try { - $product = $productRepository->get('simple-1', false, null, true); - $productRepository->delete($product); -} catch (NoSuchEntityException $e) { - //Product already removed -} - -try { - $customDesignProduct = $productRepository->get('virtual-1', false, null, true); - $productRepository->delete($customDesignProduct); -} catch (NoSuchEntityException $e) { - //Product already removed -} - -/** @var StockRegistryStorage $stockRegistryStorage */ -$stockRegistryStorage = Bootstrap::getObjectManager() - ->get(StockRegistryStorage::class); -$stockRegistryStorage->clean(); - -$registry->unregister('isSecureArea'); -$registry->register('isSecureArea', false);