Skip to content

Commit df12845

Browse files
authored
Merge pull request #4302 from magento-mpi/PR-05-29-2019
[mpi] MAGETWO-99140: Naming product attributes as container_attributename and attributename and placing them one after another causes error
2 parents c9be08f + 11790f5 commit df12845

File tree

19 files changed

+940
-401
lines changed

19 files changed

+940
-401
lines changed

app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function generateRequest($attributeType, $container, $useFulltext)
103103
}
104104
}
105105
/** @var $attribute Attribute */
106-
if (!$attribute->getIsSearchable() || in_array($attribute->getAttributeCode(), ['price', 'sku'], true)) {
106+
if (!$attribute->getIsSearchable() || in_array($attribute->getAttributeCode(), ['price'], true)) {
107107
// Some fields have their own specific handlers
108108
continue;
109109
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGeneratorTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorResolver;
1010
use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorInterface;
1111

12+
/**
13+
* Test for \Magento\CatalogSearch\Model\Search\RequestGenerator
14+
*/
1215
class RequestGeneratorTest extends \PHPUnit\Framework\TestCase
1316
{
1417
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
@@ -61,7 +64,7 @@ public function attributesProvider()
6164
return [
6265
[
6366
[
64-
'quick_search_container' => ['queries' => 0, 'filters' => 0, 'aggregations' => 0],
67+
'quick_search_container' => ['queries' => 1, 'filters' => 0, 'aggregations' => 0],
6568
'advanced_search_container' => ['queries' => 0, 'filters' => 0, 'aggregations' => 0],
6669
'catalog_view_container' => ['queries' => 0, 'filters' => 0, 'aggregations' => 0]
6770
],

app/code/Magento/CatalogSearch/etc/search_request.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<queryReference clause="must" ref="visibility"/>
2020
</query>
2121
<query xsi:type="matchQuery" value="$search_term$" name="search">
22-
<match field="sku"/>
2322
<match field="*"/>
2423
</query>
2524
<query xsi:type="filteredQuery" name="category">

app/code/Magento/Customer/Model/CustomerAuthUpdate.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,74 @@
66

77
namespace Magento\Customer\Model;
88

9+
use Magento\Customer\Model\ResourceModel\Customer as CustomerResourceModel;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
913
/**
1014
* Customer Authentication update model.
1115
*/
1216
class CustomerAuthUpdate
1317
{
1418
/**
15-
* @var \Magento\Customer\Model\CustomerRegistry
19+
* @var CustomerRegistry
1620
*/
1721
protected $customerRegistry;
1822

1923
/**
20-
* @var \Magento\Customer\Model\ResourceModel\Customer
24+
* @var CustomerResourceModel
2125
*/
2226
protected $customerResourceModel;
2327

2428
/**
25-
* @param \Magento\Customer\Model\CustomerRegistry $customerRegistry
26-
* @param \Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
29+
* @var Customer
30+
*/
31+
private $customerModel;
32+
33+
/**
34+
* @param CustomerRegistry $customerRegistry
35+
* @param CustomerResourceModel $customerResourceModel
36+
* @param Customer|null $customerModel
2737
*/
2838
public function __construct(
29-
\Magento\Customer\Model\CustomerRegistry $customerRegistry,
30-
\Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
39+
CustomerRegistry $customerRegistry,
40+
CustomerResourceModel $customerResourceModel,
41+
Customer $customerModel = null
3142
) {
3243
$this->customerRegistry = $customerRegistry;
3344
$this->customerResourceModel = $customerResourceModel;
45+
$this->customerModel = $customerModel ?: ObjectManager::getInstance()->get(Customer::class);
3446
}
3547

3648
/**
3749
* Reset Authentication data for customer.
3850
*
3951
* @param int $customerId
4052
* @return $this
53+
* @throws NoSuchEntityException
4154
*/
4255
public function saveAuth($customerId)
4356
{
4457
$customerSecure = $this->customerRegistry->retrieveSecureData($customerId);
4558

59+
$this->customerResourceModel->load($this->customerModel, $customerId);
60+
$currentLockExpiresVal = $this->customerModel->getData('lock_expires');
61+
$newLockExpiresVal = $customerSecure->getData('lock_expires');
62+
4663
$this->customerResourceModel->getConnection()->update(
4764
$this->customerResourceModel->getTable('customer_entity'),
4865
[
4966
'failures_num' => $customerSecure->getData('failures_num'),
5067
'first_failure' => $customerSecure->getData('first_failure'),
51-
'lock_expires' => $customerSecure->getData('lock_expires'),
68+
'lock_expires' => $newLockExpiresVal,
5269
],
5370
$this->customerResourceModel->getConnection()->quoteInto('entity_id = ?', $customerId)
5471
);
5572

73+
if ($currentLockExpiresVal !== $newLockExpiresVal) {
74+
$this->customerModel->reindex();
75+
}
76+
5677
return $this;
5778
}
5879
}

app/code/Magento/Customer/Test/Unit/Model/CustomerAuthUpdateTest.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
*/
66
namespace Magento\Customer\Test\Unit\Model;
77

8+
use Magento\Customer\Model\Customer as CustomerModel;
89
use Magento\Customer\Model\CustomerAuthUpdate;
10+
use Magento\Customer\Model\CustomerRegistry;
11+
use Magento\Customer\Model\Data\CustomerSecure;
12+
use Magento\Customer\Model\ResourceModel\Customer as CustomerResourceModel;
13+
use Magento\Framework\DB\Adapter\AdapterInterface;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
916

1017
/**
1118
* Class CustomerAuthUpdateTest
@@ -18,17 +25,22 @@ class CustomerAuthUpdateTest extends \PHPUnit\Framework\TestCase
1825
protected $model;
1926

2027
/**
21-
* @var \Magento\Customer\Model\CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
28+
* @var CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
2229
*/
2330
protected $customerRegistry;
2431

2532
/**
26-
* @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject
33+
* @var CustomerResourceModel|\PHPUnit_Framework_MockObject_MockObject
2734
*/
2835
protected $customerResourceModel;
2936

3037
/**
31-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
38+
* @var CustomerModel|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
protected $customerModel;
41+
42+
/**
43+
* @var ObjectManager
3244
*/
3345
protected $objectManager;
3446

@@ -37,32 +49,36 @@ class CustomerAuthUpdateTest extends \PHPUnit\Framework\TestCase
3749
*/
3850
protected function setUp()
3951
{
40-
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
52+
$this->objectManager = new ObjectManager($this);
4153

4254
$this->customerRegistry =
43-
$this->createMock(\Magento\Customer\Model\CustomerRegistry::class);
55+
$this->createMock(CustomerRegistry::class);
4456
$this->customerResourceModel =
45-
$this->createMock(\Magento\Customer\Model\ResourceModel\Customer::class);
57+
$this->createMock(CustomerResourceModel::class);
58+
$this->customerModel =
59+
$this->createMock(CustomerModel::class);
4660

4761
$this->model = $this->objectManager->getObject(
48-
\Magento\Customer\Model\CustomerAuthUpdate::class,
62+
CustomerAuthUpdate::class,
4963
[
5064
'customerRegistry' => $this->customerRegistry,
5165
'customerResourceModel' => $this->customerResourceModel,
66+
'customerModel' => $this->customerModel
5267
]
5368
);
5469
}
5570

5671
/**
5772
* test SaveAuth
73+
* @throws NoSuchEntityException
5874
*/
5975
public function testSaveAuth()
6076
{
6177
$customerId = 1;
6278

63-
$customerSecureMock = $this->createMock(\Magento\Customer\Model\Data\CustomerSecure::class);
79+
$customerSecureMock = $this->createMock(CustomerSecure::class);
6480

65-
$dbAdapter = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
81+
$dbAdapter = $this->createMock(AdapterInterface::class);
6682

6783
$this->customerRegistry->expects($this->once())
6884
->method('retrieveSecureData')
@@ -98,6 +114,9 @@ public function testSaveAuth()
98114
$customerId
99115
);
100116

117+
$this->customerModel->expects($this->once())
118+
->method('reindex');
119+
101120
$this->model->saveAuth($customerId);
102121
}
103122
}

app/code/Magento/Eav/Model/Validator/Attribute/Code.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Eav\Model\Validator\Attribute;
99

10+
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
1011
use Magento\Eav\Model\Entity\Attribute;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Validator\AbstractValidator;
@@ -65,6 +66,16 @@ public function isValid($attributeCode): bool
6566
);
6667
}
6768

69+
/**
70+
* Check attribute_code for prohibited prefix
71+
*/
72+
if (strpos($attributeCode, AbstractModifier::CONTAINER_PREFIX) === 0) {
73+
$errorMessages[] = __(
74+
'"%1" prefix is reserved by the system and cannot be used in attribute code names.',
75+
AbstractModifier::CONTAINER_PREFIX
76+
);
77+
}
78+
6879
$this->_addMessages($errorMessages);
6980

7081
return !$this->hasMessages();

app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/CodeTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public function isValidDataProvider(): array
6161
], [
6262
'more_than_60_chars_more_than_60_chars_more_than_60_chars_more',
6363
false
64-
]
64+
], [
65+
'container_attribute',
66+
false,
67+
],
6568
];
6669
}
6770
}

app/code/Magento/Paypal/Model/Cart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/**
1111
* PayPal-specific model for shopping cart items and totals
12+
*
1213
* The main idea is to accommodate all possible totals into PayPal-compatible 4 totals and line items
1314
*/
1415
class Cart extends \Magento\Payment\Model\Cart
@@ -179,7 +180,7 @@ protected function _applyDiscountTaxCompensationWorkaround(
179180
) {
180181
$dataContainer = $salesEntity->getTaxContainer();
181182
$this->addTax((double)$dataContainer->getBaseDiscountTaxCompensationAmount());
182-
$this->addTax((double)$dataContainer->getBaseShippingDiscountTaxCompensationAmount());
183+
$this->addTax((double)$dataContainer->getBaseShippingDiscountTaxCompensationAmnt());
183184
}
184185

185186
/**

app/code/Magento/Paypal/Model/Payflow/Transparent.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Paypal\Model\Payflow;
89

@@ -59,6 +60,11 @@ class Transparent extends Payflowpro implements TransparentInterface
5960
*/
6061
private $paymentExtensionFactory;
6162

63+
/**
64+
* @var \Magento\Paypal\Model\CartFactory
65+
*/
66+
private $payPalCartFactory;
67+
6268
/**
6369
* @param \Magento\Framework\Model\Context $context
6470
* @param \Magento\Framework\Registry $registry
@@ -76,6 +82,7 @@ class Transparent extends Payflowpro implements TransparentInterface
7682
* @param ResponseValidator $responseValidator
7783
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
7884
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
85+
* @param \Magento\Paypal\Model\CartFactory $payPalCartFactory
7986
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
8087
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
8188
* @param array $data
@@ -98,6 +105,7 @@ public function __construct(
98105
ResponseValidator $responseValidator,
99106
PaymentTokenInterfaceFactory $paymentTokenFactory,
100107
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
108+
\Magento\Paypal\Model\CartFactory $payPalCartFactory,
101109
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
102110
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
103111
array $data = []
@@ -123,9 +131,12 @@ public function __construct(
123131
$this->responseValidator = $responseValidator;
124132
$this->paymentTokenFactory = $paymentTokenFactory;
125133
$this->paymentExtensionFactory = $paymentExtensionFactory;
134+
$this->payPalCartFactory = $payPalCartFactory;
126135
}
127136

128137
/**
138+
* Gets response validator instance.
139+
*
129140
* @return ResponseValidator
130141
*/
131142
public function getResponceValidator()
@@ -162,13 +173,19 @@ public function authorize(InfoInterface $payment, $amount)
162173
$this->addRequestOrderInfo($request, $order);
163174
$request = $this->fillCustomerContacts($order, $request);
164175

176+
/** @var \Magento\Paypal\Model\Cart $payPalCart */
177+
$payPalCart = $this->payPalCartFactory->create(['salesModel' => $order]);
178+
$payPalCart->getAmounts();
179+
165180
$token = $payment->getAdditionalInformation(self::PNREF);
166181
$request->setData('trxtype', self::TRXTYPE_AUTH_ONLY);
167182
$request->setData('origid', $token);
168183
$request->setData('amt', $this->formatPrice($amount));
169184
$request->setData('currency', $order->getBaseCurrencyCode());
170-
$request->setData('taxamt', $this->formatPrice($order->getBaseTaxAmount()));
171-
$request->setData('freightamt', $this->formatPrice($order->getBaseShippingAmount()));
185+
$request->setData('itemamt', $this->formatPrice($payPalCart->getSubtotal()));
186+
$request->setData('taxamt', $this->formatPrice($payPalCart->getTax()));
187+
$request->setData('freightamt', $this->formatPrice($payPalCart->getShipping()));
188+
$request->setData('discount', $this->formatPrice($payPalCart->getDiscount()));
172189

173190
$response = $this->postRequest($request, $this->getConfig());
174191
$this->processErrors($response);
@@ -178,6 +195,7 @@ public function authorize(InfoInterface $payment, $amount)
178195
} catch (LocalizedException $exception) {
179196
$payment->setParentTransactionId($response->getData(self::PNREF));
180197
$this->void($payment);
198+
// phpcs:ignore Magento2.Exceptions.ThrowCatch
181199
throw new LocalizedException(__("The payment couldn't be processed at this time. Please try again later."));
182200
}
183201

@@ -200,10 +218,12 @@ public function getConfigInterface()
200218
}
201219

202220
/**
221+
* Creates vault payment token.
222+
*
203223
* @param Payment $payment
204224
* @param string $token
205-
* @throws LocalizedException
206225
* @return void
226+
* @throws \Exception
207227
*/
208228
protected function createPaymentToken(Payment $payment, $token)
209229
{
@@ -222,8 +242,11 @@ protected function createPaymentToken(Payment $payment, $token)
222242
}
223243

224244
/**
245+
* Generates CC expiration date by year and month provided in payment.
246+
*
225247
* @param Payment $payment
226248
* @return string
249+
* @throws \Exception
227250
*/
228251
private function getExpirationDate(Payment $payment)
229252
{
@@ -242,6 +265,8 @@ private function getExpirationDate(Payment $payment)
242265
}
243266

244267
/**
268+
* Returns payment extension attributes instance.
269+
*
245270
* @param Payment $payment
246271
* @return \Magento\Sales\Api\Data\OrderPaymentExtensionInterface
247272
*/

0 commit comments

Comments
 (0)