Skip to content

Commit 7117256

Browse files
author
Serhiy Shkolyarenko
committed
Merge remote-tracking branch 'origin/bugs' into grouped_product
2 parents a8b6b6a + 6063f41 commit 7117256

File tree

6 files changed

+152
-46
lines changed

6 files changed

+152
-46
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ public function delete(\Magento\Catalog\Api\Data\ProductInterface $product)
544544
unset($this->instances[$product->getSku()]);
545545
unset($this->instancesById[$product->getId()]);
546546
$this->resourceModel->delete($product);
547+
} catch (ValidatorException $e) {
548+
throw new CouldNotSaveException(__($e->getMessage()));
547549
} catch (\Exception $e) {
548550
throw new \Magento\Framework\Exception\StateException(
549551
__('Unable to remove product %1', $sku)

app/code/Magento/Checkout/CustomerData/Cart.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,15 @@ protected function getRecentItems()
150150
foreach (array_reverse($this->getAllQuoteItems()) as $item) {
151151
/* @var $item \Magento\Quote\Model\Quote\Item */
152152
if (!$item->getProduct()->isVisibleInSiteVisibility()) {
153-
$productId = $item->getProduct()->getId();
154-
$products = $this->catalogUrl->getRewriteByProductStore([$productId => $item->getStoreId()]);
155-
if (!isset($products[$productId])) {
153+
$product = $item->getOptionByCode('product_type') !== null
154+
? $item->getOptionByCode('product_type')->getProduct()
155+
: $item->getProduct();
156+
157+
$products = $this->catalogUrl->getRewriteByProductStore([$product->getId() => $item->getStoreId()]);
158+
if (!isset($products[$product->getId()])) {
156159
continue;
157160
}
158-
$urlDataObject = new \Magento\Framework\DataObject($products[$productId]);
161+
$urlDataObject = new \Magento\Framework\DataObject($products[$product->getId()]);
159162
$item->getProduct()->setUrlDataObject($urlDataObject);
160163
}
161164
$items[] = $this->itemPoolInterface->getItemData($item);

app/code/Magento/Checkout/Test/Unit/CustomerData/CartTest.php

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function testGetSectionData()
130130
$quoteItemMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
131131

132132
$productMock->expects($this->once())->method('isVisibleInSiteVisibility')->willReturn(false);
133-
$productMock->expects($this->once())->method('getId')->willReturn($productId);
133+
$productMock->expects($this->exactly(3))->method('getId')->willReturn($productId);
134134
$productMock->expects($this->once())
135135
->method('setUrlDataObject')
136136
->with(new \Magento\Framework\DataObject($productRewrite[$productId]))
@@ -170,4 +170,109 @@ public function testGetSectionData()
170170
];
171171
$this->assertEquals($expectedResult, $this->model->getSectionData());
172172
}
173+
174+
/**
175+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
176+
*/
177+
public function testGetSectionDataWithCompositeProduct()
178+
{
179+
$summaryQty = 100;
180+
$subtotalValue = 200;
181+
$productId = 10;
182+
$storeId = 20;
183+
184+
$productRewrite = [$productId => ['rewrite' => 'product']];
185+
$itemData = ['item' => 'data'];
186+
$shortcutButtonsHtml = '<span>Buttons</span>';
187+
$subtotalMock = $this->getMock('\Magento\Framework\DataObject', ['getValue'], [], '', false);
188+
$subtotalMock->expects($this->once())->method('getValue')->willReturn($subtotalValue);
189+
$totals = ['subtotal' => $subtotalMock];
190+
191+
$quoteMock = $this->getMock(
192+
'\Magento\Quote\Model\Quote',
193+
['getTotals', 'getHasError', 'getAllVisibleItems'],
194+
[],
195+
'',
196+
false
197+
);
198+
$quoteItemMock = $this->getMock(
199+
'\Magento\Quote\Model\Quote\Item',
200+
['getProduct', 'getOptionByCode', 'getStoreId'],
201+
[],
202+
'',
203+
false
204+
);
205+
206+
$this->checkoutSessionMock->expects($this->exactly(2))->method('getQuote')->willReturn($quoteMock);
207+
$quoteMock->expects($this->once())->method('getTotals')->willReturn($totals);
208+
$quoteMock->expects($this->once())->method('getHasError')->willReturn(false);
209+
210+
$this->checkoutCartMock->expects($this->once())->method('getSummaryQty')->willReturn($summaryQty);
211+
$this->checkoutHelperMock->expects($this->once())
212+
->method('formatPrice')
213+
->with($subtotalValue)
214+
->willReturn($subtotalValue);
215+
$this->checkoutHelperMock->expects($this->once())->method('canOnepageCheckout')->willReturn(true);
216+
217+
$quoteMock->expects($this->once())->method('getAllVisibleItems')->willReturn([$quoteItemMock]);
218+
219+
$productMock = $this->getMock(
220+
'\Magento\Catalog\Model\Product',
221+
['isVisibleInSiteVisibility', 'getId', 'setUrlDataObject'],
222+
[],
223+
'',
224+
false
225+
);
226+
227+
$optionsMock = $this->getMock('\Magento\Quote\Model\Quote\Item\Option', [], [], '', false);
228+
$optionsMock->expects($this->once())->method('getProduct')->willReturn($productMock);
229+
230+
$quoteItemMock->expects($this->exactly(2))->method('getProduct')->willReturn($productMock);
231+
$quoteItemMock->expects($this->exactly(2))
232+
->method('getOptionByCode')
233+
->with('product_type')
234+
->willReturn($optionsMock);
235+
$quoteItemMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
236+
237+
$productMock->expects($this->once())->method('isVisibleInSiteVisibility')->willReturn(false);
238+
$productMock->expects($this->exactly(3))->method('getId')->willReturn($productId);
239+
$productMock->expects($this->once())
240+
->method('setUrlDataObject')
241+
->with(new \Magento\Framework\DataObject($productRewrite[$productId]))
242+
->willReturnSelf();
243+
244+
$this->catalogUrlMock->expects($this->once())
245+
->method('getRewriteByProductStore')
246+
->with([$productId => $storeId])
247+
->willReturn($productRewrite);
248+
249+
$shortcutButtonsMock = $this->getMock('\Magento\Catalog\Block\ShortcutButtons', [], [], '', false);
250+
$this->layoutMock->expects($this->once())
251+
->method('createBlock')
252+
->with('Magento\Catalog\Block\ShortcutButtons')
253+
->willReturn($shortcutButtonsMock);
254+
255+
$shortcutButtonsMock->expects($this->once())->method('toHtml')->willReturn($shortcutButtonsHtml);
256+
$this->checkoutHelperMock->expects($this->once())
257+
->method('isAllowedGuestCheckout')
258+
->with($quoteMock)
259+
->willReturn(true);
260+
261+
$this->itemPoolInterfaceMock->expects($this->once())
262+
->method('getItemData')
263+
->with($quoteItemMock)
264+
->willReturn($itemData);
265+
266+
$expectedResult = [
267+
'summary_count' => 100,
268+
'subtotal' => 200,
269+
'possible_onepage_checkout' => 1,
270+
'items' => [
271+
['item' => 'data']
272+
],
273+
'extra_actions' => '<span>Buttons</span>',
274+
'isGuestCheckoutAllowed' => 1
275+
];
276+
$this->assertEquals($expectedResult, $this->model->getSectionData());
277+
}
173278
}

app/code/Magento/GiftMessage/view/frontend/web/js/action/gift-options.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,40 @@
55
/*global define*/
66
define(
77
[
8-
'../model/url-builder',
8+
'Magento_GiftMessage/js/model/url-builder',
99
'mage/storage',
1010
'Magento_Ui/js/model/messageList',
1111
'Magento_Checkout/js/model/error-processor',
12-
'mage/url'
12+
'mage/url',
13+
'Magento_Checkout/js/model/quote'
1314
],
14-
function(urlBuilder, storage, messageList, errorProcessor, url) {
15-
"use strict";
16-
return function(giftMessage, remove) {
17-
url.setBaseUrl(giftMessage.getConfigValue('baseUrl'));
18-
var quoteId = giftMessage.getConfigValue('quoteId');
15+
function (urlBuilder, storage, messageList, errorProcessor, url, quote) {
16+
'use strict';
17+
18+
return function (giftMessage, remove) {
1919
var serviceUrl;
20+
21+
url.setBaseUrl(giftMessage.getConfigValue('baseUrl'));
22+
2023
if (giftMessage.getConfigValue('isCustomerLoggedIn')) {
2124
serviceUrl = urlBuilder.createUrl('/carts/mine/gift-message', {});
25+
2226
if (giftMessage.itemId != 'orderLevel') {
23-
serviceUrl = urlBuilder.createUrl('/carts/mine/gift-message/:itemId', {itemId: giftMessage.itemId});
27+
serviceUrl = urlBuilder.createUrl('/carts/mine/gift-message/:itemId', {
28+
itemId: giftMessage.itemId
29+
});
2430
}
2531
} else {
26-
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/gift-message', {cartId: quoteId});
32+
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/gift-message', {
33+
cartId: quote.getQuoteId()
34+
});
35+
2736
if (giftMessage.itemId != 'orderLevel') {
2837
serviceUrl = urlBuilder.createUrl(
2938
'/guest-carts/:cartId/gift-message/:itemId',
30-
{cartId: quoteId, itemId: giftMessage.itemId}
39+
{
40+
cartId: quote.getQuoteId(), itemId: giftMessage.itemId
41+
}
3142
);
3243
}
3344
}
@@ -39,16 +50,16 @@ define(
3950
gift_message: giftMessage.getSubmitParams(remove)
4051
})
4152
).done(
42-
function(result) {
53+
function (response) {
4354
giftMessage.reset();
44-
_.each(giftMessage.getAfterSubmitCallbacks(), function(callback) {
55+
_.each(giftMessage.getAfterSubmitCallbacks(), function (callback) {
4556
if (_.isFunction(callback)) {
4657
callback();
4758
}
4859
});
4960
}
5061
).fail(
51-
function(response) {
62+
function (response) {
5263
errorProcessor.process(response);
5364
}
5465
);

app/code/Magento/GiftMessage/view/frontend/web/js/model/url-builder.js

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,19 @@
33
* See COPYING.txt for license details.
44
*/
55
/*jshint browser:true jquery:true*/
6-
/*global alert*/
76
define(
8-
['jquery'],
9-
function($) {
10-
return {
11-
method: "rest",
12-
storeCode: window.giftOptionsConfig.storeCode,
13-
version: 'V1',
14-
serviceUrl: ':method/:storeCode/:version',
7+
[
8+
'jquery',
9+
'Magento_Checkout/js/model/url-builder'
10+
],
11+
function ($, urlBuilder) {
12+
'use strict';
1513

16-
createUrl: function(url, params) {
17-
var completeUrl = this.serviceUrl + url;
18-
return this.bindParams(completeUrl, params);
19-
},
20-
bindParams: function(url, params) {
21-
params.method = this.method;
22-
params.storeCode = this.storeCode;
23-
params.version = this.version;
24-
25-
var urlParts = url.split("/");
26-
urlParts = urlParts.filter(Boolean);
27-
28-
$.each(urlParts, function(key, part) {
29-
part = part.replace(':', '');
30-
if (params[part] != undefined) {
31-
urlParts[key] = params[part];
32-
}
33-
});
34-
return urlParts.join('/');
14+
return $.extend(
15+
urlBuilder,
16+
{
17+
storeCode: window.giftOptionsConfig.storeCode
3518
}
36-
};
19+
);
3720
}
3821
);

app/code/Magento/Quote/Api/Data/CartInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface CartInterface extends \Magento\Framework\Api\ExtensibleDataInterface
1616
*/
1717
const KEY_ID = 'id';
1818

19+
const KEY_ENTITY_ID = 'entity_id';
20+
1921
const KEY_CREATED_AT = 'created_at';
2022

2123
const KEY_UPDATED_AT = 'updated_at';

0 commit comments

Comments
 (0)