diff -Nuar a/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilter.php b/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilter.php
new file mode 100644
index 00000000000..e9497a1d448
--- /dev/null
+++ b/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilter.php
@@ -0,0 +1,74 @@
+resource = $resource;
+ $this->stockConfiguration = $stockConfiguration;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function execute(
+ Select $select,
+ string $productTableAlias,
+ string $stockStatusTableAlias = self::TABLE_ALIAS,
+ ?int $websiteId = null
+ ): Select {
+ $stockStatusTable = $this->resource->getTableName(self::TABLE_NAME);
+ $joinCondition = [
+ "{$stockStatusTableAlias}.product_id = {$productTableAlias}.entity_id",
+ $select->getConnection()->quoteInto(
+ "{$stockStatusTableAlias}.website_id = ?",
+ $this->stockConfiguration->getDefaultScopeId()
+ ),
+ $select->getConnection()->quoteInto(
+ "{$stockStatusTableAlias}.stock_id = ?",
+ Stock::DEFAULT_STOCK_ID
+ )
+ ];
+ $select->join(
+ [$stockStatusTableAlias => $stockStatusTable],
+ implode(' AND ', $joinCondition),
+ []
+ );
+ $select->where("{$stockStatusTableAlias}.stock_status = ?", StockStatusInterface::STATUS_IN_STOCK);
+
+ return $select;
+ }
+}
diff -Nuar a/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilterInterface.php b/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilterInterface.php
new file mode 100644
index 00000000000..26eb4b0fa38
--- /dev/null
+++ b/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilterInterface.php
@@ -0,0 +1,34 @@
+
+
diff -Nuar a/vendor/magento/module-wishlist/Helper/Data.php b/vendor/magento/module-wishlist/Helper/Data.php
index 6c1ebd87b4e..2984d68f8de 100644
--- a/vendor/magento/module-wishlist/Helper/Data.php
+++ b/vendor/magento/module-wishlist/Helper/Data.php
@@ -639,6 +639,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
$product = $item->getProduct();
}
$buyRequest = $item->getBuyRequest();
+ $fragment = [];
if (is_object($buyRequest)) {
$config = $buyRequest->getSuperProductConfig();
if ($config && !empty($config['product_id'])) {
@@ -648,7 +649,16 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
$this->_storeManager->getStore()->getStoreId()
);
}
+ $fragment = $buyRequest->getSuperAttribute() ?? [];
+ if ($buyRequest->getQty()) {
+ $additional['_query']['qty'] = $buyRequest->getQty();
+ }
+ }
+ $url = $product->getUrlModel()->getUrl($product, $additional);
+ if ($fragment) {
+ $url .= '#' . http_build_query($fragment);
}
- return $product->getUrlModel()->getUrl($product, $additional);
+
+ return $url;
}
}
diff -Nuar a/vendor/magento/module-wishlist/Model/Adminhtml/ResourceModel/Item/Product/CollectionBuilder.php b/vendor/magento/module-wishlist/Model/Adminhtml/ResourceModel/Item/Product/CollectionBuilder.php
new file mode 100644
index 00000000000..aa54c17c243
--- /dev/null
+++ b/vendor/magento/module-wishlist/Model/Adminhtml/ResourceModel/Item/Product/CollectionBuilder.php
@@ -0,0 +1,26 @@
+productRepository = $productRepository;
+ $this->logger = $logger ?? ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
}
/**
@@ -123,7 +133,11 @@ class Option extends \Magento\Framework\Model\AbstractModel implements
{
//In some cases product_id is present instead product instance
if (null === $this->_product && $this->getProductId()) {
- $this->_product = $this->productRepository->getById($this->getProductId());
+ try {
+ $this->_product = $this->productRepository->getById($this->getProductId());
+ } catch (NoSuchEntityException $exception) {
+ $this->logger->error($exception);
+ }
}
return $this->_product;
}
diff -Nuar a/vendor/magento/module-wishlist/Model/ResourceModel/Item/Collection.php b/vendor/magento/module-wishlist/Model/ResourceModel/Item/Collection.php
index 92592e8417c..0fda2ef3134 100644
--- a/vendor/magento/module-wishlist/Model/ResourceModel/Item/Collection.php
+++ b/vendor/magento/module-wishlist/Model/ResourceModel/Item/Collection.php
@@ -7,10 +7,11 @@ namespace Magento\Wishlist\Model\ResourceModel\Item;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
-use Magento\CatalogInventory\Model\Stock;
+use Magento\CatalogInventory\Model\ResourceModel\StockStatusFilterInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Sales\Model\ConfigInterface;
+use Magento\Wishlist\Model\ResourceModel\Item\Product\CollectionBuilderInterface;
/**
* Wishlist item collection
@@ -157,6 +158,21 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
* @var ConfigInterface
*/
private $salesConfig;
+ /**
+ * @var CollectionBuilderInterface
+ */
+ private $productCollectionBuilder;
+ /**
+ * @var StockStatusFilterInterface
+ */
+ private $stockStatusFilter;
+
+ /**
+ * Whether product table is joined in select
+ *
+ * @var bool
+ */
+ private $isProductTableJoined = false;
/**
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
@@ -176,10 +192,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
* @param \Magento\Catalog\Model\Entity\AttributeFactory $catalogAttrFactory
* @param \Magento\Wishlist\Model\ResourceModel\Item $resource
* @param \Magento\Framework\App\State $appState
- * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
+ * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
* @param TableMaintainer|null $tableMaintainer
- * @param ConfigInterface|null $salesConfig
- *
+ * @param ConfigInterface|null $salesConfig
+ * @param CollectionBuilderInterface|null $productCollectionBuilder
+ * @param StockStatusFilterInterface|null $stockStatusFilter
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
@@ -202,7 +219,9 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
\Magento\Framework\App\State $appState,
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
TableMaintainer $tableMaintainer = null,
- ConfigInterface $salesConfig = null
+ ConfigInterface $salesConfig = null,
+ ?CollectionBuilderInterface $productCollectionBuilder = null,
+ ?StockStatusFilterInterface $stockStatusFilter = null
) {
$this->stockConfiguration = $stockConfiguration;
$this->_adminhtmlSales = $adminhtmlSales;
@@ -219,6 +238,10 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
$this->salesConfig = $salesConfig ?: ObjectManager::getInstance()->get(ConfigInterface::class);
+ $this->productCollectionBuilder = $productCollectionBuilder
+ ?: ObjectManager::getInstance()->get(CollectionBuilderInterface::class);
+ $this->stockStatusFilter = $stockStatusFilter
+ ?: ObjectManager::getInstance()->get(StockStatusFilterInterface::class);
}
/**
@@ -309,12 +332,10 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
$productCollection->setVisibility($this->_productVisibility->getVisibleInSiteIds());
}
- $productCollection->addPriceData()
- ->addTaxPercents()
- ->addIdFilter($this->_productIds)
- ->addAttributeToSelect($this->_wishlistConfig->getProductAttributes())
- ->addOptionsToResult()
- ->addUrlRewrite();
+ $productCollection->addIdFilter($this->_productIds)
+ ->addAttributeToSelect($this->_wishlistConfig->getProductAttributes());
+
+ $productCollection = $this->productCollectionBuilder->build($this, $productCollection);
if ($this->_productSalable) {
$productCollection = $this->_adminhtmlSales->applySalableProductTypesFilter($productCollection);
@@ -362,15 +383,8 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
$connection = $this->getConnection();
if ($this->_productInStock && !$this->stockConfiguration->isShowOutOfStock()) {
- $inStockConditions = [
- "stockItem.product_id = {$mainTableName}.product_id",
- $connection->quoteInto('stockItem.stock_status = ?', Stock::STOCK_IN_STOCK),
- ];
- $this->getSelect()->join(
- ['stockItem' => $this->getTable('cataloginventory_stock_status')],
- join(' AND ', $inStockConditions),
- []
- );
+ $this->joinProductTable();
+ $this->stockStatusFilter->execute($this->getSelect(), 'product_entity', 'stockItem');
}
if ($this->_productVisible) {
@@ -576,10 +590,12 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
$storeId = $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId();
$entityMetadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
+ $linkField = $entityMetadata->getLinkField();
+ $this->joinProductTable();
$this->getSelect()->join(
['product_name_table' => $attribute->getBackendTable()],
- 'product_name_table.' . $entityMetadata->getLinkField() . ' = main_table.product_id' .
+ 'product_name_table.' . $linkField . ' = product_entity.' . $linkField .
' AND product_name_table.store_id = ' .
$storeId .
' AND product_name_table.attribute_id = ' .
@@ -589,6 +605,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
$this->_isProductNameJoined = true;
}
+
return $this;
}
@@ -661,4 +678,21 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
return $this;
}
+
+ /**
+ * Join product table to select if not already joined
+ *
+ * @return void
+ */
+ private function joinProductTable(): void
+ {
+ if (!$this->isProductTableJoined) {
+ $this->getSelect()->join(
+ ['product_entity' => $this->getTable('catalog_product_entity')],
+ 'product_entity.entity_id = main_table.product_id',
+ []
+ );
+ $this->isProductTableJoined = true;
+ }
+ }
}
diff -Nuar a/vendor/magento/module-wishlist/Model/ResourceModel/Item/Product/CollectionBuilder.php b/vendor/magento/module-wishlist/Model/ResourceModel/Item/Product/CollectionBuilder.php
new file mode 100644
index 00000000000..05255d1fe39
--- /dev/null
+++ b/vendor/magento/module-wishlist/Model/ResourceModel/Item/Product/CollectionBuilder.php
@@ -0,0 +1,28 @@
+addPriceData()
+ ->addTaxPercents()
+ ->addOptionsToResult()
+ ->addUrlRewrite();
+ }
+}
diff -Nuar a/vendor/magento/module-wishlist/Model/ResourceModel/Item/Product/CollectionBuilderInterface.php b/vendor/magento/module-wishlist/Model/ResourceModel/Item/Product/CollectionBuilderInterface.php
new file mode 100644
index 00000000000..1984d92e08a
--- /dev/null
+++ b/vendor/magento/module-wishlist/Model/ResourceModel/Item/Product/CollectionBuilderInterface.php
@@ -0,0 +1,26 @@
+_useCurrentWebsite = $useCurrentWebsite;
$this->_catalogProduct = $catalogProduct;
@@ -183,6 +213,8 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
$this->productRepository = $productRepository;
+ $this->stockConfiguration = $stockConfiguration
+ ?: ObjectManager::getInstance()->get(StockConfigurationInterface::class);
}
/**
@@ -290,13 +322,13 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
/**
* Add catalog product object data to wishlist
*
- * @param \Magento\Catalog\Model\Product $product
+ * @param Product $product
* @param int $qty
* @param bool $forciblySetQty
*
* @return Item
*/
- protected function _addCatalogProduct(\Magento\Catalog\Model\Product $product, $qty = 1, $forciblySetQty = false)
+ protected function _addCatalogProduct(Product $product, $qty = 1, $forciblySetQty = false)
{
$item = null;
foreach ($this->getItemCollection() as $_item) {
@@ -311,7 +343,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
$item = $this->_wishlistItemFactory->create();
$item->setProductId($product->getId());
$item->setWishlistId($this->getId());
- $item->setAddedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
+ $item->setAddedAt((new \DateTime())->format(DateTime::DATETIME_PHP_FORMAT));
$item->setStoreId($storeId);
$item->setOptions($product->getCustomOptions());
$item->setProduct($product);
@@ -334,6 +366,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
* Retrieve wishlist item collection
*
* @return \Magento\Wishlist\Model\ResourceModel\Item\Collection
+ * @throws NoSuchEntityException
*/
public function getItemCollection()
{
@@ -342,7 +375,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
$this
)->addStoreFilter(
$this->getSharedStoreIds()
- )->setVisibilityFilter();
+ )->setVisibilityFilter($this->_useCurrentWebsite);
}
return $this->_itemCollection;
@@ -365,8 +398,9 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
/**
* Adding item to wishlist
*
- * @param Item $item
- * @return $this
+ * @param Item $item
+ * @return $this
+ * @throws Exception
*/
public function addItem(Item $item)
{
@@ -383,13 +417,14 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
*
* Returns new item or string on error.
*
- * @param int|\Magento\Catalog\Model\Product $product
- * @param \Magento\Framework\DataObject|array|string|null $buyRequest
+ * @param int|Product $product
+ * @param DataObject|array|string|null $buyRequest
* @param bool $forciblySetQty
- * @throws \Magento\Framework\Exception\LocalizedException
* @return Item|string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
+ * @throws LocalizedException
+ * @throws InvalidArgumentException
*/
public function addNewItem($product, $buyRequest = null, $forciblySetQty = false)
{
@@ -398,7 +433,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
* a) we have new instance and do not interfere with other products in wishlist
* b) product has full set of attributes
*/
- if ($product instanceof \Magento\Catalog\Model\Product) {
+ if ($product instanceof Product) {
$productId = $product->getId();
// Maybe force some store by wishlist internal properties
$storeId = $product->hasWishlistStoreId() ? $product->getWishlistStoreId() : $product->getStoreId();
@@ -412,12 +447,17 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
}
try {
+ /** @var Product $product */
$product = $this->productRepository->getById($productId, false, $storeId);
} catch (NoSuchEntityException $e) {
- throw new \Magento\Framework\Exception\LocalizedException(__('Cannot specify product.'));
+ throw new LocalizedException(__('Cannot specify product.'));
+ }
+
+ if (!$this->stockConfiguration->isShowOutOfStock($storeId) && !$product->getIsSalable()) {
+ throw new LocalizedException(__('Cannot add product without stock to wishlist.'));
}
- if ($buyRequest instanceof \Magento\Framework\DataObject) {
+ if ($buyRequest instanceof DataObject) {
$_buyRequest = $buyRequest;
} elseif (is_string($buyRequest)) {
$isInvalidItemConfiguration = false;
@@ -426,20 +466,20 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
if (!is_array($buyRequestData)) {
$isInvalidItemConfiguration = true;
}
- } catch (\InvalidArgumentException $exception) {
+ } catch (Exception $exception) {
$isInvalidItemConfiguration = true;
}
if ($isInvalidItemConfiguration) {
- throw new \InvalidArgumentException('Invalid wishlist item configuration.');
+ throw new InvalidArgumentException('Invalid wishlist item configuration.');
}
- $_buyRequest = new \Magento\Framework\DataObject($buyRequestData);
+ $_buyRequest = new DataObject($buyRequestData);
} elseif (is_array($buyRequest)) {
- $_buyRequest = new \Magento\Framework\DataObject($buyRequest);
+ $_buyRequest = new DataObject($buyRequest);
} else {
- $_buyRequest = new \Magento\Framework\DataObject();
+ $_buyRequest = new DataObject();
}
- /* @var $product \Magento\Catalog\Model\Product */
+ /* @var $product Product */
$cartCandidates = $product->getTypeInstance()->processConfiguration($_buyRequest, clone $product);
/**
@@ -486,6 +526,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
*
* @param int $customerId
* @return $this
+ * @throws LocalizedException
*/
public function setCustomerId($customerId)
{
@@ -496,6 +537,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
* Retrieve customer id
*
* @return int
+ * @throws LocalizedException
*/
public function getCustomerId()
{
@@ -506,6 +548,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
* Retrieve data for save
*
* @return array
+ * @throws LocalizedException
*/
public function getDataForSave()
{
@@ -520,6 +563,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
* Retrieve shared store ids for current website or all stores if $current is false
*
* @return array
+ * @throws NoSuchEntityException
*/
public function getSharedStoreIds()
{
@@ -554,6 +598,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
* Retrieve wishlist store object
*
* @return \Magento\Store\Model\Store
+ * @throws NoSuchEntityException
*/
public function getStore()
{
@@ -566,7 +611,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
/**
* Set wishlist store
*
- * @param \Magento\Store\Model\Store $store
+ * @param Store $store
* @return $this
*/
public function setStore($store)
@@ -605,6 +650,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
*
* @param int $customerId
* @return bool
+ * @throws LocalizedException
*/
public function isOwner($customerId)
{
@@ -626,14 +672,15 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
* For more options see \Magento\Catalog\Helper\Product->addParamsToBuyRequest()
*
* @param int|Item $itemId
- * @param \Magento\Framework\DataObject $buyRequest
- * @param null|array|\Magento\Framework\DataObject $params
+ * @param DataObject $buyRequest
+ * @param null|array|DataObject $params
* @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*
* @see \Magento\Catalog\Helper\Product::addParamsToBuyRequest()
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
+ *@throws LocalizedException
*/
public function updateItem($itemId, $buyRequest, $params = null)
{
@@ -645,16 +692,16 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
$item = $this->getItem((int)$itemId);
}
if (!$item) {
- throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t specify a wish list item.'));
+ throw new LocalizedException(__('We can\'t specify a wish list item.'));
}
$product = $item->getProduct();
$productId = $product->getId();
if ($productId) {
if (!$params) {
- $params = new \Magento\Framework\DataObject();
+ $params = new DataObject();
} elseif (is_array($params)) {
- $params = new \Magento\Framework\DataObject($params);
+ $params = new DataObject($params);
}
$params->setCurrentConfig($item->getBuyRequest());
$buyRequest = $this->_catalogProduct->addParamsToBuyRequest($buyRequest, $params);
@@ -677,7 +724,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
* Error message
*/
if (is_string($resultItem)) {
- throw new \Magento\Framework\Exception\LocalizedException(__($resultItem));
+ throw new LocalizedException(__($resultItem));
}
if ($resultItem->getId() != $itemId) {
@@ -691,7 +738,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
$resultItem->setOrigData('qty', 0);
}
} else {
- throw new \Magento\Framework\Exception\LocalizedException(__('The product does not exist.'));
+ throw new LocalizedException(__('The product does not exist.'));
}
return $this;
}
diff -Nuar a/vendor/magento/module-wishlist/Model/WishlistCleaner.php b/vendor/magento/module-wishlist/Model/WishlistCleaner.php
new file mode 100644
index 00000000000..0189ad32d76
--- /dev/null
+++ b/vendor/magento/module-wishlist/Model/WishlistCleaner.php
@@ -0,0 +1,67 @@
+itemOptionResourceModel = $itemOptionResourceModel;
+ $this->itemResourceModel = $itemResourceModel;
+ }
+
+ /**
+ * Deletes all wishlist items related the specified product
+ *
+ * @param ProductInterface $product
+ * @throws LocalizedException
+ */
+ public function execute(ProductInterface $product)
+ {
+ $connection = $this->itemResourceModel->getConnection();
+
+ $selectQuery = $connection
+ ->select()
+ ->from(['w_item' => $this->itemResourceModel->getMainTable()])
+ ->join(
+ ['w_item_option' => $this->itemOptionResourceModel->getMainTable()],
+ 'w_item.wishlist_item_id = w_item_option.wishlist_item_id'
+ )
+ ->where('w_item_option.product_id = ?', $product->getId());
+
+ $connection->query($selectQuery->deleteFromSelect('w_item'));
+ }
+}
diff -Nuar a/vendor/magento/module-wishlist/Plugin/Helper/Product/View.php b/vendor/magento/module-wishlist/Plugin/Helper/Product/View.php
new file mode 100644
index 00000000000..58deb33a788
--- /dev/null
+++ b/vendor/magento/module-wishlist/Plugin/Helper/Product/View.php
@@ -0,0 +1,51 @@
+getRequest()->getParam('qty');
+ if ($qty) {
+ if (null === $params || !$params instanceof DataObject) {
+ $params = new DataObject((array) $params);
+ }
+ if (!$params->getBuyRequest()) {
+ $params->setBuyRequest(new DataObject([]));
+ }
+ $params->getBuyRequest()->setQty($qty);
+ }
+
+ return [$resultPage, $productId, $controller, $params];
+ }
+}
diff -Nuar a/vendor/magento/module-wishlist/Plugin/Model/ResourceModel/Product.php b/vendor/magento/module-wishlist/Plugin/Model/ResourceModel/Product.php
new file mode 100644
index 00000000000..e5492cd6863
--- /dev/null
+++ b/vendor/magento/module-wishlist/Plugin/Model/ResourceModel/Product.php
@@ -0,0 +1,52 @@
+wishlistCleaner = $wishlistCleaner;
+ }
+
+ /**
+ * Cleans up wishlist items referencing the product being deleted
+ *
+ * @param ProductResourceModel $productResourceModel
+ * @param mixed $product
+ * @return void
+ * @throws LocalizedException
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function beforeDelete(
+ ProductResourceModel $productResourceModel,
+ $product
+ ) {
+ if ($product instanceof ProductInterface) {
+ $this->wishlistCleaner->execute($product);
+ }
+ }
+}
diff -Nuar a/vendor/magento/module-wishlist/Pricing/ConfiguredPrice/ConfigurableProduct.php b/vendor/magento/module-wishlist/Pricing/ConfiguredPrice/ConfigurableProduct.php
index e1fafe35e43..7a16b83eaf5 100644
--- a/vendor/magento/module-wishlist/Pricing/ConfiguredPrice/ConfigurableProduct.php
+++ b/vendor/magento/module-wishlist/Pricing/ConfiguredPrice/ConfigurableProduct.php
@@ -31,11 +31,11 @@ class ConfigurableProduct extends AbstractPrice
*/
public function getConfiguredAmount(): \Magento\Framework\Pricing\Amount\AmountInterface
{
- /** @var \Magento\Wishlist\Model\Item\Option $customOption */
- $customOption = $this->getProduct()->getCustomOption('simple_product');
- $product = $customOption ? $customOption->getProduct() : $this->getProduct();
-
- return $product->getPriceInfo()->getPrice(ConfiguredPriceInterface::CONFIGURED_PRICE_CODE)->getAmount();
+ return $this
+ ->getProduct()
+ ->getPriceInfo()
+ ->getPrice(ConfiguredPriceInterface::CONFIGURED_PRICE_CODE)
+ ->getAmount();
}
/**
@@ -45,11 +45,11 @@ class ConfigurableProduct extends AbstractPrice
*/
public function getConfiguredRegularAmount(): \Magento\Framework\Pricing\Amount\AmountInterface
{
- /** @var \Magento\Wishlist\Model\Item\Option $customOption */
- $customOption = $this->getProduct()->getCustomOption('simple_product');
- $product = $customOption ? $customOption->getProduct() : $this->getProduct();
-
- return $product->getPriceInfo()->getPrice(ConfiguredPriceInterface::CONFIGURED_REGULAR_PRICE_CODE)->getAmount();
+ return $this
+ ->getProduct()
+ ->getPriceInfo()
+ ->getPrice(ConfiguredPriceInterface::CONFIGURED_REGULAR_PRICE_CODE)
+ ->getAmount();
}
/**
@@ -57,10 +57,7 @@ class ConfigurableProduct extends AbstractPrice
*/
public function getValue()
{
- /** @var \Magento\Wishlist\Model\Item\Option $customOption */
- $customOption = $this->getProduct()->getCustomOption('simple_product');
- $product = $customOption ? $customOption->getProduct() : $this->getProduct();
- $price = $product->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();
+ $price = $this->getProduct()->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();
return max(0, $price);
}
@@ -73,4 +70,17 @@ class ConfigurableProduct extends AbstractPrice
$this->item = $item;
return $this;
}
+
+ /**
+ * @inheritDoc
+ */
+ public function getProduct()
+ {
+ /** @var \Magento\Catalog\Model\Product $product */
+ $product = parent::getProduct();
+ /** @var \Magento\Wishlist\Model\Item\Option $customOption */
+ $customOption = $product->getCustomOption('simple_product');
+
+ return $customOption ? ($customOption->getProduct() ?? $product) : $product;
+ }
}
diff -Nuar a/vendor/magento/module-wishlist/etc/adminhtml/di.xml b/vendor/magento/module-wishlist/etc/adminhtml/di.xml
index 2e222f81938..be4d1966a46 100644
--- a/vendor/magento/module-wishlist/etc/adminhtml/di.xml
+++ b/vendor/magento/module-wishlist/etc/adminhtml/di.xml
@@ -21,4 +21,9 @@
Magento\Wishlist\Model\Session\Storage
+
+
+
+
diff -Nuar a/vendor/magento/module-wishlist/etc/di.xml b/vendor/magento/module-wishlist/etc/di.xml
index c0230a5326f..924bdfa3eb5 100644
--- a/vendor/magento/module-wishlist/etc/di.xml
+++ b/vendor/magento/module-wishlist/etc/di.xml
@@ -78,4 +78,6 @@
+
diff -Nuar a/vendor/magento/module-wishlist/etc/frontend/di.xml b/vendor/magento/module-wishlist/etc/frontend/di.xml
index f28e85fff0a..c1c03802ba9 100644
--- a/vendor/magento/module-wishlist/etc/frontend/di.xml
+++ b/vendor/magento/module-wishlist/etc/frontend/di.xml
@@ -53,4 +53,7 @@
+
+
+