6 declare(strict_types=1);
14 use Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory;
162 \
Magento\Framework\Stdlib\DateTime\DateTime $date,
163 ItemFactory $wishlistItemFactory,
164 CollectionFactory $wishlistCollectionFactory,
169 $useCurrentWebsite =
true,
171 Json $serializer =
null 173 $this->_useCurrentWebsite = $useCurrentWebsite;
174 $this->_catalogProduct = $catalogProduct;
175 $this->_wishlistData = $wishlistData;
177 $this->_date = $date;
178 $this->_wishlistItemFactory = $wishlistItemFactory;
179 $this->_wishlistCollectionFactory = $wishlistCollectionFactory;
201 $customerIdFieldName = $this->
_getResource()->getCustomerIdFieldName();
203 if (!$this->
getId() && $create) {
221 return $this->_wishlistData->getDefaultWishlistName();
246 if (!$this->getShared()) {
260 return $this->mathRandom->getUniqueHash();
270 parent::beforeSave();
271 $this->setUpdatedAt($this->_date->gmtDate());
284 if (
null !== $this->_itemCollection) {
309 if (
$item ===
null) {
311 $item = $this->_wishlistItemFactory->create();
314 $item->setAddedAt((
new \DateTime())->format(\
Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
320 if (
$item->getId()) {
324 $qty = $forciblySetQty ? $qty :
$item->getQty() + $qty;
325 $item->setQty($qty)->save();
340 if ($this->_itemCollection ===
null) {
341 $this->_itemCollection = $this->_wishlistCollectionFactory->create()->addWishlistFilter(
345 )->setVisibilityFilter();
373 $item->setWishlist($this);
374 if (!
$item->getId()) {
376 $this->_eventManager->dispatch(
'wishlist_add_item', [
'item' =>
$item]);
410 $storeId = $this->_storeManager->getStore()->getId();
417 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Cannot specify product.'));
423 $isInvalidItemConfiguration =
false;
425 $buyRequestData = $this->serializer->unserialize(
$buyRequest);
426 if (!is_array($buyRequestData)) {
427 $isInvalidItemConfiguration =
true;
429 }
catch (\InvalidArgumentException $exception) {
430 $isInvalidItemConfiguration =
true;
432 if ($isInvalidItemConfiguration) {
433 throw new \InvalidArgumentException(
'Invalid wishlist item configuration.');
435 $_buyRequest = new \Magento\Framework\DataObject($buyRequestData);
437 $_buyRequest = new \Magento\Framework\DataObject(
$buyRequest);
439 $_buyRequest = new \Magento\Framework\DataObject();
443 $cartCandidates =
$product->getTypeInstance()->processConfiguration($_buyRequest, clone
$product);
448 if (is_string($cartCandidates)) {
449 return $cartCandidates;
455 if (!is_array($cartCandidates)) {
456 $cartCandidates = [$cartCandidates];
462 foreach ($cartCandidates as $candidate) {
463 if ($candidate->getParentProductId()) {
466 $candidate->setWishlistStoreId(
$storeId);
468 $qty = $candidate->getQty() ? $candidate->getQty() : 1;
474 if (
$item->getHasError()) {
479 $this->_eventManager->dispatch(
'wishlist_product_add_after', [
'items' =>
$items]);
514 $data[
'shared'] = (int)$this->getShared();
515 $data[
'sharing_code'] = $this->getSharingCode();
526 if ($this->_storeIds ===
null || !is_array($this->_storeIds)) {
527 if ($this->_useCurrentWebsite) {
528 $this->_storeIds = $this->
getStore()->getWebsite()->getStoreIds();
531 $stores = $this->_storeManager->getStores();
549 $this->_storeIds = (array)$storeIds;
560 if ($this->_store ===
null) {
561 $this->
setStore($this->_storeManager->getStore());
596 if (
$item->getProduct()->getIsSalable()) {
641 if ($itemId instanceof
Item) {
643 $itemId =
$item->getId();
648 throw new \Magento\Framework\Exception\LocalizedException(
__(
'We can\'t specify a wish list item.'));
655 $params = new \Magento\Framework\DataObject();
664 $isForceSetQuantity =
true;
672 $isForceSetQuantity =
false;
679 if (is_string($resultItem)) {
680 throw new \Magento\Framework\Exception\LocalizedException(
__($resultItem));
683 if ($resultItem->getId() != $itemId) {
684 if ($resultItem->getDescription() !=
$item->getDescription()) {
685 $resultItem->setDescription(
$item->getDescription())->
save();
687 $item->isDeleted(
true);
691 $resultItem->setOrigData(
'qty', 0);
694 throw new \Magento\Framework\Exception\LocalizedException(
__(
'The product does not exist.'));
707 if ($this->
getId()) {
708 $identities = [self::CACHE_TAG .
'_' . $this->
getId()];
setCustomerId($customerId)
updateItem($itemId, $buyRequest, $params=null)
setData($key, $value=null)
addNewItem($product, $buyRequest=null, $forciblySetQty=false)
getData($key='', $index=null)
elseif(isset( $params[ 'redirect_parent']))
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Catalog\Helper\Product $catalogProduct, \Magento\Wishlist\Helper\Data $wishlistData, ResourceWishlist $resource, Collection $resourceCollection, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\DateTime\DateTime $date, ItemFactory $wishlistItemFactory, CollectionFactory $wishlistCollectionFactory, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Framework\Math\Random $mathRandom, \Magento\Framework\Stdlib\DateTime $dateTime, ProductRepositoryInterface $productRepository, $useCurrentWebsite=true, array $data=[], Json $serializer=null)
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest
_addCatalogProduct(\Magento\Catalog\Model\Product $product, $qty=1, $forciblySetQty=false)
loadByCustomerId($customerId, $create=false)
$_wishlistCollectionFactory
setSharedStoreIds($storeIds)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
if(!isset($_GET['name'])) $name