Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 191fb72

Browse files
author
Oleksandr Gorkun
committed
Merge branch '2.2-develop' of https://github.com/magento-qwerty/magento2ce into MAGETWO-71549
2 parents 2d2abca + 7ca7002 commit 191fb72

File tree

39 files changed

+937
-179
lines changed

39 files changed

+937
-179
lines changed

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ define([
6161
},
6262

6363
/**
64-
* @returns {Bool}
64+
* @returns {Boolean}
6565
*/
6666
isVaultEnabled: function () {
6767
return this.vaultEnabler.isVaultEnabled();
@@ -144,10 +144,19 @@ define([
144144
},
145145

146146
/**
147-
* Trigger order placing
147+
* Returns state of place order button
148+
* @returns {Boolean}
149+
*/
150+
isButtonActive: function () {
151+
return this.isActive() && this.isPlaceOrderActionAllowed();
152+
},
153+
154+
/**
155+
* Triggers order placing
148156
*/
149157
placeOrderClick: function () {
150158
if (this.validateCardType()) {
159+
this.isPlaceOrderActionAllowed(false);
151160
$(this.getSelector('submit')).trigger('click');
152161
}
153162
},

app/code/Magento/Braintree/view/frontend/web/template/payment/form.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@
141141
data-bind="
142142
click: placeOrderClick,
143143
attr: {title: $t('Place Order')},
144-
css: {disabled: !isPlaceOrderActionAllowed()},
145-
enable: isActive()
144+
enable: isButtonActive()
146145
"
147146
disabled>
148147
<span data-bind="i18n: 'Place Order'"></span>

app/code/Magento/Catalog/Cron/DeleteOutdatedPriceValues.php

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/**
1515
* Cron operation is responsible for deleting all product prices on WEBSITE level
16-
* in case 'Catalog Price Scope' configuratoin parameter is set to GLOBAL.
16+
* in case 'Catalog Price Scope' configuration parameter is set to GLOBAL.
1717
*/
1818
class DeleteOutdatedPriceValues
1919
{
@@ -48,27 +48,46 @@ public function __construct(
4848
}
4949

5050
/**
51-
* Delete all price values for non-admin stores if PRICE_SCOPE is global
51+
* Delete all price values for non-admin stores if PRICE_SCOPE is set to global.
5252
*
5353
* @return void
5454
*/
5555
public function execute()
5656
{
57-
$priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE);
58-
if ($priceScope == Store::PRICE_SCOPE_GLOBAL) {
59-
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $priceAttribute */
60-
$priceAttribute = $this->attributeRepository
61-
->get(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE);
62-
$connection = $this->resource->getConnection();
63-
$conditions = [
64-
$connection->quoteInto('attribute_id = ?', $priceAttribute->getId()),
65-
$connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID),
66-
];
57+
if ($this->isPriceScopeSetToGlobal() === false) {
58+
return;
59+
}
60+
61+
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $priceAttribute */
62+
$priceAttribute = $this->attributeRepository
63+
->get(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE);
64+
$connection = $this->resource->getConnection();
65+
$conditions = [
66+
$connection->quoteInto('attribute_id = ?', $priceAttribute->getId()),
67+
$connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID),
68+
];
6769

68-
$connection->delete(
69-
$priceAttribute->getBackend()->getTable(),
70-
$conditions
71-
);
70+
$connection->delete(
71+
$priceAttribute->getBackend()->getTable(),
72+
$conditions
73+
);
74+
}
75+
76+
/**
77+
* Checks if price scope config option explicitly equal to global value.
78+
*
79+
* Such strict comparision is required to prevent price deleting when
80+
* price scope config option is null for some reason.
81+
*
82+
* @return bool
83+
*/
84+
private function isPriceScopeSetToGlobal()
85+
{
86+
$priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE);
87+
if ($priceScope === null) {
88+
return false;
7289
}
90+
91+
return (int)$priceScope === Store::PRICE_SCOPE_GLOBAL;
7392
}
7493
}

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
6161
/**
6262
* @var string|null
6363
*/
64-
private $order = null;
64+
private $relevanceOrderDirection = null;
6565

6666
/**
6767
* @var string
@@ -361,9 +361,19 @@ protected function _renderFiltersBefore()
361361
[]
362362
);
363363

364-
if ($this->order && 'relevance' === $this->order['field']) {
365-
$this->getSelect()->order('search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
364+
if ($this->relevanceOrderDirection) {
365+
$this->getSelect()->order(
366+
'search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->relevanceOrderDirection
367+
);
366368
}
369+
370+
/*
371+
* This order is required to force search results be the same
372+
* for the same requests and products with the same relevance
373+
* NOTE: this does not replace existing orders but ADDs one more
374+
*/
375+
$this->setOrder('entity_id');
376+
367377
return parent::_renderFiltersBefore();
368378
}
369379

@@ -385,10 +395,12 @@ protected function _renderFilters()
385395
*/
386396
public function setOrder($attribute, $dir = Select::SQL_DESC)
387397
{
388-
$this->order = ['field' => $attribute, 'dir' => $dir];
389-
if ($attribute !== 'relevance') {
398+
if ($attribute === 'relevance') {
399+
$this->relevanceOrderDirection = $dir;
400+
} else {
390401
parent::setOrder($attribute, $dir);
391402
}
403+
392404
return $this;
393405
}
394406

app/code/Magento/ConfigurableProduct/Model/Product/SaveHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ public function execute($entity, $arguments = [])
6666
$this->saveConfigurableProductAttributes($entity, $configurableOptions);
6767
}
6868

69-
$configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks();
70-
$this->resourceModel->saveProducts($entity, $configurableLinks);
69+
$configurableLinks = $extensionAttributes->getConfigurableProductLinks();
70+
if ($configurableLinks !== null) {
71+
$configurableLinks = (array)$configurableLinks;
72+
$this->resourceModel->saveProducts($entity, $configurableLinks);
73+
}
7174

7275
return $entity;
7376
}

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,17 @@ public function getHtmlId()
208208
*/
209209
public function getHtmlExtraParams()
210210
{
211-
$extraParams = [
212-
"'validate-date-au':true"
213-
];
211+
$validators = [];
214212

215213
if ($this->isRequired()) {
216-
$extraParams[] = 'required:true';
214+
$validators['required'] = true;
217215
}
218216

219-
$extraParams = implode(', ', $extraParams);
217+
$validators['validate-date'] = [
218+
'dateFormat' => $this->getDateFormat()
219+
];
220220

221-
return 'data-validate="{' . $extraParams . '}"';
221+
return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';
222222
}
223223

224224
/**

app/code/Magento/Customer/Helper/Address.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Magento\Customer\Api\AddressMetadataInterface;
99
use Magento\Customer\Api\CustomerMetadataInterface;
1010
use Magento\Customer\Api\Data\AttributeMetadataInterface;
11+
use Magento\Customer\Model\Metadata\AttributeResolver;
1112
use Magento\Directory\Model\Country\Format;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\Exception\NoSuchEntityException;
1315

1416
/**
@@ -93,27 +95,35 @@ class Address extends \Magento\Framework\App\Helper\AbstractHelper
9395
*/
9496
protected $_addressConfig;
9597

98+
/**
99+
* @var AttributeResolver
100+
*/
101+
private $attributeResolver;
102+
96103
/**
97104
* @param \Magento\Framework\App\Helper\Context $context
98105
* @param \Magento\Framework\View\Element\BlockFactory $blockFactory
99106
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
100107
* @param CustomerMetadataInterface $customerMetadataService
101108
* @param AddressMetadataInterface $addressMetadataService
102109
* @param \Magento\Customer\Model\Address\Config $addressConfig
110+
* @param AttributeResolver|null $attributeResolver
103111
*/
104112
public function __construct(
105113
\Magento\Framework\App\Helper\Context $context,
106114
\Magento\Framework\View\Element\BlockFactory $blockFactory,
107115
\Magento\Store\Model\StoreManagerInterface $storeManager,
108116
CustomerMetadataInterface $customerMetadataService,
109117
AddressMetadataInterface $addressMetadataService,
110-
\Magento\Customer\Model\Address\Config $addressConfig
118+
\Magento\Customer\Model\Address\Config $addressConfig,
119+
AttributeResolver $attributeResolver = null
111120
) {
112121
$this->_blockFactory = $blockFactory;
113122
$this->_storeManager = $storeManager;
114123
$this->_customerMetadataService = $customerMetadataService;
115124
$this->_addressMetadataService = $addressMetadataService;
116125
$this->_addressConfig = $addressConfig;
126+
$this->attributeResolver = $attributeResolver ?: ObjectManager::getInstance()->get(AttributeResolver::class);
117127
parent::__construct($context);
118128
}
119129

@@ -391,4 +401,31 @@ public function isAttributeVisible($code)
391401
}
392402
return false;
393403
}
404+
405+
/**
406+
* Checks whether it is allowed to show an attribute on the form
407+
*
408+
* This check relies on the attribute's property 'getUsedInForms' which contains a list of forms
409+
* where allowed to render specified attribute.
410+
*
411+
* @param string $attributeCode
412+
* @param string $formName
413+
* @return bool
414+
*/
415+
public function isAttributeAllowedOnForm($attributeCode, $formName)
416+
{
417+
$isAllowed = false;
418+
$attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($attributeCode);
419+
if ($attributeMetadata) {
420+
/** @var \Magento\Customer\Model\Attribute $attribute */
421+
$attribute = $this->attributeResolver->getModelByAttribute(
422+
\Magento\Customer\Api\AddressMetadataManagementInterface::ENTITY_TYPE_ADDRESS,
423+
$attributeMetadata
424+
);
425+
$usedInForms = $attribute->getUsedInForms();
426+
$isAllowed = in_array($formName, $usedInForms, true);
427+
}
428+
429+
return $isAllowed;
430+
}
394431
}

app/code/Magento/Customer/Model/Plugin/CustomerNotification.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Framework\App\Area;
1313
use Magento\Framework\App\RequestInterface;
1414
use Magento\Framework\App\State;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Psr\Log\LoggerInterface;
1517

1618
class CustomerNotification
1719
{
@@ -35,24 +37,32 @@ class CustomerNotification
3537
*/
3638
private $state;
3739

40+
/**
41+
* @var LoggerInterface
42+
*/
43+
private $logger;
44+
3845
/**
3946
* Initialize dependencies.
4047
*
4148
* @param Session $session
4249
* @param NotificationStorage $notificationStorage
4350
* @param State $state
4451
* @param CustomerRepositoryInterface $customerRepository
52+
* @param LoggerInterface $logger
4553
*/
4654
public function __construct(
4755
Session $session,
4856
NotificationStorage $notificationStorage,
4957
State $state,
50-
CustomerRepositoryInterface $customerRepository
58+
CustomerRepositoryInterface $customerRepository,
59+
LoggerInterface $logger
5160
) {
5261
$this->session = $session;
5362
$this->notificationStorage = $notificationStorage;
5463
$this->state = $state;
5564
$this->customerRepository = $customerRepository;
65+
$this->logger = $logger;
5666
}
5767

5868
/**
@@ -63,17 +73,23 @@ public function __construct(
6373
*/
6474
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
6575
{
76+
$customerId = $this->session->getCustomerId();
77+
6678
if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost()
6779
&& $this->notificationStorage->isExists(
6880
NotificationStorage::UPDATE_CUSTOMER_SESSION,
69-
$this->session->getCustomerId()
81+
$customerId
7082
)
7183
) {
72-
$customer = $this->customerRepository->getById($this->session->getCustomerId());
73-
$this->session->setCustomerData($customer);
74-
$this->session->setCustomerGroupId($customer->getGroupId());
75-
$this->session->regenerateId();
76-
$this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
84+
try {
85+
$customer = $this->customerRepository->getById($customerId);
86+
$this->session->setCustomerData($customer);
87+
$this->session->setCustomerGroupId($customer->getGroupId());
88+
$this->session->regenerateId();
89+
$this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId);
90+
} catch (NoSuchEntityException $e) {
91+
$this->logger->error($e);
92+
}
7793
}
7894
}
7995
}

0 commit comments

Comments
 (0)