diff --git a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml index 293d70df8c8e6..84f9a7930d40b 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml @@ -48,7 +48,7 @@ - + diff --git a/app/code/Magento/Checkout/ViewModel/Cart.php b/app/code/Magento/Checkout/ViewModel/Cart.php index 2bdfe504d4627..21fe090249a92 100644 --- a/app/code/Magento/Checkout/ViewModel/Cart.php +++ b/app/code/Magento/Checkout/ViewModel/Cart.php @@ -16,7 +16,7 @@ class Cart implements ArgumentInterface /** * Config settings path to enable clear shopping cart button */ - private const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart'; + public const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart'; /** * @var ScopeConfigInterface @@ -41,7 +41,7 @@ public function __construct( */ public function isClearShoppingCartEnabled() { - return (bool) $this->_scopeConfig->getValue( + return (bool)$this->_scopeConfig->getValue( self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART, ScopeInterface::SCOPE_WEBSITE ); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/ViewModel/CartTest.php b/dev/tests/integration/testsuite/Magento/Checkout/ViewModel/CartTest.php new file mode 100644 index 0000000000000..52040a503c37a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/ViewModel/CartTest.php @@ -0,0 +1,126 @@ +objectManager = Bootstrap::getObjectManager(); + $this->cart = $objectManager->get(Cart::class); + $this->mutableScopeConfig = $objectManager->get(MutableScopeConfigInterface::class); + $this->storeManager = $objectManager->get(StoreManagerInterface::class); + } + + /** + * @magentoAppArea frontend + * @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testConfigClearShoppingCartEnabledWithWebsiteScopes() + { + // Assert not active by default + $this->assertFalse($this->cart->isClearShoppingCartEnabled()); + + // Enable Clear Shopping Cart in default website scope + $this->setClearShoppingCartEnabled( + true, + ScopeInterface::SCOPE_WEBSITE + ); + + // Assert now active in default website scope + $this->assertTrue($this->cart->isClearShoppingCartEnabled()); + + $defaultStore = $this->storeManager->getStore(); + $defaultWebsite = $defaultStore->getWebsite(); + $defaultWebsiteCode = $defaultWebsite->getCode(); + + $secondStore = $this->storeManager->getStore('fixture_second_store'); + $secondWebsite = $secondStore->getWebsite(); + $secondWebsiteCode = $secondWebsite->getCode(); + + // Change current store context to that of second website + $this->storeManager->setCurrentStore($secondStore); + + // Assert not active by default in second website + $this->assertFalse($this->cart->isClearShoppingCartEnabled()); + + // Enable Clear Shopping Cart in second website scope + $this->setClearShoppingCartEnabled( + true, + ScopeInterface::SCOPE_WEBSITE, + $secondWebsiteCode + ); + + // Assert now active in second website scope + $this->assertTrue($this->cart->isClearShoppingCartEnabled()); + + // Disable Clear Shopping Cart in default website scope + $this->setClearShoppingCartEnabled( + false, + ScopeInterface::SCOPE_WEBSITE, + $defaultWebsiteCode + ); + + // Assert still active in second website + $this->assertTrue($this->cart->isClearShoppingCartEnabled()); + } + + /** + * Set purchase order enabled status. + * + * @param bool $isActive + * @param string $scope + * @param string|null $scopeCode + */ + private function setClearShoppingCartEnabled(bool $isActive, string $scope, $scopeCode = null) + { + $this->mutableScopeConfig->setValue( + 'checkout/cart/enable_clear_shopping_cart', + $isActive ? '1' : '0', + $scope, + $scopeCode + ); + } +}