diff --git a/app/code/Magento/CatalogUrlRewrite/Model/WebapiProductUrlPathGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/WebapiProductUrlPathGenerator.php new file mode 100644 index 0000000000000..487943c2305b4 --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/Model/WebapiProductUrlPathGenerator.php @@ -0,0 +1,73 @@ +collectionFactory = $collectionFactory; + } + + /** + * @inheritdoc + */ + protected function prepareProductUrlKey(\Magento\Catalog\Model\Product $product) + { + $urlKey = $product->getUrlKey(); + if ($urlKey === '' || $urlKey === null) { + $urlKey = $this->prepareUrlKey($product->formatUrlKey($product->getName())); + } + + return $product->formatUrlKey($urlKey); + } + + /** + * Crete url key if it does not exist yet. + * + * @param string $urlKey + * @return string + */ + private function prepareUrlKey(string $urlKey) : string + { + /** @var ProductCollection $collection */ + $collection = $this->collectionFactory->create(); + $collection->addFieldToFilter('url_key', ['like' => $urlKey]); + if ($collection->getSize() !== 0) { + $urlKey = $urlKey . '-1'; + $urlKey = $this->prepareUrlKey($urlKey); + } + + return $urlKey; + } +} diff --git a/app/code/Magento/CatalogUrlRewrite/etc/webapi_rest/di.xml b/app/code/Magento/CatalogUrlRewrite/etc/webapi_rest/di.xml new file mode 100644 index 0000000000000..ac8beb362f0fb --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/etc/webapi_rest/di.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/app/code/Magento/CatalogUrlRewrite/etc/webapi_soap/di.xml b/app/code/Magento/CatalogUrlRewrite/etc/webapi_soap/di.xml new file mode 100644 index 0000000000000..ac8beb362f0fb --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/etc/webapi_soap/di.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/app/code/Magento/Checkout/Test/Mftf/ActionGroup/CheckoutActionGroup.xml b/app/code/Magento/Checkout/Test/Mftf/ActionGroup/CheckoutActionGroup.xml index 21f3c675eba87..13f7c00deaced 100644 --- a/app/code/Magento/Checkout/Test/Mftf/ActionGroup/CheckoutActionGroup.xml +++ b/app/code/Magento/Checkout/Test/Mftf/ActionGroup/CheckoutActionGroup.xml @@ -11,7 +11,6 @@ - diff --git a/app/code/Magento/Customer/Test/Mftf/Data/RegionData.xml b/app/code/Magento/Customer/Test/Mftf/Data/RegionData.xml index 99741a357109e..9f31e5994eaae 100644 --- a/app/code/Magento/Customer/Test/Mftf/Data/RegionData.xml +++ b/app/code/Magento/Customer/Test/Mftf/Data/RegionData.xml @@ -15,7 +15,7 @@ Texas TX - 1 + 57 California diff --git a/app/code/Magento/Paypal/Model/Api/PayflowNvp.php b/app/code/Magento/Paypal/Model/Api/PayflowNvp.php index 6373c6d99fb16..861d3ebcc9bc2 100644 --- a/app/code/Magento/Paypal/Model/Api/PayflowNvp.php +++ b/app/code/Magento/Paypal/Model/Api/PayflowNvp.php @@ -136,6 +136,9 @@ class PayflowNvp extends \Magento\Paypal\Model\Api\Nvp 'CVV2MATCH' => 'cvv2_check_result', 'USERSELECTEDFUNDINGSOURCE' => 'funding_source', + + 'NOSHIPPING' => 'suppress_shipping', + 'REQBILLINGADDRESS' => 'require_billing_address', ]; /** @@ -248,6 +251,8 @@ class PayflowNvp extends \Magento\Paypal\Model\Api\Nvp 'PAYFLOWCOLOR', 'LOCALECODE', 'USERSELECTEDFUNDINGSOURCE', + 'NOSHIPPING', + 'REQBILLINGADDRESS', ]; /** diff --git a/app/code/Magento/Weee/Plugin/Catalog/Controller/Adminhtml/Product/Initialization/Helper/ProcessTaxAttribute.php b/app/code/Magento/Weee/Plugin/Catalog/Controller/Adminhtml/Product/Initialization/Helper/ProcessTaxAttribute.php new file mode 100644 index 0000000000000..011a1b3f9766b --- /dev/null +++ b/app/code/Magento/Weee/Plugin/Catalog/Controller/Adminhtml/Product/Initialization/Helper/ProcessTaxAttribute.php @@ -0,0 +1,56 @@ +request = $request; + } + + /** + * @param Helper $subject + * @param Product $result + * @param Product $product + * @param array $productData + * @return Product + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterInitializeFromData( + Helper $subject, + Product $result, + Product $product, + array $productData + ): Product { + $attributes = $result->getAttributes(); + if (!empty($attributes)) { + foreach ($attributes as $attribute) { + if ($attribute->getFrontendInput() == 'weee' && !isset($productData[$attribute->getAttributeCode()])) { + $result->setData($attribute->getAttributeCode(), []); + } + } + } + + return $result; + } +} diff --git a/app/code/Magento/Weee/Test/Mftf/Section/AdminProductAddFPTValueSection.xml b/app/code/Magento/Weee/Test/Mftf/Section/AdminProductAddFPTValueSection.xml index 40a9a97f31425..c38d2e1945e80 100644 --- a/app/code/Magento/Weee/Test/Mftf/Section/AdminProductAddFPTValueSection.xml +++ b/app/code/Magento/Weee/Test/Mftf/Section/AdminProductAddFPTValueSection.xml @@ -10,6 +10,7 @@ xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
+ diff --git a/app/code/Magento/Weee/Test/Mftf/Test/AdminRemoveProductWeeeAttributeOptionTest.xml b/app/code/Magento/Weee/Test/Mftf/Test/AdminRemoveProductWeeeAttributeOptionTest.xml new file mode 100644 index 0000000000000..6c7d4d3d0a83f --- /dev/null +++ b/app/code/Magento/Weee/Test/Mftf/Test/AdminRemoveProductWeeeAttributeOptionTest.xml @@ -0,0 +1,61 @@ + + + + + + + + <description value="Weee attribute options can be removed in product page"/> + <severity value="CRITICAL"/> + <testCaseId value="MAGETWO-94817"/> + <group value="weee"/> + </annotations> + <before> + <createData entity="productFPTAttribute" stepKey="createProductFPTAttribute"/> + <createData entity="AddToDefaultSet" stepKey="addFPTToAttributeSet"> + <requiredEntity createDataKey="createProductFPTAttribute"/> + </createData> + <createData entity="SimpleOne" stepKey="createSimpleProduct"/> + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/> + <actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProductInitial"> + <argument name="product" value="$$createSimpleProduct$$"/> + </actionGroup> + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProductInitial"> + <argument name="product" value="$$createSimpleProduct$$"/> + </actionGroup> + <actionGroup ref="AdminProductAddFPTValueActionGroup" stepKey="addWeeeAttributeValue"> + <argument name="FPTAttributeCode" value="$$createProductFPTAttribute.attribute_code$$"/> + <argument name="stateForFPT" value="California"/> + <argument name="valueForFPT" value="10"/> + </actionGroup> + <actionGroup ref="SaveProductOnProductPageOnAdmin" stepKey="saveProductInitial"/> + </before> + <after> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductListing"/> + <waitForPageLoad stepKey="waitForProductListingPageLoad"/> + <actionGroup ref="AdminResetProductGridToDefaultViewActionGroup" stepKey="resetGridToDefaultKeywordSearch"/> + <actionGroup ref="logout" stepKey="logout"/> + <deleteData createDataKey="createProductFPTAttribute" stepKey="deleteProductFPTAttribute"/> + <deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/> + </after> + <!-- Test Steps --> + <!-- Step 1: Open created product edit page --> + <actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProduct"> + <argument name="product" value="$$createSimpleProduct$$"/> + </actionGroup> + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct"> + <argument name="product" value="$$createSimpleProduct$$"/> + </actionGroup> + <!-- Step 2: Remove weee attribute options --> + <click selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="removeAttributeOption"/> + <actionGroup ref="SaveProductOnProductPageOnAdmin" stepKey="saveProduct"/> + <!-- Assert weee attribute options are empty --> + <dontSeeElement selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="dontSeeOptions"/> + </test> +</tests> diff --git a/app/code/Magento/Weee/Ui/DataProvider/Product/Form/Modifier/Weee.php b/app/code/Magento/Weee/Ui/DataProvider/Product/Form/Modifier/Weee.php index c96a7a0200334..87dea65a41dcf 100644 --- a/app/code/Magento/Weee/Ui/DataProvider/Product/Form/Modifier/Weee.php +++ b/app/code/Magento/Weee/Ui/DataProvider/Product/Form/Modifier/Weee.php @@ -180,6 +180,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig) 'component' => 'Magento_Weee/js/fpt-group', 'visible' => true, 'label' => __('Country/State'), + 'showLabel' => false, ], ], ], @@ -197,6 +198,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig) 'validation' => [ 'required-entry' => true, ], + 'showLabel' => false, ], ], ], @@ -216,6 +218,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig) ], 'caption' => '*', 'visible' => true, + 'showLabel' => false, ], ], ], @@ -233,6 +236,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig) 'validation' => [ 'validate-fpt-group' => true ], + 'showLabel' => false, ], ], ], @@ -252,6 +256,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig) 'validation' => [ 'required-entry' => true ], + 'showLabel' => false, ], ], ], @@ -267,6 +272,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig) 'label' => __('Website'), 'visible' => $this->websiteManager->isMultiWebsites(), 'options' => $this->websiteManager->getWebsites($product, $eavAttribute), + 'showLabel' => false, ], ], ], diff --git a/app/code/Magento/Weee/etc/di.xml b/app/code/Magento/Weee/etc/di.xml index e52aebd3af8b5..8b433163cad22 100644 --- a/app/code/Magento/Weee/etc/di.xml +++ b/app/code/Magento/Weee/etc/di.xml @@ -78,4 +78,7 @@ </argument> </arguments> </type> + <type name="Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper"> + <plugin name="weeeAttributeOptionsProcess" type="Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProcessTaxAttribute"/> + </type> </config> diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php index 3eccede920b4a..880af262125d0 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php @@ -181,6 +181,62 @@ private function loadWebsiteByCode(string $websiteCode): Website return $website; } + /** + * Test for check that 2 same product create and url_key save. + * + * @return void + */ + public function testSaveTwoSameProduct() + { + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Save', + ], + ]; + + $product1 = [ + 'product' => [ + 'attribute_set_id' => 4, + 'name' => "Test API 1", + 'price' => 254.13, + 'sku' => '1234', + ] + ]; + $product2 = [ + 'product' => [ + 'attribute_set_id' => 4, + 'name' => "Test API 1", + 'price' => 254.13, + 'sku' => '1235', + ] + ]; + + $product1 = $this->_webApiCall($serviceInfo, $product1); + $response = $this->_webApiCall($serviceInfo, $product2); + + $index = null; + foreach ($response['custom_attributes'] as $key => $customAttribute) { + if ($customAttribute['attribute_code'] == 'url_key') { + $index = $key; + break; + } + } + + $this->assertArrayHasKey(ProductInterface::SKU, $response); + + $expectedResult = $product1['custom_attributes'][$index]['value'] . '-1'; + $this->assertEquals($expectedResult, $response['custom_attributes'][$index]['value']); + + $this->deleteProduct('1234'); + $this->deleteProduct('1235'); + } + /** * Test removing association between product and website 1 * @magentoApiDataFixture Magento/Catalog/_files/product_with_two_websites.php