Skip to content

Commit a9c765c

Browse files
authored
Merge pull request #1499 from kandy/2.1-backport
2.1 Backporton
2 parents e8669c2 + 21b4056 commit a9c765c

File tree

69 files changed

+3218
-605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3218
-605
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ public function build($productId)
9898
->limit(1);
9999
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
100100

101-
$priceSelectDefault = clone $priceSelect;
102-
$priceSelectDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
103-
$select[] = $priceSelectDefault;
104-
105101
if (!$this->catalogHelper->isPriceGlobal()) {
106-
$priceSelect->where('t.store_id = ?', $this->storeManager->getStore()->getId());
107-
$select[] = $priceSelect;
102+
$priceSelectStore = clone $priceSelect;
103+
$priceSelectStore->where('t.store_id = ?', $this->storeManager->getStore()->getId());
104+
$selects[] = $priceSelectStore;
108105
}
109106

110-
return $select;
107+
$priceSelect->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
108+
$selects[] = $priceSelect;
109+
110+
return $selects;
111111
}
112112
}

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ public function build($productId)
142142
->limit(1);
143143
$specialPrice = $this->baseSelectProcessor->process($specialPrice);
144144

145-
$specialPriceDefault = clone $specialPrice;
146-
$specialPriceDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
147-
$select[] = $specialPriceDefault;
148-
149145
if (!$this->catalogHelper->isPriceGlobal()) {
150-
$specialPrice->where('t.store_id = ?', $this->storeManager->getStore()->getId());
151-
$select[] = $specialPrice;
146+
$priceSelectStore = clone $specialPrice;
147+
$priceSelectStore->where('t.store_id = ?', $this->storeManager->getStore()->getId());
148+
$selects[] = $priceSelectStore;
152149
}
153150

154-
return $select;
151+
$specialPrice->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
152+
$selects[] = $specialPrice;
153+
154+
return $selects;
155155
}
156156
}

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ public function build($productId)
100100
->limit(1);
101101
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
102102

103-
$priceSelectDefault = clone $priceSelect;
104-
$priceSelectDefault->where('t.website_id = ?', self::DEFAULT_WEBSITE_ID);
105-
$select[] = $priceSelectDefault;
106-
107103
if (!$this->catalogHelper->isPriceGlobal()) {
108-
$priceSelect->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId());
109-
$select[] = $priceSelect;
104+
$priceSelectStore = clone $priceSelect;
105+
$priceSelectStore->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId());
106+
$selects[] = $priceSelectStore;
110107
}
111108

112-
return $select;
109+
$priceSelect->where('t.website_id = ?', self::DEFAULT_WEBSITE_ID);
110+
$selects[] = $priceSelect;
111+
112+
return $selects;
113113
}
114114
}

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderComposite.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function __construct($linkedProductSelectBuilder)
2626
*/
2727
public function build($productId)
2828
{
29-
$select = [];
29+
$selects = [];
3030
foreach ($this->linkedProductSelectBuilder as $productSelectBuilder) {
31-
$select = array_merge($select, $productSelectBuilder->build($productId));
31+
$selects = array_merge($selects, $productSelectBuilder->build($productId));
3232
}
3333

34-
return $select;
34+
return $selects;
3535
}
3636
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\ResourceModel\Product\Website;
7+
8+
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
9+
use Magento\Framework\DB\Select;
10+
use Magento\Framework\EntityManager\MetadataPool;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Framework\App\ResourceConnection;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
15+
/**
16+
* Filter products that belongs to current website
17+
*/
18+
class SelectProcessor implements BaseSelectProcessorInterface
19+
{
20+
/**
21+
* @var ResourceConnection
22+
*/
23+
private $resource;
24+
25+
/**
26+
* @var MetadataPool
27+
*/
28+
private $metadataPool;
29+
30+
/**
31+
* @var StoreManagerInterface
32+
*/
33+
private $storeManager;
34+
35+
/**
36+
* @param MetadataPool $metadataPool
37+
* @param ResourceConnection $resource
38+
* @param StoreManagerInterface $storeManager
39+
*/
40+
public function __construct(
41+
MetadataPool $metadataPool,
42+
ResourceConnection $resource,
43+
StoreManagerInterface $storeManager
44+
) {
45+
$this->metadataPool = $metadataPool;
46+
$this->resource = $resource;
47+
$this->storeManager = $storeManager;
48+
}
49+
50+
/**
51+
* Joins website-product relation table to filter products that are only in current website
52+
*
53+
* {@inheritdoc}
54+
*/
55+
public function process(Select $select)
56+
{
57+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
58+
$select->joinInner(
59+
['pw' => $this->resource->getTableName('catalog_product_website')],
60+
'pw.product_id = ' . BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField
61+
. ' AND pw.website_id = ' . $this->storeManager->getWebsite()->getId(),
62+
[]
63+
);
64+
65+
return $select;
66+
}
67+
}

app/code/Magento/Catalog/etc/di.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,26 @@
794794
</argument>
795795
</arguments>
796796
</type>
797-
<preference for="Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface" type="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor" />
797+
<preference for="Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface" type="Magento\Catalog\Model\ResourceModel\Product\CompositeWithWebsiteProcessor" />
798798
<type name="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor">
799799
<arguments>
800800
<argument name="baseSelectProcessors" xsi:type="array">
801801
<item name="status" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\StatusBaseSelectProcessor</item>
802802
</argument>
803803
</arguments>
804804
</type>
805+
<virtualType name="Magento\Catalog\Model\ResourceModel\Product\CompositeWithWebsiteProcessor" type="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor">
806+
<arguments>
807+
<argument name="baseSelectProcessors" xsi:type="array">
808+
<item name="website" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Website\SelectProcessor</item>
809+
</argument>
810+
</arguments>
811+
</virtualType>
812+
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\LinkedProductSelectBuilderByIndexPrice">
813+
<arguments>
814+
<argument name="baseSelectProcessor" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor</argument>
815+
</arguments>
816+
</type>
805817
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
806818
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
807819
</type>

app/code/Magento/Catalog/etc/events.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
<event name="magento_catalog_api_data_categorytreeinterface_load_after">
5252
<observer name="legacy_categorytree_load_after" instance="Magento\Framework\EntityManager\Observer\AfterEntityLoad" />
5353
</event>
54-
<event name="admin_system_config_changed_section_catalog">
55-
<observer name="catalog_update_price_attribute" instance="Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange" />
56-
</event>
5754
<event name="catalog_product_save_before">
5855
<observer name="set_special_price_start_date" instance="Magento\Catalog\Observer\SetSpecialPriceStartDate" />
5956
</event>
57+
<event name="admin_system_config_changed_section_catalog">
58+
<observer name="catalog_update_price_attribute" instance="Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange" />
59+
</event>
6060
</config>

app/code/Magento/Checkout/view/frontend/web/js/model/payment-service.js

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@ define(
88
'Magento_Checkout/js/model/quote',
99
'Magento_Checkout/js/model/payment/method-list',
1010
'Magento_Checkout/js/action/select-payment-method'
11-
],
12-
function (_, quote, methodList, selectPaymentMethod) {
11+
], function (_, quote, methodList, selectPaymentMethod) {
1312
'use strict';
14-
var freeMethodCode = 'free';
13+
14+
/**
15+
* Free method filter
16+
* @param {Object} paymentMethod
17+
* @return {Boolean}
18+
*/
19+
var isFreePaymentMethod = function (paymentMethod) {
20+
return paymentMethod.method === 'free';
21+
},
22+
23+
/**
24+
* Grabs the grand total from quote
25+
* @return {Number}
26+
*/
27+
getGrandTotal = function () {
28+
return quote.totals()['grand_total'];
29+
};
1530

1631
return {
1732
isFreeAvailable: false,
@@ -20,20 +35,19 @@ define(
2035
* @param {Array} methods
2136
*/
2237
setPaymentMethods: function (methods) {
23-
var self = this,
24-
freeMethod,
38+
var freeMethod,
2539
filteredMethods,
26-
methodIsAvailable;
40+
methodIsAvailable,
41+
methodNames;
2742

28-
freeMethod = _.find(methods, function (method) {
29-
return method.method === freeMethodCode;
30-
});
31-
this.isFreeAvailable = freeMethod ? true : false;
43+
freeMethod = _.find(methods, isFreePaymentMethod);
44+
this.isFreeAvailable = !!freeMethod;
3245

33-
if (self.isFreeAvailable && freeMethod && quote.totals().grand_total <= 0) {
46+
if (freeMethod && getGrandTotal() <= 0) {
3447
methods.splice(0, methods.length, freeMethod);
3548
selectPaymentMethod(freeMethod);
3649
}
50+
3751
filteredMethods = _.without(methods, freeMethod);
3852

3953
if (filteredMethods.length === 1) {
@@ -47,26 +61,38 @@ define(
4761
selectPaymentMethod(null);
4862
}
4963
}
64+
65+
/**
66+
* Overwrite methods with existing methods to preserve ko array references.
67+
* This prevent ko from re-rendering those methods.
68+
*/
69+
methodNames = _.pluck(methods, 'method');
70+
_.map(methodList(), function (existingMethod) {
71+
var existingMethodIndex = methodNames.indexOf(existingMethod.method);
72+
73+
if (existingMethodIndex !== -1) {
74+
methods[existingMethodIndex] = existingMethod;
75+
}
76+
});
77+
5078
methodList(methods);
5179
},
5280
/**
5381
* Get the list of available payment methods.
54-
* @returns {Array}
82+
* @return {Array}
5583
*/
5684
getAvailablePaymentMethods: function () {
57-
var methods = [],
58-
self = this;
59-
_.each(methodList(), function (method) {
60-
if (self.isFreeAvailable && (
61-
quote.totals().grand_total <= 0 && method.method === freeMethodCode ||
62-
quote.totals().grand_total > 0 && method.method !== freeMethodCode
63-
) || !self.isFreeAvailable
64-
) {
65-
methods.push(method);
66-
}
67-
});
85+
var allMethods = methodList().slice(),
86+
grandTotalOverZero = getGrandTotal() > 0;
87+
88+
if (!this.isFreeAvailable) {
89+
return allMethods;
90+
}
91+
if (grandTotalOverZero) {
92+
return _.reject(allMethods, isFreePaymentMethod);
93+
}
94+
return _.filter(allMethods, isFreePaymentMethod);
6895

69-
return methods;
7096
}
7197
};
7298
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Block;
7+
8+
/**
9+
* Class CustomerScopeData provide scope (website, store or store_group) information on front
10+
* Can be used, for example, on store front, in order to determine
11+
* that private cache invalid for current scope, by comparing
12+
* with appropriate value in store front private cache.
13+
*/
14+
class CustomerScopeData extends \Magento\Framework\View\Element\Template
15+
{
16+
/**
17+
* @var \Magento\Framework\View\Element\Template\Context
18+
*/
19+
private $storeManager;
20+
21+
/**
22+
* @var \Magento\Framework\Json\EncoderInterface
23+
*/
24+
private $jsonEncoder;
25+
26+
/**
27+
* @param \Magento\Framework\View\Element\Template\Context $context
28+
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
29+
* @param array $data
30+
*/
31+
public function __construct(
32+
\Magento\Framework\View\Element\Template\Context $context,
33+
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
34+
array $data = []
35+
) {
36+
parent::__construct($context, $data);
37+
$this->storeManager = $context->getStoreManager();
38+
$this->jsonEncoder = $jsonEncoder;
39+
}
40+
41+
/**
42+
* Return id of current website
43+
*
44+
* Can be used when necessary to obtain website id of the current customer.
45+
*
46+
* @return integer
47+
*/
48+
public function getWebsiteId()
49+
{
50+
return (int)$this->_storeManager->getStore()->getWebsiteId();
51+
}
52+
}

app/code/Magento/Customer/CustomerData/Customer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class Customer implements SectionSourceInterface
1919
*/
2020
protected $currentCustomer;
2121

22+
/**
23+
* @var View
24+
*/
25+
private $customerViewHelper;
26+
2227
/**
2328
* @param CurrentCustomer $currentCustomer
2429
* @param View $customerViewHelper
@@ -39,10 +44,12 @@ public function getSectionData()
3944
if (!$this->currentCustomer->getCustomerId()) {
4045
return [];
4146
}
47+
4248
$customer = $this->currentCustomer->getCustomer();
4349
return [
4450
'fullname' => $this->customerViewHelper->getCustomerName($customer),
4551
'firstname' => $customer->getFirstname(),
52+
'websiteId' => $customer->getWebsiteId(),
4653
];
4754
}
4855
}

0 commit comments

Comments
 (0)