Skip to content

Commit e82ba2e

Browse files
authored
Merge pull request magento#849 from magento-tango/MAGETWO-64483
Bug fixes: * MAGETWO-56014: [GitHub] Dashboard Most Viewed Products Tab in admin - prices issue magento#5660 * MAGETWO-62044: Not possible to update or delete products in cart or checkout after deleting address
2 parents f4c95fc + ad23561 commit e82ba2e

File tree

8 files changed

+559
-181
lines changed

8 files changed

+559
-181
lines changed

app/code/Magento/Backend/Block/Dashboard/Tab/Products/Viewed.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Backend\Block\Dashboard\Tab\Products;
77

8+
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Pricing\Price\FinalPrice;
10+
811
/**
912
* Adminhtml dashboard most viewed products grid
1013
*
@@ -66,8 +69,14 @@ protected function _prepareCollection()
6669
);
6770

6871
$this->setCollection($collection);
72+
parent::_prepareCollection();
73+
74+
/** @var Product $product */
75+
foreach ($collection as $product) {
76+
$product->setPrice($product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue());
77+
}
6978

70-
return parent::_prepareCollection();
79+
return $this;
7180
}
7281

7382
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public function getCustomerAddressId();
370370
/**
371371
* Set customer address id
372372
*
373-
* @param int $customerAddressId
373+
* @param int|null $customerAddressId
374374
* @return $this
375375
*/
376376
public function setCustomerAddressId($customerAddressId);

app/code/Magento/Quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
*/
66
namespace Magento\Quote\Model\Quote\ShippingAssignment;
77

8+
use Magento\Framework\Exception\LocalizedException;
89
use Magento\Quote\Api\Data\CartInterface;
910
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
1011
use Magento\Framework\Exception\InputException;
1112
use Magento\Quote\Model\ShippingAssignmentFactory;
1213
use Magento\Quote\Model\Quote\Item\CartItemPersister;
14+
use Magento\Customer\Api\AddressRepositoryInterface;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\Exception\NoSuchEntityException;
1317

1418
class ShippingAssignmentProcessor
1519
{
@@ -28,41 +32,56 @@ class ShippingAssignmentProcessor
2832
*/
2933
protected $cartItemPersister;
3034

35+
/**
36+
* @var AddressRepositoryInterface
37+
*/
38+
private $addressRepository;
39+
3140
/**
3241
* @param ShippingAssignmentFactory $shippingAssignmentFactory
3342
* @param ShippingProcessor $shippingProcessor
3443
* @param CartItemPersister $cartItemPersister
44+
* @param AddressRepositoryInterface $addressRepository
3545
*/
3646
public function __construct(
3747
ShippingAssignmentFactory $shippingAssignmentFactory,
3848
ShippingProcessor $shippingProcessor,
39-
CartItemPersister $cartItemPersister
49+
CartItemPersister $cartItemPersister,
50+
AddressRepositoryInterface $addressRepository = null
4051
) {
4152
$this->shippingAssignmentFactory = $shippingAssignmentFactory;
4253
$this->shippingProcessor = $shippingProcessor;
4354
$this->cartItemPersister = $cartItemPersister;
55+
$this->addressRepository = $addressRepository
56+
?: ObjectManager::getInstance()->get(AddressRepositoryInterface::class);
4457
}
4558

4659
/**
60+
* Create shipping assignment
61+
*
4762
* @param CartInterface $quote
4863
* @return \Magento\Quote\Api\Data\ShippingAssignmentInterface
4964
*/
5065
public function create(CartInterface $quote)
5166
{
5267
/** @var \Magento\Quote\Model\Quote $quote */
5368
$shippingAddress = $quote->getShippingAddress();
69+
5470
/** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment */
5571
$shippingAssignment = $this->shippingAssignmentFactory->create();
5672
$shippingAssignment->setItems($quote->getItems());
5773
$shippingAssignment->setShipping($this->shippingProcessor->create($shippingAddress));
74+
5875
return $shippingAssignment;
5976
}
6077

6178
/**
79+
* Save shipping assignment
80+
*
6281
* @param ShippingAssignmentInterface $shippingAssignment
6382
* @param CartInterface $quote
6483
* @return void
65-
* @throws InputException
84+
* @throws InputException|LocalizedException
6685
*/
6786
public function save(CartInterface $quote, ShippingAssignmentInterface $shippingAssignment)
6887
{
@@ -73,6 +92,17 @@ public function save(CartInterface $quote, ShippingAssignmentInterface $shipping
7392
$this->cartItemPersister->save($quote, $item);
7493
}
7594
}
95+
96+
$shippingAddress = $shippingAssignment->getShipping()->getAddress();
97+
98+
if ($shippingAddress->getCustomerAddressId()) {
99+
try {
100+
$this->addressRepository->getById($shippingAddress->getCustomerAddressId());
101+
} catch (NoSuchEntityException $e) {
102+
$shippingAddress->setCustomerAddressId(null);
103+
}
104+
}
105+
76106
$this->shippingProcessor->save($shippingAssignment->getShipping(), $quote);
77107
}
78108
}

app/code/Magento/Quote/Model/QuoteRepository/SaveHandler.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
namespace Magento\Quote\Model\QuoteRepository;
77

88
use Magento\Quote\Api\Data\CartInterface;
9+
use Magento\Customer\Api\AddressRepositoryInterface;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Exception\NoSuchEntityException;
912
use Magento\Framework\Exception\InputException;
1013

1114
class SaveHandler
@@ -30,38 +33,48 @@ class SaveHandler
3033
*/
3134
private $shippingAssignmentPersister;
3235

36+
/**
37+
* @var AddressRepositoryInterface
38+
*/
39+
private $addressRepository;
40+
3341
/**
3442
* @param \Magento\Quote\Model\ResourceModel\Quote $quoteResource
3543
* @param \Magento\Quote\Model\Quote\Item\CartItemPersister $cartItemPersister
3644
* @param \Magento\Quote\Model\Quote\Address\BillingAddressPersister $billingAddressPersister
3745
* @param \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentPersister $shippingAssignmentPersister
46+
* @param AddressRepositoryInterface $addressRepository
3847
*/
3948
public function __construct(
4049
\Magento\Quote\Model\ResourceModel\Quote $quoteResource,
4150
\Magento\Quote\Model\Quote\Item\CartItemPersister $cartItemPersister,
4251
\Magento\Quote\Model\Quote\Address\BillingAddressPersister $billingAddressPersister,
43-
\Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentPersister $shippingAssignmentPersister
52+
\Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentPersister $shippingAssignmentPersister,
53+
AddressRepositoryInterface $addressRepository = null
4454
) {
4555
$this->quoteResourceModel = $quoteResource;
4656
$this->cartItemPersister = $cartItemPersister;
4757
$this->billingAddressPersister = $billingAddressPersister;
4858
$this->shippingAssignmentPersister = $shippingAssignmentPersister;
59+
$this->addressRepository = $addressRepository
60+
?: ObjectManager::getInstance()->get(AddressRepositoryInterface::class);
4961
}
5062

5163
/**
64+
* Process and save quote data
65+
*
5266
* @param CartInterface $quote
5367
* @return CartInterface
54-
*
5568
* @throws InputException
5669
* @throws \Magento\Framework\Exception\CouldNotSaveException
5770
* @throws \Magento\Framework\Exception\LocalizedException
58-
* @throws \Magento\Framework\Exception\NoSuchEntityException
5971
*/
6072
public function save(CartInterface $quote)
6173
{
6274
/** @var \Magento\Quote\Model\Quote $quote */
6375
// Quote Item processing
6476
$items = $quote->getItems();
77+
6578
if ($items) {
6679
foreach ($items as $item) {
6780
/** @var \Magento\Quote\Model\Quote\Item $item */
@@ -73,17 +86,28 @@ public function save(CartInterface $quote)
7386

7487
// Billing Address processing
7588
$billingAddress = $quote->getBillingAddress();
89+
7690
if ($billingAddress) {
91+
if ($billingAddress->getCustomerAddressId()) {
92+
try {
93+
$this->addressRepository->getById($billingAddress->getCustomerAddressId());
94+
} catch (NoSuchEntityException $e) {
95+
$billingAddress->setCustomerAddressId(null);
96+
}
97+
}
98+
7799
$this->billingAddressPersister->save($quote, $billingAddress);
78100
}
79101

80102
$this->processShippingAssignment($quote);
81-
82103
$this->quoteResourceModel->save($quote->collectTotals());
104+
83105
return $quote;
84106
}
85107

86108
/**
109+
* Process shipping assignment
110+
*
87111
* @param \Magento\Quote\Model\Quote $quote
88112
* @return void
89113
* @throws InputException
@@ -92,11 +116,14 @@ private function processShippingAssignment($quote)
92116
{
93117
// Shipping Assignments processing
94118
$extensionAttributes = $quote->getExtensionAttributes();
119+
95120
if (!$quote->isVirtual() && $extensionAttributes && $extensionAttributes->getShippingAssignments()) {
96121
$shippingAssignments = $extensionAttributes->getShippingAssignments();
122+
97123
if (count($shippingAssignments) > 1) {
98-
throw new InputException(__("Only 1 shipping assignment can be set"));
124+
throw new InputException(__('Only 1 shipping assignment can be set'));
99125
}
126+
100127
$this->shippingAssignmentPersister->save($quote, $shippingAssignments[0]);
101128
}
102129
}

0 commit comments

Comments
 (0)