Skip to content

Commit

Permalink
Merge pull request #3254 from magento-tsg/2.2-develop-pr48
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.2 (pr48) (2.2.8)
  • Loading branch information
Alexander Akimov authored Oct 4, 2018
2 parents 3489e1b + 0d1551e commit 98ee213
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Model;

use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;

/**
* Class for creating product url through web-api.
*/
class WebapiProductUrlPathGenerator extends ProductUrlPathGenerator
{
/**
* @var CollectionFactory
*/
private $collectionFactory;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param CollectionFactory $collectionFactory
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
CollectionFactory $collectionFactory
) {
parent::__construct($storeManager, $scopeConfig, $categoryUrlPathGenerator, $productRepository);
$this->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;
}
}
10 changes: 10 additions & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Magento\CatalogUrlRewrite\Model\WebapiProductUrlPathGenerator"/>
</config>
10 changes: 10 additions & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/webapi_soap/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Magento\CatalogUrlRewrite\Model\WebapiProductUrlPathGenerator"/>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<!-- Checkout select Check/Money Order payment -->
<actionGroup name="CheckoutSelectCheckMoneyOrderPaymentActionGroup">
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30" stepKey="waitForPaymentSectionLoaded"/>
<waitForElementVisible selector="{{CheckoutPaymentSection.billingAddress}}" time="30" stepKey="waitForBillingAddressDetailsAppears"/>
<conditionalClick selector="{{CheckoutPaymentSection.checkMoneyOrderPayment}}" dependentSelector="{{CheckoutPaymentSection.checkMoneyOrderPayment}}" visible="true" stepKey="clickCheckMoneyOrderPayment"/>
</actionGroup>

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Test/Mftf/Data/RegionData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<entity name="RegionTX" type="region">
<data key="region">Texas</data>
<data key="region_code">TX</data>
<data key="region_id">1</data>
<data key="region_id">57</data>
</entity>
<entity name="RegionCA" type="region">
<data key="region">California</data>
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Paypal/Model/Api/PayflowNvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

/**
Expand Down Expand Up @@ -248,6 +251,8 @@ class PayflowNvp extends \Magento\Paypal\Model\Api\Nvp
'PAYFLOWCOLOR',
'LOCALECODE',
'USERSELECTEDFUNDINGSOURCE',
'NOSHIPPING',
'REQBILLINGADDRESS',
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper;
use Magento\Framework\App\RequestInterface;

/**
* Handles product tax attributes data initialization.
*/
class ProcessTaxAttribute
{
/**
* @var RequestInterface
*/
private $request;

/**
* @param RequestInterface $request
*/
public function __construct(RequestInterface $request)
{
$this->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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
<section name="AdminProductAddFPTValueSection">
<element name="addFPT" type="button" selector="[data-index='{{FPTAttributeCode}}'] [data-action='add_new_row']" parameterized="true"/>
<element name="removeRowByIndex" type="button" selector="[data-index='{{FPTAttributeCode}}'] [data-action='remove_row']:nth-of-type({{rowIndex}})" parameterized="true"/>
<element name="selectCountryForFPT" type="select" selector="(//select[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[country]')])[last()]" parameterized="true"/>
<element name="selectStateForFPT" type="select" selector="(//select[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[state]')])[last()]" parameterized="true"/>
<element name="setTaxValueForFPT" type="text" selector="(//input[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[value]')])[last()]" parameterized="true"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
<test name="AdminRemoveProductWeeeAttributeOptionTest">
<annotations>
<features value="Weee attribute options can be removed in product page"/>
<title value="Weee attribute options can be removed in product page"/>
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'component' => 'Magento_Weee/js/fpt-group',
'visible' => true,
'label' => __('Country/State'),
'showLabel' => false,
],
],
],
Expand All @@ -197,6 +198,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'validation' => [
'required-entry' => true,
],
'showLabel' => false,
],
],
],
Expand All @@ -216,6 +218,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
],
'caption' => '*',
'visible' => true,
'showLabel' => false,
],
],
],
Expand All @@ -233,6 +236,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'validation' => [
'validate-fpt-group' => true
],
'showLabel' => false,
],
],
],
Expand All @@ -252,6 +256,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'validation' => [
'required-entry' => true
],
'showLabel' => false,
],
],
],
Expand All @@ -267,6 +272,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'label' => __('Website'),
'visible' => $this->websiteManager->isMultiWebsites(),
'options' => $this->websiteManager->getWebsites($product, $eavAttribute),
'showLabel' => false,
],
],
],
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Weee/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98ee213

Please sign in to comment.