Skip to content

Commit d4aab3c

Browse files
authored
Merge pull request #6894 from magento-tsg/MC-24548
[Arrows] MC-24548: collect-totals API call not updating the selected shippingMethod
2 parents 0c14764 + ab7c4cd commit d4aab3c

File tree

7 files changed

+249
-16
lines changed

7 files changed

+249
-16
lines changed

app/code/Magento/ProductVideo/Test/Mftf/Data/ProductVideoData.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
<data key="videoTitle">The New Vimeo Player (You Know, For Videos)</data>
1919
<data key="videoShortTitle">The New Vimeo Player</data>
2020
</entity>
21+
<entity name="VimeoPrivateVideo" type="product_video">
22+
<data key="videoUrl">https://vimeo.com/313826626</data>
23+
</entity>
2124
</entities>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminValidatePrivacyOnVimeoGetVideoInformationTest">
12+
<annotations>
13+
<features value="ProductVideo"/>
14+
<stories value="Add/remove images and videos for all product types and category"/>
15+
<title value="Admin validates Vimeo video privacy when getting video information"/>
16+
<description value="Admin should be able to see warning message when adding Vimeo video with restricted privacy privacy when getting video information"/>
17+
<severity value="AVERAGE"/>
18+
<testCaseId value="MC-42471"/>
19+
<useCaseId value="MC-42105"/>
20+
<group value="productVideo"/>
21+
</annotations>
22+
<before>
23+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
24+
</before>
25+
<after>
26+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
27+
</after>
28+
<actionGroup ref="AdminOpenNewProductFormPageActionGroup" stepKey="openNewProductPage"/>
29+
<actionGroup ref="AdminOpenProductVideoModalActionGroup" stepKey="openAddProductVideoModal"/>
30+
<actionGroup ref="AdminFillProductVideoFieldActionGroup" stepKey="fillVideoUrlField">
31+
<argument name="input" value="{{AdminProductNewVideoSection.videoUrlTextField}}"/>
32+
<argument name="value" value="{{VimeoPrivateVideo.videoUrl}}"/>
33+
</actionGroup>
34+
<actionGroup ref="AdminGetVideoInformationActionGroup" stepKey="clickOnGetVideoInformation"/>
35+
<waitForElementVisible selector="{{AdminConfirmationModalSection.message}}" stepKey="waitForWarningMessage"/>
36+
<see selector="{{AdminConfirmationModalSection.message}}" userInput='Because of its privacy settings, this video cannot be played here.' stepKey="seeAdminWarningMessage"/>
37+
</test>
38+
</tests>

app/code/Magento/ProductVideo/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ Delete,Delete
4141
"Show related video","Show related video"
4242
"Auto restart video","Auto restart video"
4343
"Delete image in all store views","Delete image in all store views"
44+
"Because of its privacy settings, this video cannot be played here.","Because of its privacy settings, this video cannot be played here."

app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -495,28 +495,40 @@ define([
495495
*/
496496
function _onVimeoLoaded(data) {
497497
var tmp,
498-
respData;
498+
respData,
499+
videoDescription = '';
499500

500501
if (!data) {
501502
this._onRequestError($.mage.__('Video not found'));
502503

503504
return null;
504505
}
505506
tmp = data;
506-
respData = {
507-
duration: this._formatVimeoDuration(tmp.duration),
508-
channel: tmp['author_name'],
509-
channelId: tmp['author_url'],
510-
uploaded: tmp['upload_date'],
511-
title: tmp.title,
512-
description: tmp.description.replace(/(&nbsp;|<([^>]+)>)/ig, ''),
513-
thumbnail: tmp['thumbnail_url'],
514-
videoId: videoInfo.id,
515-
videoProvider: videoInfo.type
516-
};
517-
this._videoInformation = respData;
518-
this.element.trigger(this._UPDATE_VIDEO_INFORMATION_TRIGGER, respData);
519-
this.element.trigger(this._FINISH_UPDATE_INFORMATION_TRIGGER, true);
507+
508+
if (tmp.description !== null) {
509+
videoDescription = tmp.description;
510+
}
511+
512+
if (tmp.duration == null) {
513+
this._onRequestError(
514+
$.mage.__('Because of its privacy settings, this video cannot be played here.')
515+
);
516+
} else {
517+
respData = {
518+
duration: this._formatVimeoDuration(tmp.duration),
519+
channel: tmp['author_name'],
520+
channelId: tmp['author_url'],
521+
uploaded: tmp['upload_date'],
522+
title: tmp.title,
523+
description: videoDescription.replace(/(&nbsp;|<([^>]+)>)/ig, ''),
524+
thumbnail: tmp['thumbnail_url'],
525+
videoId: videoInfo.id,
526+
videoProvider: videoInfo.type
527+
};
528+
this._videoInformation = respData;
529+
this.element.trigger(this._UPDATE_VIDEO_INFORMATION_TRIGGER, respData);
530+
this.element.trigger(this._FINISH_UPDATE_INFORMATION_TRIGGER, true);
531+
}
520532
}
521533

522534
type = videoInfo.type;

app/code/Magento/Quote/Model/ShippingMethodManagement.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,15 @@ public function apply($cartId, $carrierCode, $methodCode)
224224
$this->quoteAddressResource->delete($shippingAddress);
225225
throw new StateException(__('The shipping address is missing. Set the address and try again.'));
226226
}
227-
$shippingAddress->setShippingMethod($carrierCode . '_' . $methodCode);
227+
$shippingMethod = $carrierCode . '_' . $methodCode;
228+
$shippingAddress->setShippingMethod($shippingMethod);
229+
$shippingAssignments = $quote->getExtensionAttributes()->getShippingAssignments();
230+
if (!empty($shippingAssignments)) {
231+
$shippingAssignment = $shippingAssignments[0];
232+
$shipping = $shippingAssignment->getShipping();
233+
$shipping->setMethod($shippingMethod);
234+
$shippingAssignment->setShipping($shipping);
235+
}
228236
}
229237

230238
/**

app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
use Magento\Store\Model\Store;
2828
use PHPUnit\Framework\MockObject\MockObject;
2929
use PHPUnit\Framework\TestCase;
30+
use Magento\Quote\Api\Data\CartExtensionInterface;
31+
use Magento\Sales\Model\Order\ShippingAssignmentBuilder;
32+
use Magento\Quote\Api\Data\ShippingInterface;
3033

3134
/**
3235
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -103,6 +106,21 @@ class ShippingMethodManagementTest extends TestCase
103106
*/
104107
private $quoteAddressResource;
105108

109+
/**
110+
* @var CartExtensionInterface|MockObject
111+
*/
112+
private $extensionAttributesMock;
113+
114+
/**
115+
* @var ShippingInterface|MockObject
116+
*/
117+
private $shippingMock;
118+
119+
/**
120+
* @var ShippingAssignmentBuilder|MockObject
121+
*/
122+
private $shippingAssignmentBuilder;
123+
106124
protected function setUp(): void
107125
{
108126
$this->objectManager = new ObjectManager($this);
@@ -135,6 +153,7 @@ protected function setUp(): void
135153
'collectTotals',
136154
'save',
137155
'__wakeup',
156+
'getExtensionAttributes'
138157
])
139158
->getMock();
140159

@@ -190,6 +209,20 @@ protected function setUp(): void
190209
'dataProcessor',
191210
$this->dataProcessor
192211
);
212+
213+
$this->extensionAttributesMock = $this->getMockBuilder(CartExtensionInterface::class)
214+
->setMethods(['getShippingAssignments'])
215+
->getMockForAbstractClass();
216+
217+
$this->shippingMock = $this->getMockForAbstractClass(ShippingInterface::class);
218+
219+
$this->shippingAssignmentBuilder = $this->getMockBuilder(ShippingAssignmentBuilder::class)
220+
->disableOriginalConstructor()
221+
->setMethods([
222+
'getShipping',
223+
'setShipping'
224+
])
225+
->getMock();
193226
}
194227

195228
public function testGetMethodWhenShippingAddressIsNotSet()
@@ -424,6 +457,24 @@ public function testSetMethodWithCouldNotSaveException()
424457
$this->shippingAddress->expects($this->once())
425458
->method('setShippingMethod')
426459
->with($carrierCode . '_' . $methodCode);
460+
$this->quote->expects($this->once())
461+
->method('getExtensionAttributes')
462+
->willReturn($this->extensionAttributesMock);
463+
464+
$this->extensionAttributesMock->expects($this->once())->method('getShippingAssignments')
465+
->willReturn([$this->shippingAssignmentBuilder]);
466+
467+
$this->shippingAssignmentBuilder->expects($this->once())->method('getShipping')
468+
->willReturn($this->shippingMock);
469+
470+
$this->shippingMock->expects($this->once())
471+
->method('setMethod')
472+
->with($carrierCode . '_' . $methodCode);
473+
474+
$this->shippingAssignmentBuilder->expects($this->once())
475+
->method('setShipping')
476+
->with($this->shippingMock);
477+
427478
$exception = new \Exception('Custom Error');
428479
$this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
429480
$this->quoteRepository->expects($this->once())
@@ -477,6 +528,24 @@ public function testSetMethod()
477528
->method('getCountryId')->willReturn($countryId);
478529
$this->shippingAddress->expects($this->once())
479530
->method('setShippingMethod')->with($carrierCode . '_' . $methodCode);
531+
$this->quote->expects($this->once())
532+
->method('getExtensionAttributes')
533+
->willReturn($this->extensionAttributesMock);
534+
535+
$this->extensionAttributesMock->expects($this->once())->method('getShippingAssignments')
536+
->willReturn([$this->shippingAssignmentBuilder]);
537+
538+
$this->shippingAssignmentBuilder->expects($this->once())->method('getShipping')
539+
->willReturn($this->shippingMock);
540+
541+
$this->shippingMock->expects($this->once())
542+
->method('setMethod')
543+
->with($carrierCode . '_' . $methodCode);
544+
545+
$this->shippingAssignmentBuilder->expects($this->once())
546+
->method('setShipping')
547+
->with($this->shippingMock);
548+
480549
$this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
481550
$this->quoteRepository->expects($this->once())->method('save')->with($this->quote);
482551

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Api;
7+
8+
use Magento\Framework\Webapi\Rest\Request;
9+
use Magento\Quote\Model\Quote;
10+
use Magento\Quote\Model\QuoteIdMaskFactory;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\ObjectManager;
13+
use Magento\TestFramework\TestCase\WebapiAbstract;
14+
use Magento\Quote\Model\QuoteIdMask;
15+
16+
/**
17+
* Class GuestCollectRatesTest checks that totals will be recollected properly with new shipping method
18+
*/
19+
class GuestCollectRatesTest extends WebapiAbstract
20+
{
21+
const SERVICE_VERSION = 'V1';
22+
const SERVICE_NAME = 'quoteGuestCartTotalManagementV1';
23+
const RESOURCE_PATH = '/V1/guest-carts/';
24+
25+
/**
26+
* @var ObjectManager
27+
*/
28+
private $objectManager;
29+
30+
/**
31+
* @var Quote
32+
*/
33+
protected $quote;
34+
35+
protected function setUp(): void
36+
{
37+
$this->objectManager = Bootstrap::getObjectManager();
38+
$this->quote = $this->objectManager->create(Quote::class);
39+
}
40+
41+
/**
42+
* Checks that totals are properly recollected after changing shipping method
43+
*
44+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
45+
*/
46+
public function testCollectRatesWithChangedShippingMethod()
47+
{
48+
$this->quote->load('test_order_1', 'reserved_order_id');
49+
$cartId = $this->quote->getId();
50+
51+
/** @var QuoteIdMask $quoteIdMask */
52+
$quoteIdMask = $this->objectManager
53+
->create(QuoteIdMaskFactory::class)
54+
->create();
55+
$quoteIdMask->load($cartId, 'quote_id');
56+
57+
$cartId = $quoteIdMask->getMaskedId();
58+
$requestData = [
59+
"shippingMethodCode" => "freeshipping",
60+
"shippingCarrierCode" => "freeshipping",
61+
"paymentMethod" => [
62+
"method" => "checkmo",
63+
],
64+
];
65+
66+
if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) {
67+
$requestData['cartId'] = $cartId;
68+
}
69+
70+
$totals = $this->_webApiCall($this->getListServiceInfo($cartId), $requestData);
71+
$this->assertEquals(20, $totals['grand_total']);
72+
$this->assertEquals(0, $totals['shipping_amount']);
73+
74+
$requestData['shippingMethodCode'] = 'flatrate';
75+
$requestData['shippingCarrierCode'] = 'flatrate';
76+
77+
$totals = $this->_webApiCall($this->getListServiceInfo($cartId), $requestData);
78+
$this->assertEquals(30, $totals['grand_total']);
79+
$this->assertEquals(10, $totals['shipping_amount']);
80+
}
81+
82+
/**
83+
* Service info
84+
*
85+
* @param int $cartId
86+
* @return array
87+
*/
88+
protected function getListServiceInfo($cartId)
89+
{
90+
return [
91+
'rest' => [
92+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/collect-totals',
93+
'httpMethod' => Request::HTTP_METHOD_PUT,
94+
],
95+
'soap' => [
96+
'service' => self::SERVICE_NAME,
97+
'serviceVersion' => self::SERVICE_VERSION,
98+
'operation' => 'quoteGuestCartTotalManagementV1CollectTotals',
99+
],
100+
];
101+
}
102+
}

0 commit comments

Comments
 (0)