14 use Magento\Wishlist\Model\Item\OptionFactory;
15 use Magento\Wishlist\Model\ResourceModel\Item\Option\CollectionFactory;
150 \
Magento\Framework\Stdlib\DateTime\DateTime $date,
152 OptionFactory $wishlistOptFactory,
153 CollectionFactory $wishlOptionCollectionFactory,
161 $this->productTypeConfig = $productTypeConfig;
163 $this->_date = $date;
164 $this->_catalogUrl = $catalogUrl;
165 $this->_wishlistOptFactory = $wishlistOptFactory;
166 $this->_wishlOptionCollectionFactory = $wishlOptionCollectionFactory;
191 $this->
setData(
'qty', $qty >= 0 ? $qty : 1);
204 $skipOptions = [
'id',
'qty',
'return_url'];
206 if (in_array(
$code, $skipOptions)) {
225 if (!isset($this->_optionsByCode[
$option->getCode()])) {
228 throw new \Magento\Framework\Exception\LocalizedException(
229 __(
'An item option with code %1 already exists.',
$option->getCode())
260 unset($this->_options[
$index]);
261 unset($this->_optionsByCode[
$option->getCode()]);
267 $this->_flagOptionsSaved =
true;
281 $this->_flagOptionsSaved = $flag;
302 return parent::afterSave();
313 if (!$this->getWishlistId()) {
314 throw new \Magento\Framework\Exception\LocalizedException(
__(
'We can\'t specify a wish list.'));
316 if (!$this->getProductId()) {
317 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Cannot specify product.'));
330 parent::beforeSave();
336 if ($this->getStoreId() ===
null) {
337 $this->setStoreId($this->_storeManager->getStore()->getId());
341 if ($this->getAddedAt() ===
null) {
342 $this->setAddedAt($this->_date->gmtDate());
375 if (!$this->getProductId()) {
376 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Cannot specify product.'));
379 $product = $this->productRepository->getById($this->getProductId(),
false, $this->getStoreId(),
true);
381 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Cannot specify product.'), $e);
390 $product->setCustomOptions($this->_optionsByCode);
411 if (
$product->getStatus() != \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
415 if (!
$product->isVisibleInSiteVisibility()) {
419 $urlData = $this->_catalogUrl->getRewriteByProductStore([
$product->getId() =>
$storeId]);
420 if (!isset($urlData[
$product->getId()])) {
424 $visibility =
$product->getUrlDataObject()->getVisibility();
425 if (!in_array($visibility,
$product->getVisibleInSiteVisibilities())) {
431 throw new ProductException(
__(
'Product is not salable.'));
437 if (!
$product->isVisibleInSiteVisibility()) {
461 $query[
'options'] =
'cart';
476 $initialData =
$option ? $this->serializer->unserialize(
$option->getValue()) : [];
479 $initialData = $initialData->getData();
482 $buyRequest = new \Magento\Framework\DataObject($initialData);
504 $sBuyRequest = $this->serializer->serialize(
$buyRequest + $oldBuyRequest);
508 $option->setValue($sBuyRequest);
510 $this->
addOption([
'code' =>
'info_buyRequest',
'value' => $sBuyRequest]);
527 $_buyRequest = $this->serializer->serialize(
$buyRequest->getData());
528 $this->
setData(
'buy_request', $_buyRequest);
541 if ($this->getProductId() !=
$product->getId()) {
578 if ($itemProduct->getId() !=
$product->getId()) {
605 foreach ($options1 as
$option) {
607 if (in_array(
$code, $this->_notRepresentOptions)) {
610 if (!isset($options2[
$code]) || $options2[
$code]->getValue() !=
$option->getValue()) {
661 $option = $this->_wishlistOptFactory->create()->setData(
$option)->setItem($this);
665 $option = $this->_wishlistOptFactory->create()->setData(
$option->getData())
669 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Invalid item option format.'));
674 $exOption->addData(
$option->getData());
706 return $this->_optionsByCode[
$code];
719 return !$this->productTypeConfig->isProductSet(
$product->getTypeId());
729 return $this->_customOptionDownloadUrl;
740 $this->_customOptionDownloadUrl =
$url;
753 $params = new \Magento\Framework\DataObject();
754 $params->setUrl($this->_customOptionDownloadUrl);
771 if (!$this->
getId()) {
775 $options = $this->_wishlOptionCollectionFactory->create()->addItemFilter($this);
776 if ($optionsFilter) {
777 $options->addFieldToFilter(
'code', $optionsFilter);
$_wishlOptionCollectionFactory
loadWithOptions($id, $optionsFilter=null)
compareOptions($options1, $options2)
elseif(isset( $params[ 'redirect_parent']))
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\DateTime\DateTime $date, \Magento\Catalog\Model\ResourceModel\Url $catalogUrl, OptionFactory $wishlistOptFactory, CollectionFactory $wishlOptionCollectionFactory, \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig, ProductRepositoryInterface $productRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Framework\Serialize\Serializer\Json $serializer=null)
isRepresent($product, $buyRequest)
load($modelId, $field=null)
$_customOptionDownloadUrl
setBuyRequest($buyRequest)
representProduct($product)
setOrigData($key=null, $data=null)
_compareOptions($options1, $options2)
loadByProductWishlist($wishlistId, $productId, $sharedStores)
mergeBuyRequest($buyRequest)
compareOptions($options1, $options2)
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest
setCustomDownloadUrl($url)
setData($key, $value=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
addToCart(\Magento\Checkout\Model\Cart $cart, $delete=false)
isDeleted($isDeleted=null)