Skip to content

Commit 0953478

Browse files
committed
Merge remote-tracking branch 'mpi/MC-18196' into pr_vk_2019_08_16
2 parents 69d5bbf + 54590fd commit 0953478

File tree

10 files changed

+368
-18
lines changed

10 files changed

+368
-18
lines changed

app/code/Magento/Wishlist/Helper/Data.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ public function getProductUrl($item, $additional = [])
639639
$product = $item->getProduct();
640640
}
641641
$buyRequest = $item->getBuyRequest();
642+
$fragment = [];
642643
if (is_object($buyRequest)) {
643644
$config = $buyRequest->getSuperProductConfig();
644645
if ($config && !empty($config['product_id'])) {
@@ -648,7 +649,16 @@ public function getProductUrl($item, $additional = [])
648649
$this->_storeManager->getStore()->getStoreId()
649650
);
650651
}
652+
$fragment = $buyRequest->getSuperAttribute() ?? [];
653+
if ($buyRequest->getQty()) {
654+
$additional['_query']['qty'] = $buyRequest->getQty();
655+
}
656+
}
657+
$url = $product->getUrlModel()->getUrl($product, $additional);
658+
if ($fragment) {
659+
$url .= '#' . http_build_query($fragment);
651660
}
652-
return $product->getUrlModel()->getUrl($product, $additional);
661+
662+
return $url;
653663
}
654664
}

app/code/Magento/Wishlist/Model/Item/Option.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
namespace Magento\Wishlist\Model\Item;
77

88
use Magento\Catalog\Model\Product;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Exception\NoSuchEntityException;
911
use Magento\Wishlist\Model\Item;
1012
use Magento\Catalog\Api\ProductRepositoryInterface;
1113

1214
/**
1315
* Item option model
14-
* @method int getProductId()
1516
*
17+
* @method int getProductId()
1618
* @api
1719
* @since 100.0.2
1820
*/
@@ -34,24 +36,32 @@ class Option extends \Magento\Framework\Model\AbstractModel implements
3436
*/
3537
protected $productRepository;
3638

39+
/**
40+
* @var \Psr\Log\LoggerInterface
41+
*/
42+
private $logger;
43+
3744
/**
3845
* @param \Magento\Framework\Model\Context $context
3946
* @param \Magento\Framework\Registry $registry
4047
* @param ProductRepositoryInterface $productRepository
4148
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
4249
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
4350
* @param array $data
51+
* @param \Psr\Log\LoggerInterface|null $logger
4452
*/
4553
public function __construct(
4654
\Magento\Framework\Model\Context $context,
4755
\Magento\Framework\Registry $registry,
4856
ProductRepositoryInterface $productRepository,
4957
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
5058
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
51-
array $data = []
59+
array $data = [],
60+
\Psr\Log\LoggerInterface $logger = null
5261
) {
5362
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
5463
$this->productRepository = $productRepository;
64+
$this->logger = $logger ?? ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
5565
}
5666

5767
/**
@@ -123,7 +133,11 @@ public function getProduct()
123133
{
124134
//In some cases product_id is present instead product instance
125135
if (null === $this->_product && $this->getProductId()) {
126-
$this->_product = $this->productRepository->getById($this->getProductId());
136+
try {
137+
$this->_product = $this->productRepository->getById($this->getProductId());
138+
} catch (NoSuchEntityException $exception) {
139+
$this->logger->error($exception);
140+
}
127141
}
128142
return $this->_product;
129143
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Model;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Wishlist\Model\ResourceModel\Item as ItemResourceModel;
13+
use Magento\Wishlist\Model\ResourceModel\Item\Option as ItemOptionResourceModel;
14+
15+
/**
16+
* Deletes wishlist items
17+
*/
18+
class WishlistCleaner
19+
{
20+
/**
21+
* Wishlist Item Option resource model
22+
*
23+
* @var ItemOptionResourceModel
24+
*/
25+
private $itemOptionResourceModel;
26+
27+
/**
28+
* Wishlist Item Option resource model
29+
*
30+
* @var ItemResourceModel
31+
*/
32+
private $itemResourceModel;
33+
34+
/**
35+
* @param ItemOptionResourceModel $itemOptionResourceModel
36+
* @param ItemResourceModel $itemResourceModel
37+
*/
38+
public function __construct(
39+
ItemOptionResourceModel $itemOptionResourceModel,
40+
ItemResourceModel $itemResourceModel
41+
) {
42+
$this->itemOptionResourceModel = $itemOptionResourceModel;
43+
$this->itemResourceModel = $itemResourceModel;
44+
}
45+
46+
/**
47+
* Deletes all wishlist items related the specified product
48+
*
49+
* @param ProductInterface $product
50+
* @throws LocalizedException
51+
*/
52+
public function execute(ProductInterface $product)
53+
{
54+
$connection = $this->itemResourceModel->getConnection();
55+
56+
$selectQuery = $connection
57+
->select()
58+
->from(['w_item' => $this->itemResourceModel->getMainTable()])
59+
->join(
60+
['w_item_option' => $this->itemOptionResourceModel->getMainTable()],
61+
'w_item.wishlist_item_id = w_item_option.wishlist_item_id'
62+
)
63+
->where('w_item_option.product_id = ?', $product->getId());
64+
65+
$connection->query($selectQuery->deleteFromSelect('w_item'));
66+
}
67+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Wishlist\Plugin\Helper\Product;
10+
11+
use Magento\Framework\App\Action\AbstractAction;
12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\View\Result\Page;
14+
15+
/**
16+
* Parses the query string and pre-fills product quantity
17+
*/
18+
class View
19+
{
20+
/**
21+
* Parses the query string and pre-fills product quantity
22+
*
23+
* @param \Magento\Catalog\Helper\Product\View $view
24+
* @param Page $resultPage
25+
* @param mixed $productId
26+
* @param AbstractAction $controller
27+
* @param mixed $params
28+
* @return array
29+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
30+
*/
31+
public function beforePrepareAndRender(
32+
\Magento\Catalog\Helper\Product\View $view,
33+
Page $resultPage,
34+
$productId,
35+
AbstractAction $controller,
36+
$params = null
37+
) {
38+
$qty = $controller->getRequest()->getParam('qty');
39+
if ($qty) {
40+
if (null === $params || !$params instanceof DataObject) {
41+
$params = new DataObject((array) $params);
42+
}
43+
if (!$params->getBuyRequest()) {
44+
$params->setBuyRequest(new DataObject([]));
45+
}
46+
$params->getBuyRequest()->setQty($qty);
47+
}
48+
49+
return [$resultPage, $productId, $controller, $params];
50+
}
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Wishlist\Plugin\Model\ResourceModel;
10+
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Catalog\Model\ResourceModel\Product as ProductResourceModel;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Wishlist\Model\WishlistCleaner;
15+
16+
/**
17+
* Cleans up wishlist items referencing the product being deleted
18+
*/
19+
class Product
20+
{
21+
/**
22+
* @var WishlistCleaner
23+
*/
24+
private $wishlistCleaner;
25+
26+
/**
27+
* @param WishlistCleaner $wishlistCleaner
28+
*/
29+
public function __construct(
30+
WishlistCleaner $wishlistCleaner
31+
) {
32+
$this->wishlistCleaner = $wishlistCleaner;
33+
}
34+
35+
/**
36+
* Cleans up wishlist items referencing the product being deleted
37+
*
38+
* @param ProductResourceModel $productResourceModel
39+
* @param mixed $product
40+
* @return void
41+
* @throws LocalizedException
42+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
43+
*/
44+
public function beforeDelete(
45+
ProductResourceModel $productResourceModel,
46+
$product
47+
) {
48+
if ($product instanceof ProductInterface) {
49+
$this->wishlistCleaner->execute($product);
50+
}
51+
}
52+
}

app/code/Magento/Wishlist/Pricing/ConfiguredPrice/ConfigurableProduct.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class ConfigurableProduct extends AbstractPrice
3131
*/
3232
public function getConfiguredAmount(): \Magento\Framework\Pricing\Amount\AmountInterface
3333
{
34-
/** @var \Magento\Wishlist\Model\Item\Option $customOption */
35-
$customOption = $this->getProduct()->getCustomOption('simple_product');
36-
$product = $customOption ? $customOption->getProduct() : $this->getProduct();
37-
38-
return $product->getPriceInfo()->getPrice(ConfiguredPriceInterface::CONFIGURED_PRICE_CODE)->getAmount();
34+
return $this
35+
->getProduct()
36+
->getPriceInfo()
37+
->getPrice(ConfiguredPriceInterface::CONFIGURED_PRICE_CODE)
38+
->getAmount();
3939
}
4040

4141
/**
@@ -45,22 +45,19 @@ public function getConfiguredAmount(): \Magento\Framework\Pricing\Amount\AmountI
4545
*/
4646
public function getConfiguredRegularAmount(): \Magento\Framework\Pricing\Amount\AmountInterface
4747
{
48-
/** @var \Magento\Wishlist\Model\Item\Option $customOption */
49-
$customOption = $this->getProduct()->getCustomOption('simple_product');
50-
$product = $customOption ? $customOption->getProduct() : $this->getProduct();
51-
52-
return $product->getPriceInfo()->getPrice(ConfiguredPriceInterface::CONFIGURED_REGULAR_PRICE_CODE)->getAmount();
48+
return $this
49+
->getProduct()
50+
->getPriceInfo()
51+
->getPrice(ConfiguredPriceInterface::CONFIGURED_REGULAR_PRICE_CODE)
52+
->getAmount();
5353
}
5454

5555
/**
5656
* @inheritdoc
5757
*/
5858
public function getValue()
5959
{
60-
/** @var \Magento\Wishlist\Model\Item\Option $customOption */
61-
$customOption = $this->getProduct()->getCustomOption('simple_product');
62-
$product = $customOption ? $customOption->getProduct() : $this->getProduct();
63-
$price = $product->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();
60+
$price = $this->getProduct()->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();
6461

6562
return max(0, $price);
6663
}
@@ -73,4 +70,17 @@ public function setItem(ItemInterface $item)
7370
$this->item = $item;
7471
return $this;
7572
}
73+
74+
/**
75+
* @inheritDoc
76+
*/
77+
public function getProduct()
78+
{
79+
/** @var \Magento\Catalog\Model\Product $product */
80+
$product = parent::getProduct();
81+
/** @var \Magento\Wishlist\Model\Item\Option $customOption */
82+
$customOption = $product->getCustomOption('simple_product');
83+
84+
return $customOption ? ($customOption->getProduct() ?? $product) : $product;
85+
}
7686
}

0 commit comments

Comments
 (0)