/**
  * Get customer wishlist model instance
  *
  * @param   int $customerId
  * @return  Wishlist|false
  */
 protected function getWishlist($customerId)
 {
     if (!$customerId) {
         return false;
     }
     return $this->wishlistFactory->create()->loadByCustomerId($customerId, true);
 }
 /**
  * If it's configured to capture on shipment - do this.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $object = $observer->getEvent()->getDataObject();
     $wishlist = $this->wishlist->create()->load($object->getWishlistId());
     $emailWishlist = $this->wishlistFactory->create();
     try {
         if ($object->getWishlistId()) {
             $itemCount = count($wishlist->getItemCollection());
             $item = $emailWishlist->getWishlist($object->getWishlistId());
             if ($item && $item->getId()) {
                 $preSaveItemCount = $item->getItemCount();
                 if ($itemCount != $item->getItemCount()) {
                     $item->setItemCount($itemCount);
                 }
                 if ($itemCount == 1 && $preSaveItemCount == 0) {
                     $item->setWishlistImported(null);
                 } elseif ($item->getWishlistImported()) {
                     $item->setWishlistModified(1);
                 }
                 $item->save();
             }
         }
     } catch (\Exception $e) {
         $this->helper->debug((string) $e, []);
     }
     return $this;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $row = $data;
             /** @var \Magento\Customer\Model\Customer $customer */
             $customer = $this->helper->getCustomerByEmail($row['customer_email']);
             if (!$customer) {
                 continue;
             }
             /** @var \Magento\Wishlist\Model\Wishlist $wishlist */
             $wishlist = $this->wishlistFactory->create();
             $wishlist->loadByCustomerId($customer->getId(), true);
             if (!$wishlist->getId()) {
                 continue;
             }
             $productSkuList = explode("\n", $row['product_list']);
             $this->helper->addProductsToWishlist($wishlist, $productSkuList);
         }
     }
 }
예제 #4
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getWishlist($wishlistId = null)
 {
     if ($this->wishlist) {
         return $this->wishlist;
     }
     try {
         if (!$wishlistId) {
             $wishlistId = $this->request->getParam('wishlist_id');
         }
         $customerId = $this->customerSession->getCustomerId();
         $wishlist = $this->wishlistFactory->create();
         if (!$wishlistId && !$customerId) {
             return $wishlist;
         }
         if ($wishlistId) {
             $wishlist->load($wishlistId);
         } elseif ($customerId) {
             $wishlist->loadByCustomerId($customerId, true);
         }
         if (!$wishlist->getId() || $wishlist->getCustomerId() != $customerId) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('The requested Wish List doesn\'t exist.'));
         }
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $this->messageManager->addError($e->getMessage());
         return false;
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('We can\'t create the Wish List right now.'));
         return false;
     }
     $this->wishlist = $wishlist;
     return $wishlist;
 }
 public function setUp()
 {
     $this->helper = $this->getMockBuilder('Magento\\Wishlist\\Helper\\Data')->disableOriginalConstructor()->getMock();
     $this->wishlistFactory = $this->getMockBuilder('Magento\\Wishlist\\Model\\WishlistFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistFactory->expects($this->any())->method('create')->willReturn($this->wishlist);
     $this->observer = new Observer($this->helper, $this->wishlistFactory);
 }
예제 #6
0
 protected function setUp()
 {
     $this->checkoutSession = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->setMethods(['getSharedWishlist', 'getWishlistPendingMessages', 'getWishlistPendingUrls', 'getWishlistIds', 'getSingleWishlistId', 'setSingleWishlistId', 'setWishlistIds', 'setWishlistPendingUrls', 'setWishlistPendingMessages', 'setNoCartRedirect'])->disableOriginalConstructor()->getMock();
     $this->customerSession = $this->getMockBuilder('Magento\\Customer\\Model\\Session')->disableOriginalConstructor()->setMethods(['setWishlistItemCount', 'isLoggedIn', 'getCustomerId'])->getMock();
     $this->wishlistFactory = $this->getMockBuilder('Magento\\Wishlist\\Model\\WishlistFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->messageManager = $this->getMockBuilder('Magento\\Framework\\Message\\ManagerInterface')->getMock();
     $this->wishlistFactory->expects($this->any())->method('create')->willReturn($this->wishlist);
     $this->observer = new Observer($this->checkoutSession, $this->customerSession, $this->wishlistFactory, $this->messageManager);
 }
예제 #7
0
 public function testGetWishlistWithIdWithoutCustomer()
 {
     $wishlist = $this->getMock('\\Magento\\Wishlist\\Model\\Wishlist', ['loadByCustomerId', 'load', 'getId', 'getCustomerId', '__wakeup'], [], '', false);
     $wishlist->expects($this->once())->method('load')->will($this->returnSelf());
     $wishlist->expects($this->any())->method('getId')->will($this->returnValue(1));
     $wishlist->expects($this->once())->method('getCustomerId')->will($this->returnValue(1));
     $this->wishlistFactory->expects($this->once())->method('create')->will($this->returnValue($wishlist));
     $this->request->expects($this->once())->method('getParam')->will($this->returnValue(1));
     $this->assertEquals(false, $this->wishlistProvider->getWishlist());
 }
 /**
  * If it's configured to capture on shipment - do this.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     //wishlist
     $wishlist = $observer->getEvent()->getObject()->getData();
     //required data for checking the new instance of wishlist with items in it.
     if (is_array($wishlist) && isset($wishlist['customer_id']) && isset($wishlist['wishlist_id'])) {
         $wishlistModel = $this->wishlist->create()->load($wishlist['wishlist_id']);
         $itemsCount = $wishlistModel->getItemsCount();
         //wishlist items found
         if ($itemsCount) {
             //save wishlist info in the table
             $this->registerWishlist($wishlist);
         }
     }
 }
예제 #9
0
 public function testGetWishlistWithCustomerId()
 {
     $customerId = 1;
     $data = $customerId . ',2';
     $wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistFactoryMock->expects($this->once())->method('create')->willReturn($wishlist);
     $this->requestMock->expects($this->at(0))->method('getParam')->with('wishlist_id', null)->willReturn('');
     $this->urlDecoderMock->expects($this->any())->method('decode')->willReturnArgument(0);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('data', null)->willReturn($data);
     $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn(0);
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerFactoryMock->expects($this->once())->method('create')->willReturn($customer);
     $this->customerRepositoryMock->expects($this->never())->method('getById');
     $customer->expects($this->exactly(2))->method('getId')->willReturn($customerId);
     $wishlist->expects($this->once())->method('loadByCustomerId')->with($customerId, false)->willReturnSelf();
     $this->assertEquals($wishlist, $this->model->getWishlist());
 }
 /**
  * Retrieve current wishlist
  * @param string $wishlistId
  * @return \Magento\Wishlist\Model\Wishlist
  */
 public function getWishlist($wishlistId = null)
 {
     if ($this->wishlist) {
         return $this->wishlist;
     }
     $code = (string) $this->request->getParam('code');
     if (empty($code)) {
         return false;
     }
     $wishlist = $this->wishlistFactory->create()->loadByCode($code);
     if (!$wishlist->getId()) {
         return false;
     }
     $this->checkoutSession->setSharedWishlist($code);
     $this->wishlist = $wishlist;
     return $wishlist;
 }
 /**
  * @return bool|\Magento\Framework\DataObject
  */
 public function _getWishlist()
 {
     $customerId = $this->getRequest()->getParam('customer_id');
     if (!$customerId) {
         return false;
     }
     $customer = $this->customerFactory->create()->load($customerId);
     if (!$customer->getId()) {
         return false;
     }
     $collection = $this->wishlistFactory->create()->getCollection()->addFieldToFilter('customer_id', $customerId)->setOrder('updated_at', 'DESC')->setPageSize(1);
     if ($collection->getSize()) {
         //@codingStandardsIgnoreStart
         return $collection->getFirstItem();
         //@codingStandardsIgnoreEnd
     } else {
         return false;
     }
 }
예제 #12
0
 /**
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(Observer $observer)
 {
     $request = $observer->getEvent()->getRequest();
     $sharedWishlist = $this->checkoutSession->getSharedWishlist();
     $messages = $this->checkoutSession->getWishlistPendingMessages();
     $urls = $this->checkoutSession->getWishlistPendingUrls();
     $wishlistIds = $this->checkoutSession->getWishlistIds();
     $singleWishlistId = $this->checkoutSession->getSingleWishlistId();
     if ($singleWishlistId) {
         $wishlistIds = [$singleWishlistId];
     }
     if (count($wishlistIds) && $request->getParam('wishlist_next')) {
         $wishlistId = array_shift($wishlistIds);
         if ($this->customerSession->isLoggedIn()) {
             $wishlist = $this->wishlistFactory->create()->loadByCustomerId($this->customerSession->getCustomerId(), true);
         } elseif ($sharedWishlist) {
             $wishlist = $this->wishlistFactory->create()->loadByCode($sharedWishlist);
         } else {
             return;
         }
         $wishlists = $wishlist->getItemCollection()->load();
         foreach ($wishlists as $wishlistItem) {
             if ($wishlistItem->getId() == $wishlistId) {
                 $wishlistItem->delete();
             }
         }
         $this->checkoutSession->setWishlistIds($wishlistIds);
         $this->checkoutSession->setSingleWishlistId(null);
     }
     if ($request->getParam('wishlist_next') && count($urls)) {
         $url = array_shift($urls);
         $message = array_shift($messages);
         $this->checkoutSession->setWishlistPendingUrls($urls);
         $this->checkoutSession->setWishlistPendingMessages($messages);
         $this->messageManager->addError($message);
         $observer->getEvent()->getResponse()->setRedirect($url);
         $this->checkoutSession->setNoCartRedirect(true);
     }
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing wishlists:');
     $fixtureFile = 'Wishlist/wishlist.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\Tools\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         /** @var \Magento\Customer\Model\Customer $customer */
         $customer = $this->wishlistHelper->getCustomerByEmail($row['customer_email']);
         if (!$customer) {
             continue;
         }
         /** @var \Magento\Wishlist\Model\Wishlist $wishlist */
         $wishlist = $this->wishlistFactory->create();
         $wishlist->loadByCustomerId($customer->getId(), true);
         if (!$wishlist->getId()) {
             continue;
         }
         $productSkuList = explode("\n", $row['product_list']);
         $this->wishlistHelper->addProductsToWishlist($wishlist, $productSkuList);
         $this->logger->logInline('.');
     }
 }
 /**
  * Export single wishilist for website.
  *
  * @param \Magento\Store\Model\Website $website
  */
 public function exportWishlistForWebsiteInSingle(\Magento\Store\Model\Website $website)
 {
     //transactional data limit
     $limit = $this->helper->getWebsiteConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
     $collection = $this->getModifiedWishlistToImport($website, $limit);
     $this->wishlistIds = [];
     //email_wishlist wishlist ids
     $wishlistIds = $collection->getColumnValues('wishlist_id');
     $wishlistCollection = $this->wishlist->create()->getCollection()->addFieldToFilter('wishlist_id', ['in' => $wishlistIds]);
     $wishlistCollection->getSelect()->joinLeft(['c' => $this->resource->getTableName('customer_entity')], 'c.entity_id = customer_id', ['email', 'store_id']);
     foreach ($wishlistCollection as $wishlist) {
         $wishlistId = $wishlist->getid();
         $wishlistItems = $wishlist->getItemCollection();
         $connectorWishlist = $this->wishlistFactory->create();
         $connectorWishlist->setId($wishlistId)->setUpdatedAt($wishlist->getUpdatedAt())->setCustomerId($wishlist->getCustomerId())->setEmail($wishlist->getEmail());
         if ($wishlistItems->getSize()) {
             foreach ($wishlistItems as $item) {
                 $product = $item->getProduct();
                 $wishlistItem = $this->itemFactory->create()->setProduct($product)->setQty($item->getQty())->setPrice($product);
                 //store for wishlists
                 $connectorWishlist->setItem($wishlistItem);
                 $this->countWishlists++;
             }
             //send wishlist as transactional data
             $this->start = microtime(true);
             //register in queue with importer
             $check = $this->importerFactory->create()->registerQueue(Importer::IMPORT_TYPE_WISHLIST, $connectorWishlist, Importer::MODE_SINGLE, $website->getId());
             if ($check) {
                 $this->wishlistIds[] = $wishlistId;
             }
         } else {
             //register in queue with importer
             $check = $this->importerFactory->create()->registerQueue(Importer::IMPORT_TYPE_WISHLIST, [$wishlist->getId()], Importer::MODE_SINGLE, $website->getId());
             if ($check) {
                 $this->wishlistIds[] = $wishlistId;
             }
         }
     }
     if (!empty($this->wishlistIds)) {
         $this->setImported($this->wishlistIds, true);
     }
 }
예제 #15
0
파일: Grid.php 프로젝트: nja78/magento2
 /**
  * Retrieve collection of customer wishlists
  *
  * @return \Magento\Wishlist\Model\Resource\Wishlist\Collection
  */
 public function getCustomerWishlists()
 {
     return $this->_wishlistFactory->create()->getCollection()->filterByCustomerId($this->getCustomerId());
 }
예제 #16
0
 /**
  * @return Wishlist
  */
 protected function _createWishList()
 {
     return $this->_wishListFactory->create();
 }
예제 #17
0
 /**
  * Retrieve wishlist by logged in customer
  *
  * @return \Magento\Wishlist\Model\Wishlist
  */
 public function getWishlist()
 {
     if (is_null($this->_wishlist)) {
         if ($this->_coreRegistry->registry('shared_wishlist')) {
             $this->_wishlist = $this->_coreRegistry->registry('shared_wishlist');
         } else {
             $this->_wishlist = $this->wishlistProvider->getWishlist();
             if (!$this->_wishlist) {
                 $this->_wishlist = $this->_wishlistFactory->create();
                 if ($this->getCustomer()) {
                     $this->_wishlist->loadByCustomerId($this->getCustomer()->getId());
                 }
             }
         }
     }
     return $this->_wishlist;
 }