From 113b90f2bf64461ab5fbd09b614fd9352439dc3d Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Thu, 27 Oct 2016 15:36:19 +0300 Subject: [PATCH 01/11] MAGETWO-60327: [GITHUB] Orders always get a status of Suspected Fraud in multi-currency store configurations #4263 (cherry picked from commit e04fc7f) --- app/code/Magento/Sales/Model/Order/Payment.php | 2 +- app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Payment.php b/app/code/Magento/Sales/Model/Order/Payment.php index 9e71eba773538..fd207149a2d1f 100644 --- a/app/code/Magento/Sales/Model/Order/Payment.php +++ b/app/code/Magento/Sales/Model/Order/Payment.php @@ -1260,7 +1260,7 @@ public function getAuthorizationTransaction() */ public function isCaptureFinal($amountToCapture) { - $total = $this->getOrder()->getTotalDue(); + $total = $this->getOrder()->getBaseTotalDue(); return $this->formatAmount($total, true) == $this->formatAmount($amountToCapture, true); } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php index f640e9dfdbb0e..6b1ec71f249da 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php @@ -1521,7 +1521,7 @@ public function testIsCaptureFinal() $partialAmount = 12.00; $this->orderMock->expects(static::exactly(2)) - ->method('getTotalDue') + ->method('getBaseTotalDue') ->willReturn($amount); static::assertFalse($this->payment->isCaptureFinal($partialAmount)); From acd6609780cdee048cccc68480f0bcd52d918560 Mon Sep 17 00:00:00 2001 From: RomaKis Date: Fri, 18 Nov 2016 20:45:02 +0200 Subject: [PATCH 02/11] MAGETWO-60327: [GITHUB] Orders always get a status of Suspected Fraud in multi-currency store configurations #4263 --- .../Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php b/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php index 29e45a4016bca..6d1f961f0c0fb 100644 --- a/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php @@ -470,7 +470,7 @@ protected function setupOrderMock( 'getCustomerEmail', 'getCustomerId', 'getStoreId', - 'getTotalDue' + 'getBaseTotalDue' ] )->getMock(); @@ -493,7 +493,7 @@ protected function setupOrderMock( ->method('getStoreId') ->willReturn($storeId); $orderMock->expects(static::any()) - ->method('getTotalDue') + ->method('getBaseTotalDue') ->willReturn(self::TOTAL_AMOUNT); $this->orderRepository->expects(static::any()) @@ -1696,7 +1696,7 @@ protected function setupPaymentObjectForCapture($paymentId) $order = $this->getMockBuilder('Magento\Sales\Api\Data\OrderInterface') ->getMockForAbstractClass(); $order->expects(static::any()) - ->method('getTotalDue') + ->method('getBaseTotalDue') ->willReturn(self::TOTAL_AMOUNT); $this->orderRepository->expects(static::any()) ->method('get') From 5ba083393edae59f83687bb0e7f974821514e9da Mon Sep 17 00:00:00 2001 From: RomaKis Date: Wed, 23 Nov 2016 13:44:31 +0200 Subject: [PATCH 03/11] MAGETWO-60965: [Backport] - New attribute is not visible when create new address - for 2.0 --- .../frontend/web/template/billing-address/details.html | 8 +++++++- .../shipping-address/address-renderer/default.html | 8 +++++++- .../shipping-information/address-renderer/default.html | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/template/billing-address/details.html b/app/code/Magento/Checkout/view/frontend/web/template/billing-address/details.html index a3c17315d98cc..cd4436ceb5384 100644 --- a/app/code/Magento/Checkout/view/frontend/web/template/billing-address/details.html +++ b/app/code/Magento/Checkout/view/frontend/web/template/billing-address/details.html @@ -13,7 +13,13 @@ - + + + + + + +
diff --git a/app/code/Magento/Checkout/view/frontend/web/template/shipping-address/address-renderer/default.html b/app/code/Magento/Checkout/view/frontend/web/template/shipping-address/address-renderer/default.html index 11a1eeb1cb13b..369c84c7ca41f 100644 --- a/app/code/Magento/Checkout/view/frontend/web/template/shipping-address/address-renderer/default.html +++ b/app/code/Magento/Checkout/view/frontend/web/template/shipping-address/address-renderer/default.html @@ -13,7 +13,13 @@ - + + + + + + +
diff --git a/app/code/Magento/Checkout/view/frontend/web/template/shipping-information/address-renderer/default.html b/app/code/Magento/Checkout/view/frontend/web/template/shipping-information/address-renderer/default.html index 27e38ec15b917..af202791a4233 100644 --- a/app/code/Magento/Checkout/view/frontend/web/template/shipping-information/address-renderer/default.html +++ b/app/code/Magento/Checkout/view/frontend/web/template/shipping-information/address-renderer/default.html @@ -13,7 +13,14 @@ - + + + + + + +
+ From bb155f6dd141d7ed0bcb42229e53f19ccdb71ca4 Mon Sep 17 00:00:00 2001 From: RomaKis Date: Wed, 23 Nov 2016 15:00:18 +0200 Subject: [PATCH 04/11] MAGETWO-60965: [Backport] - New attribute is not visible when create new address - for 2.0 --- .../Customer/Test/Block/Address/Edit.php | 18 +++++++ .../Test/Page/CustomerAddressEdit.php | 51 ------------------- .../Test/Page/CustomerAddressEdit.xml | 12 +++++ 3 files changed, 30 insertions(+), 51 deletions(-) delete mode 100644 dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.php create mode 100644 dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.xml diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Block/Address/Edit.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Block/Address/Edit.php index b9d5f3c3af01e..17a78c28ffa0e 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Block/Address/Edit.php +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Block/Address/Edit.php @@ -61,4 +61,22 @@ public function saveAddress() { $this->_rootElement->find($this->saveAddress)->click(); } + + /** + * Fixture mapping. + * + * @param array|null $fields + * @param string|null $parent + * @return array + */ + protected function dataMapping(array $fields = null, $parent = null) + { + if (isset($fields['custom_attribute'])) { + $this->placeholders = + ['attribute_code' => $fields['custom_attribute']['code']]; + $this->applyPlaceholders(); + } + + return parent::dataMapping($fields, $parent); + } } diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.php deleted file mode 100644 index 4946f08258709..0000000000000 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.php +++ /dev/null @@ -1,51 +0,0 @@ -url = $_ENV['app_frontend_url'] . self::MCA; - } - - /** - * Get Customer Address Edit form. - * - * @return \Magento\Customer\Test\Block\Address\Edit - */ - public function getEditForm() - { - return Factory::getBlockFactory()->getMagentoCustomerAddressEdit( - $this->browser->find($this->editForm, Locator::SELECTOR_CSS) - ); - } -} diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.xml new file mode 100644 index 0000000000000..2f3738d05e5e3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.xml @@ -0,0 +1,12 @@ + + + + + + + From 5089d584b5dda552809c3e1581257ae1c5afab28 Mon Sep 17 00:00:00 2001 From: Myroslav Dobra Date: Wed, 23 Nov 2016 17:42:30 +0200 Subject: [PATCH 05/11] MAGETWO-60724: [Backport] - Nginx doesn't redirect to setup page when using port - for 2.0 --- lib/internal/Magento/Framework/App/Http.php | 3 +-- lib/internal/Magento/Framework/App/SetupInfo.php | 8 ++++++++ .../Magento/Framework/App/Test/Unit/SetupInfoTest.php | 7 +++++++ .../Magento/Framework/App/Test/Unit/_files/pub/index.php | 5 +++++ .../Framework/App/Test/Unit/_files/setup/index.php | 5 +++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/_files/pub/index.php create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/_files/setup/index.php diff --git a/lib/internal/Magento/Framework/App/Http.php b/lib/internal/Magento/Framework/App/Http.php index 83fc6d2d83fee..423eb9b9b3f39 100644 --- a/lib/internal/Magento/Framework/App/Http.php +++ b/lib/internal/Magento/Framework/App/Http.php @@ -188,8 +188,7 @@ private function redirectToSetup(Bootstrap $bootstrap, \Exception $exception) . "because the Magento setup directory cannot be accessed. \n" . 'You can install Magento using either the command line or you must restore access ' . 'to the following directory: ' . $setupInfo->getDir($projectRoot) . "\n"; - $newMessage .= 'If you are using the sample nginx configuration, please go to ' - . $this->_request->getScheme(). '://' . $this->_request->getHttpHost() . $setupInfo->getUrl(); + throw new \Exception($newMessage, 0, $exception); } } diff --git a/lib/internal/Magento/Framework/App/SetupInfo.php b/lib/internal/Magento/Framework/App/SetupInfo.php index 0c4c95f6ab9ac..768e0ce399e1b 100644 --- a/lib/internal/Magento/Framework/App/SetupInfo.php +++ b/lib/internal/Magento/Framework/App/SetupInfo.php @@ -145,6 +145,14 @@ public function isAvailable() { $setupDir = $this->getDir($this->projectRoot); $isSubDir = false !== strpos($setupDir . '/', $this->docRoot . '/'); + // Setup is not accessible from pub folder + $setupDir = rtrim($setupDir, '/'); + $lastOccurrence = strrpos($setupDir, '/pub/setup'); + + if (false !== $lastOccurrence) { + $setupDir = substr_replace($setupDir, '/setup', $lastOccurrence, strlen('/pub/setup')); + } + return $isSubDir && realpath($setupDir); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/SetupInfoTest.php b/lib/internal/Magento/Framework/App/Test/Unit/SetupInfoTest.php index 7f67923363e18..6c9bc89244f2f 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/SetupInfoTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/SetupInfoTest.php @@ -191,6 +191,13 @@ public function isAvailableDataProvider() ], true ], + 'root within doc root + pub, existent sub-directory' => [ + [ + 'DOCUMENT_ROOT' => __DIR__ . '/_files/pub/', + 'SCRIPT_FILENAME' => __DIR__ . '/_files/pub/index.php', + ], + true + ], ]; } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/_files/pub/index.php b/lib/internal/Magento/Framework/App/Test/Unit/_files/pub/index.php new file mode 100644 index 0000000000000..2a0cd37c68d37 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/_files/pub/index.php @@ -0,0 +1,5 @@ + Date: Thu, 24 Nov 2016 15:22:03 +0200 Subject: [PATCH 06/11] MAGETWO-60965: [Backport] - New attribute is not visible when create new address - for 2.0 --- .../Test/TestStep/CreateProductsStep.php | 10 ++- .../Checkout/Test/Block/Onepage/Shipping.php | 60 ++++++++++++- .../Block/Onepage/Shipping/AddressModal.php | 86 +++++++++++++++++++ .../Block/Onepage/Shipping/AddressModal.xml | 29 +++++++ .../TestStep/AddNewShippingAddressStep.php | 59 +++++++++++++ 5 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.php create mode 100644 dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.xml create mode 100644 dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/AddNewShippingAddressStep.php diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductsStep.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductsStep.php index 77c2f4d3c7fb0..167e309cc151b 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductsStep.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductsStep.php @@ -19,7 +19,7 @@ class CreateProductsStep implements TestStepInterface /** * Products names in data set * - * @var string + * @var string|array */ protected $products; @@ -60,8 +60,12 @@ public function __construct(FixtureFactory $fixtureFactory, $products, array $da public function run() { $products = []; - $productsDataSets = explode(',', $this->products); - foreach ($productsDataSets as $key => $productDataSet) { + + if (!is_array($this->products)) { // for backward compatible changes + $this->products = explode(',', $this->products); + } + + foreach ($this->products as $key => $productDataSet) { $productDataSet = explode('::', $productDataSet); $fixtureClass = $productDataSet[0]; $dataset = isset($productDataSet[1]) ? $productDataSet[1] : ''; diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php index a3eda5ea1b3c5..57ad158d44707 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php @@ -6,12 +6,70 @@ namespace Magento\Checkout\Test\Block\Onepage; +use Magento\Checkout\Test\Block\Onepage\Shipping\AddressModal; use Magento\Mtf\Block\Form; +use Magento\Mtf\Client\Locator; /** * Checkout shipping address block. */ class Shipping extends Form { - // + /** + * CSS Selector for "New Address" button + * + * @var string + */ + private $newAddressButton = '[data-bind*="isNewAddressAdded"]'; + + /** + * Wait element. + * + * @var string + */ + private $waitElement = '.loading-mask'; + + /** + * SCC Selector for Address Modal block. + * + * @var string + */ + private $addressModalBlock = '//*[@id="opc-new-shipping-address"]/../..'; + + /** + * @var string + */ + private $selectedAddress = '.shipping-address-item.selected-item'; + + /** + * Click on "New Address" button. + * + * @return void + */ + public function clickOnNewAddressButton() + { + $this->waitForElementNotVisible($this->waitElement); + $this->_rootElement->find($this->newAddressButton)->click(); + } + + /** + * Get Address Modal Block. + * + * @return AddressModal + */ + public function getAddressModalBlock() + { + return $this->blockFactory->create( + AddressModal::class, + ['element' => $this->browser->find($this->addressModalBlock, Locator::SELECTOR_XPATH)] + ); + } + + /** + * @return array + */ + public function getSelectedAddress() + { + return $this->_rootElement->find($this->selectedAddress, Locator::SELECTOR_CSS)->getText(); + } } diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.php new file mode 100644 index 0000000000000..b6db89fa03f3e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.php @@ -0,0 +1,86 @@ +_rootElement->find($this->saveButton)->click(); + } + + /** + * Get Error messages for attributes. + * + * @return array + */ + public function getErrorMessages() + { + $result = []; + + foreach ($this->_rootElement->getElements($this->errorField) as $item) { + $result[$item->find($this->fieldLabel)->getText()] = $item->find($this->errorMessage)->getText(); + } + + return $result; + } + + /** + * Fixture mapping. + * + * @param array|null $fields + * @param string|null $parent + * @return array + */ + protected function dataMapping(array $fields = null, $parent = null) + { + if (isset($fields['custom_attribute'])) { + $this->placeholders = ['attribute_code' => $fields['custom_attribute']['code']]; + $this->applyPlaceholders(); + } + + return parent::dataMapping($fields, $parent); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.xml b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.xml new file mode 100644 index 0000000000000..4a61606988393 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.xml @@ -0,0 +1,29 @@ + + + + + + + + + input[name="street[0]"] + + + + select + + + select + + + + + [name="custom_attributes[%attribute_code%]"] + + + diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/AddNewShippingAddressStep.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/AddNewShippingAddressStep.php new file mode 100644 index 0000000000000..e744ad3f1da1e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/AddNewShippingAddressStep.php @@ -0,0 +1,59 @@ +checkoutOnepage = $checkoutOnepage; + $this->address = $address; + } + + /** + * Create customer account. + * + * @return void + */ + public function run() + { + $shippingBlock = $this->checkoutOnepage->getShippingBlock(); + $shippingBlock->clickOnNewAddressButton(); + + if ($this->address) { + $shippingBlock->getAddressModalBlock()->fill($this->address); + } + + $shippingBlock->getAddressModalBlock()->save(); + } +} From c54b46f5e9bffad93d440d31eb1d5df3e6d9ac0f Mon Sep 17 00:00:00 2001 From: RomaKis Date: Thu, 24 Nov 2016 16:03:31 +0200 Subject: [PATCH 07/11] MAGETWO-60965: [Backport] - New attribute is not visible when create new address - for 2.0 --- .../Test/Page/CustomerAddressEdit.php | 51 +++++++++++++++++++ .../Test/Page/CustomerAddressEdit.xml | 12 ----- 2 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.php delete mode 100644 dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.xml diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.php new file mode 100644 index 0000000000000..42df533895124 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.php @@ -0,0 +1,51 @@ +url = $_ENV['app_frontend_url'] . self::MCA; + } + + /** + * Get Customer Address Edit form. + * + * @return \Magento\Customer\Test\Block\Address\Edit + */ + public function getEditForm() + { + return Factory::getBlockFactory()->getMagentoCustomerAddressEdit( + $this->browser->find($this->editForm, Locator::SELECTOR_CSS) + ); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.xml deleted file mode 100644 index 2f3738d05e5e3..0000000000000 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAddressEdit.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - From d7ebdef15e80b884fda51e44848d6e701221d36d Mon Sep 17 00:00:00 2001 From: RomaKis Date: Thu, 1 Dec 2016 15:15:58 +0200 Subject: [PATCH 08/11] MAGETWO-61628: [Backport] - Match products by rule in admin not working - for 2.0 --- .../Controller/Adminhtml/Category/Save.php | 12 ++++++ .../Model/Entity/Attribute/Source/Table.php | 41 ++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php index bfac72d9c66e6..340c1683c5db2 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Catalog\Controller\Adminhtml\Category; +use Magento\Store\Model\StoreManagerInterface; /** * Class Save @@ -25,6 +26,11 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category */ protected $layoutFactory; + /** + * @var StoreManagerInterface + */ + private $storeManager; + /** * Constructor * @@ -43,6 +49,10 @@ public function __construct( $this->resultRawFactory = $resultRawFactory; $this->resultJsonFactory = $resultJsonFactory; $this->layoutFactory = $layoutFactory; + + if ($this->storeManager == null){ + $this->storeManager = $this->_objectManager->get(StoreManagerInterface::class); + } } /** @@ -82,6 +92,8 @@ public function execute() } $storeId = $this->getRequest()->getParam('store'); + $store = $this->storeManager->getStore($storeId); + $this->storeManager->setCurrentStore($store->getCode()); $refreshTree = false; $data = $this->getRequest()->getPostValue(); if ($data) { diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php index d91f86a4781a2..d193bece49353 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php @@ -5,6 +5,9 @@ */ namespace Magento\Eav\Model\Entity\Attribute\Source; +use Magento\Framework\App\ObjectManager; +use Magento\Store\Model\StoreManagerInterface; + class Table extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource { /** @@ -24,6 +27,11 @@ class Table extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource */ protected $_attrOptionFactory; + /** + * @var StoreManagerInterface + */ + private $storeManager; + /** * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory @@ -47,24 +55,30 @@ public function __construct( public function getAllOptions($withEmpty = true, $defaultValues = false) { $storeId = $this->getAttribute()->getStoreId(); + if ($storeId === null) { + $storeId = $this->getStoreManager()->getStore()->getId(); + } if (!is_array($this->_options)) { $this->_options = []; } if (!is_array($this->_optionsDefault)) { $this->_optionsDefault = []; } - if (!isset($this->_options[$storeId])) { + $attributeId = $this->getAttribute()->getId(); + if (!isset($this->_options[$storeId][$attributeId])) { $collection = $this->_attrOptionCollectionFactory->create()->setPositionOrder( 'asc' )->setAttributeFilter( - $this->getAttribute()->getId() + $attributeId )->setStoreFilter( - $this->getAttribute()->getStoreId() + $storeId )->load(); - $this->_options[$storeId] = $collection->toOptionArray(); - $this->_optionsDefault[$storeId] = $collection->toOptionArray('default_value'); + $this->_options[$storeId][$attributeId] = $collection->toOptionArray(); + $this->_optionsDefault[$storeId][$attributeId] = $collection->toOptionArray('default_value'); } - $options = $defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId]; + $options = $defaultValues + ? $this->_optionsDefault[$storeId][$attributeId] + : $this->_options[$storeId][$attributeId]; if ($withEmpty) { $options = $this->addEmptyOption($options); } @@ -72,6 +86,21 @@ public function getAllOptions($withEmpty = true, $defaultValues = false) return $options; } + /** + * Get StoreManager dependency + * + * @return StoreManagerInterface + * @deprecated + */ + private function getStoreManager() + { + if ($this->storeManager === null) { + $this->storeManager = ObjectManager::getInstance()->get(StoreManagerInterface::class); + } + + return $this->storeManager; + } + /** * Retrieve Option values array by ids * From 10791537bb73a1d6532fb825df5333e78916970d Mon Sep 17 00:00:00 2001 From: RomaKis Date: Thu, 1 Dec 2016 16:22:55 +0200 Subject: [PATCH 09/11] MAGETWO-61628: [Backport] - Match products by rule in admin not working - for 2.0 --- .../Controller/Adminhtml/Category/Save.php | 27 +++++++++----- .../Adminhtml/Category/SaveTest.php | 37 +++++++++++++++++-- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php index 340c1683c5db2..01b5a1b7b70ec 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php @@ -49,10 +49,6 @@ public function __construct( $this->resultRawFactory = $resultRawFactory; $this->resultJsonFactory = $resultJsonFactory; $this->layoutFactory = $layoutFactory; - - if ($this->storeManager == null){ - $this->storeManager = $this->_objectManager->get(StoreManagerInterface::class); - } } /** @@ -92,8 +88,9 @@ public function execute() } $storeId = $this->getRequest()->getParam('store'); - $store = $this->storeManager->getStore($storeId); - $this->storeManager->setCurrentStore($store->getCode()); + $store = $this->getStoreManager()->getStore($storeId); + $this->getStoreManager()->setCurrentStore($store->getCode()); + $refreshTree = false; $data = $this->getRequest()->getPostValue(); if ($data) { @@ -102,9 +99,7 @@ public function execute() $parentId = $this->getRequest()->getParam('parent'); if (!$parentId) { if ($storeId) { - $parentId = $this->_objectManager->get( - 'Magento\Store\Model\StoreManagerInterface' - )->getStore( + $parentId = $this->getStoreManager()->getStore( $storeId )->getRootCategoryId(); } else { @@ -223,4 +218,18 @@ public function execute() $redirectParams ); } + + /** + * Get StoreManager object + * + * @return StoreManagerInterface + */ + private function getStoreManager() + { + if ($this->storeManager == null) { + $this->storeManager = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface'); + } + + return $this->storeManager; + } } diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php index a843138ac820b..c1fa0dcf427e2 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php @@ -326,7 +326,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) false, true, true, - ['getStore', 'getRootCategoryId'] + ['getStore', 'getRootCategoryId', 'setCurrentStore'] ); /** * @var \Magento\Framework\View\Layout @@ -364,6 +364,20 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) false ); + /** + * @var \Magento\Store\Model\Store + * |\PHPUnit_Framework_MockObject_MockObject $storeMock + */ + $storeMock = $this->getMock( + \Magento\Store\Model\Store::class, + [ + 'getCode', + ], + [], + '', + false + ); + $this->resultRedirectFactoryMock->expects($this->once()) ->method('create') ->will($this->returnValue($resultRedirectMock)); @@ -379,6 +393,15 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) ] ) ); + + $storeMock->expects($this->once()) + ->method('getCode') + ->will($this->returnValue('admin')); + + $storeManagerMock->expects($this->once()) + ->method('setCurrentStore') + ->with('admin'); + $this->objectManagerMock->expects($this->atLeastOnce()) ->method('create') ->will($this->returnValue($categoryMock)); @@ -441,15 +464,23 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) if (!$parentId) { if ($storeId) { - $storeManagerMock->expects($this->once()) + $storeManagerMock->expects($this->exactly(2)) ->method('getStore') ->with($storeId) - ->will($this->returnSelf()); + ->willReturnOnConsecutiveCalls( + $storeMock, + $this->returnSelf() + ); $storeManagerMock->expects($this->once()) ->method('getRootCategoryId') ->will($this->returnValue($rootCategoryId)); $parentId = $rootCategoryId; } + } else { + $storeManagerMock->expects($this->once()) + ->method('getStore') + ->with($storeId) + ->will($this->returnValue($storeMock)); } $categoryMock->expects($this->any()) ->method('load') From e1994e053847d2902d07dad5a639b5dd7036db7f Mon Sep 17 00:00:00 2001 From: RomaKis Date: Thu, 1 Dec 2016 16:58:49 +0200 Subject: [PATCH 10/11] MAGETWO-61628: [Backport] - Match products by rule in admin not working - for 2.0 --- .../Controller/Adminhtml/Category/Save.php | 3 +- .../Adminhtml/Category/SaveTest.php | 54 +++++++++---------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php index 01b5a1b7b70ec..13c8e31dea024 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Catalog\Controller\Adminhtml\Category; + use Magento\Store\Model\StoreManagerInterface; /** @@ -227,7 +228,7 @@ public function execute() private function getStoreManager() { if ($this->storeManager == null) { - $this->storeManager = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface'); + $this->storeManager = $this->_objectManager->get(StoreManagerInterface::class); } return $this->storeManager; diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php index c1fa0dcf427e2..8516afa307063 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php @@ -87,7 +87,7 @@ protected function setUp() $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->contextMock = $this->getMock( - 'Magento\Backend\App\Action\Context', + \Magento\Backend\App\Action\Context::class, [ 'getTitle', 'getRequest', @@ -102,35 +102,35 @@ protected function setUp() false ); $this->resultRedirectFactoryMock = $this->getMock( - 'Magento\Backend\Model\View\Result\RedirectFactory', + \Magento\Backend\Model\View\Result\RedirectFactory::class, ['create'], [], '', false ); $this->resultRawFactoryMock = $this->getMock( - 'Magento\Framework\Controller\Result\RawFactory', + \Magento\Framework\Controller\Result\RawFactory::class, [], [], '', false ); $this->resultJsonFactoryMock = $this->getMock( - 'Magento\Framework\Controller\Result\JsonFactory', + \Magento\Framework\Controller\Result\JsonFactory::class, ['create'], [], '', false ); $this->layoutFactoryMock = $this->getMock( - 'Magento\Framework\View\LayoutFactory', + \Magento\Framework\View\LayoutFactory::class, ['create'], [], '', false ); $this->requestMock = $this->getMockForAbstractClass( - 'Magento\Framework\App\RequestInterface', + \Magento\Framework\App\RequestInterface::class, [], '', false, @@ -138,11 +138,11 @@ protected function setUp() true, ['getParam', 'getPost', 'getPostValue'] ); - $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->eventManagerMock = $this->getMockForAbstractClass( - 'Magento\Framework\Event\ManagerInterface', + \Magento\Framework\Event\ManagerInterface::class, [], '', false, @@ -151,13 +151,13 @@ protected function setUp() ['dispatch'] ); $this->responseMock = $this->getMockForAbstractClass( - 'Magento\Framework\App\ResponseInterface', + \Magento\Framework\App\ResponseInterface::class, [], '', false ); $this->messageManagerMock = $this->getMockForAbstractClass( - 'Magento\Framework\Message\ManagerInterface', + \Magento\Framework\Message\ManagerInterface::class, [], '', false, @@ -177,7 +177,7 @@ protected function setUp() ->willReturn($this->resultRedirectFactoryMock); $this->save = $this->objectManager->getObject( - 'Magento\Catalog\Controller\Adminhtml\Category\Save', + \Magento\Catalog\Controller\Adminhtml\Category\Save::class, [ 'context' => $this->contextMock, 'resultRawFactory' => $this->resultRawFactoryMock, @@ -212,7 +212,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $resultRedirectMock */ $resultRedirectMock = $this->getMock( - 'Magento\Backend\Model\View\Result\Redirect', + \Magento\Backend\Model\View\Result\Redirect::class, [], [], '', @@ -223,7 +223,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $blockMock */ $blockMock = $this->getMock( - 'Magento\Framework\View\Element\Messages', + \Magento\Framework\View\Element\Messages::class, ['setMessages', 'getGroupedHtml'], [], '', @@ -234,7 +234,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $categoryMock */ $categoryMock = $this->getMock( - 'Magento\Catalog\Model\Category', + \Magento\Catalog\Model\Category::class, [ 'setStoreId', 'load', @@ -263,7 +263,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $parentCategoryMock */ $parentCategoryMock = $this->getMock( - 'Magento\Catalog\Model\Category', + \Magento\Catalog\Model\Category::class, [ 'setStoreId', 'load', @@ -287,7 +287,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $sessionMock */ $sessionMock = $this->getMock( - 'Magento\Backend\Model\Auth\Session', + \Magento\Backend\Model\Auth\Session::class, ['setActiveTabId'], [], '', @@ -298,7 +298,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $registryMock */ $registryMock = $this->getMock( - 'Magento\Framework\Registry', + \Magento\Framework\Registry::class, ['register'], [], '', @@ -309,7 +309,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $wysiwygConfigMock */ $wysiwygConfigMock = $this->getMock( - 'Magento\Cms\Model\Wysiwyg\Config', + \Magento\Cms\Model\Wysiwyg\Config::class, ['setStoreId'], [], '', @@ -320,7 +320,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $storeManagerMock */ $storeManagerMock = $this->getMockForAbstractClass( - 'Magento\Store\Model\StoreManagerInterface', + \Magento\Store\Model\StoreManagerInterface::class, [], '', false, @@ -333,7 +333,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $layoutMock */ $layoutMock = $this->getMockForAbstractClass( - 'Magento\Framework\View\Layout', + \Magento\Framework\View\Layout::class, [], '', false, @@ -346,7 +346,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $resultJsonMock */ $resultJsonMock = $this->getMock( - 'Magento\Cms\Model\Wysiwyg\Config', + \Magento\Cms\Model\Wysiwyg\Config::class, ['setData'], [], '', @@ -357,7 +357,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) * |\PHPUnit_Framework_MockObject_MockObject $messagesMock */ $messagesMock = $this->getMock( - 'Magento\Framework\Message\Collection', + \Magento\Framework\Message\Collection::class, [], [], '', @@ -410,10 +410,10 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) ->will( $this->returnValueMap( [ - ['Magento\Backend\Model\Auth\Session', $sessionMock], - ['Magento\Framework\Registry', $registryMock], - ['Magento\Cms\Model\Wysiwyg\Config', $wysiwygConfigMock], - ['Magento\Store\Model\StoreManagerInterface', $storeManagerMock], + [\Magento\Backend\Model\Auth\Session::class, $sessionMock], + [\Magento\Framework\Registry::class, $registryMock], + [\Magento\Cms\Model\Wysiwyg\Config::class, $wysiwygConfigMock], + [\Magento\Store\Model\StoreManagerInterface::class, $storeManagerMock], ] ) ); @@ -525,7 +525,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) ); $categoryResource = $this->getMock( - 'Magento\Catalog\Model\ResourceModel\Category', + \Magento\Catalog\Model\ResourceModel\Category::class, [], [], '', From dc97b7109003b568893ba8da503f370a14638040 Mon Sep 17 00:00:00 2001 From: Myroslav Dobra Date: Tue, 20 Dec 2016 16:23:52 +0200 Subject: [PATCH 11/11] MAGETWO-61628: [Backport] - Match products by rule in admin not working - for 2.0 --- .../Test/Unit/Controller/Adminhtml/Category/SaveTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php index 8516afa307063..4eb6dd6e5be62 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php @@ -365,8 +365,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId) ); /** - * @var \Magento\Store\Model\Store - * |\PHPUnit_Framework_MockObject_MockObject $storeMock + * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject $storeMock */ $storeMock = $this->getMock( \Magento\Store\Model\Store::class,