本文整理汇总了PHP中Magento\Wishlist\Controller\WishlistProviderInterface类的典型用法代码示例。如果您正苦于以下问题:PHP WishlistProviderInterface类的具体用法?PHP WishlistProviderInterface怎么用?PHP WishlistProviderInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WishlistProviderInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Add cart item to wishlist and remove from cart
*
* @return \Zend_Controller_Response_Abstract
* @throws NotFoundException
*/
public function execute()
{
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
throw new NotFoundException();
}
$itemId = (int) $this->getRequest()->getParam('item');
/* @var \Magento\Checkout\Model\Cart $cart */
$cart = $this->_objectManager->get('Magento\\Checkout\\Model\\Cart');
$session = $this->_objectManager->get('Magento\\Checkout\\Model\\Session');
try {
$item = $cart->getQuote()->getItemById($itemId);
if (!$item) {
throw new \Magento\Framework\Model\Exception(__("The requested cart item doesn't exist."));
}
$productId = $item->getProductId();
$buyRequest = $item->getBuyRequest();
$wishlist->addNewItem($productId, $buyRequest);
$productIds[] = $productId;
$cart->getQuote()->removeItem($itemId);
$cart->save();
$this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
$productName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($item->getProduct()->getName());
$wishlistName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($wishlist->getName());
$this->messageManager->addSuccess(__("%1 has been moved to wish list %2", $productName, $wishlistName));
$wishlist->save();
} catch (\Magento\Framework\Model\Exception $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t move the item to the wish list.'));
}
return $this->getResponse()->setRedirect($this->_objectManager->get('Magento\\Checkout\\Helper\\Cart')->getCartUrl());
}
开发者ID:aiesh,项目名称:magento2,代码行数:39,代码来源:Fromcart.php
示例2: execute
/**
* Remove item
*
* @return void
* @throws NotFoundException
*/
public function execute()
{
$id = (int) $this->getRequest()->getParam('item');
$item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($id);
if (!$item->getId()) {
throw new NotFoundException();
}
$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist) {
throw new NotFoundException();
}
try {
$item->delete();
$wishlist->save();
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError(__('An error occurred while deleting the item from wish list: %1', $e->getMessage()));
} catch (\Exception $e) {
$this->messageManager->addError(__('An error occurred while deleting the item from wish list.'));
}
$this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
$request = $this->getRequest();
$refererUrl = (string) $request->getServer('HTTP_REFERER');
$url = (string) $request->getParam(\Magento\Framework\App\Response\RedirectInterface::PARAM_NAME_REFERER_URL);
if ($url) {
$refererUrl = $url;
}
if ($request->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED) && $refererUrl) {
$redirectUrl = $refererUrl;
} else {
$redirectUrl = $this->_redirect->getRedirectUrl($this->_url->getUrl('*/*'));
}
$this->getResponse()->setRedirect($redirectUrl);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:39,代码来源:Remove.php
示例3: execute
/**
* Add cart item to wishlist and remove from cart
*
* @return \Magento\Framework\Controller\Result\Redirect
* @throws NotFoundException
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function execute()
{
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
throw new NotFoundException(__('Page not found.'));
}
try {
$itemId = (int) $this->getRequest()->getParam('item');
$item = $this->cart->getQuote()->getItemById($itemId);
if (!$item) {
throw new LocalizedException(__('The requested cart item doesn\'t exist.'));
}
$productId = $item->getProductId();
$buyRequest = $item->getBuyRequest();
$wishlist->addNewItem($productId, $buyRequest);
$this->cart->getQuote()->removeItem($itemId);
$this->cart->save();
$this->wishlistHelper->calculate();
$wishlist->save();
$this->messageManager->addSuccessMessage(__("%1 has been moved to your wish list.", $this->escaper->escapeHtml($item->getProduct()->getName())));
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addExceptionMessage($e, __('We can\'t move the item to the wish list.'));
}
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setUrl($this->cartHelper->getCartUrl());
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:36,代码来源:Fromcart.php
示例4: execute
/**
* Add cart item to wishlist and remove from cart
*
* @return \Magento\Framework\Controller\Result\Redirect
* @throws NotFoundException
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function execute()
{
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
throw new NotFoundException(__('Page not found.'));
}
$itemId = (int) $this->getRequest()->getParam('item');
/* @var \Magento\Checkout\Model\Cart $cart */
$cart = $this->_objectManager->get('Magento\\Checkout\\Model\\Cart');
$this->_objectManager->get('Magento\\Checkout\\Model\\Session');
$item = $cart->getQuote()->getItemById($itemId);
if (!$item) {
throw new \Magento\Framework\Exception\LocalizedException(__('The requested cart item doesn\'t exist.'));
}
$productId = $item->getProductId();
$buyRequest = $item->getBuyRequest();
$wishlist->addNewItem($productId, $buyRequest);
$productIds[] = $productId;
$cart->getQuote()->removeItem($itemId);
$cart->save();
$this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
$productName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($item->getProduct()->getName());
$wishlistName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($wishlist->getName());
$this->messageManager->addSuccess(__("%1 has been moved to wish list %2", $productName, $wishlistName));
$wishlist->save();
return $this->getDefaultResult();
}
开发者ID:opexsw,项目名称:magento2,代码行数:35,代码来源:Fromcart.php
示例5: execute
/**
* Display customer wishlist
*
* @return void
* @throws NotFoundException
*/
public function execute()
{
if (!$this->wishlistProvider->getWishlist()) {
throw new NotFoundException();
}
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:Index.php
示例6: execute
/**
* Display customer wishlist
*
* @return \Magento\Framework\View\Result\Page
* @throws NotFoundException
*/
public function execute()
{
if (!$this->wishlistProvider->getWishlist()) {
throw new NotFoundException(__('Page not found.'));
}
/** @var \Magento\Framework\View\Result\Page resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
return $resultPage;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Index.php
示例7: executeInternal
/**
* Action to accept new configuration for a wishlist item
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function executeInternal()
{
$productId = (int)$this->getRequest()->getParam('product');
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
if (!$productId) {
$resultRedirect->setPath('*/');
return $resultRedirect;
}
try {
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
$product = null;
}
if (!$product || !$product->isVisibleInCatalog()) {
$this->messageManager->addError(__('We can\'t specify a product.'));
$resultRedirect->setPath('*/');
return $resultRedirect;
}
try {
$id = (int)$this->getRequest()->getParam('id');
/* @var \Magento\Wishlist\Model\Item */
$item = $this->_objectManager->create('Magento\Wishlist\Model\Item');
$item->load($id);
$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist) {
$resultRedirect->setPath('*/');
return $resultRedirect;
}
$buyRequest = new \Magento\Framework\DataObject($this->getRequest()->getParams());
$wishlist->updateItem($id, $buyRequest)->save();
$this->_objectManager->get('Magento\Wishlist\Helper\Data')->calculate();
$this->_eventManager->dispatch(
'wishlist_update_item',
['wishlist' => $wishlist, 'product' => $product, 'item' => $wishlist->getItem($id)]
);
$this->_objectManager->get('Magento\Wishlist\Helper\Data')->calculate();
$message = __('%1 has been updated in your Wish List.', $product->getName());
$this->messageManager->addSuccess($message);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('We can\'t update your Wish List right now.'));
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
}
$resultRedirect->setPath('*/*', ['wishlist_id' => $wishlist->getId()]);
return $resultRedirect;
}
开发者ID:nblair,项目名称:magescotch,代码行数:61,代码来源:UpdateItemOptions.php
示例8: executeInternal
/**
* Action to reconfigure wishlist item
*
* @return \Magento\Framework\Controller\ResultInterface
* @throws NotFoundException
*/
public function executeInternal()
{
$id = (int)$this->getRequest()->getParam('id');
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
try {
/* @var $item \Magento\Wishlist\Model\Item */
$item = $this->_objectManager->create('Magento\Wishlist\Model\Item');
$item->loadWithOptions($id);
if (!$item->getId()) {
throw new \Magento\Framework\Exception\LocalizedException(
__('We can\'t load the Wish List item right now.')
);
}
$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist) {
throw new NotFoundException(__('Page not found.'));
}
$this->_coreRegistry->register('wishlist_item', $item);
$params = new \Magento\Framework\DataObject();
$params->setCategoryId(false);
$params->setConfigureMode(true);
$buyRequest = $item->getBuyRequest();
if (!$buyRequest->getQty() && $item->getQty()) {
$buyRequest->setQty($item->getQty());
}
if ($buyRequest->getQty() && !$item->getQty()) {
$item->setQty($buyRequest->getQty());
$this->_objectManager->get('Magento\Wishlist\Helper\Data')->calculate();
}
$params->setBuyRequest($buyRequest);
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$this->_objectManager->get(
'Magento\Catalog\Helper\Product\View'
)->prepareAndRender(
$resultPage,
$item->getProductId(),
$this,
$params
);
return $resultPage;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$resultRedirect->setPath('*');
return $resultRedirect;
} catch (\Exception $e) {
$this->messageManager->addError(__('We can\'t configure the product right now.'));
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
$resultRedirect->setPath('*');
return $resultRedirect;
}
}
开发者ID:nblair,项目名称:magescotch,代码行数:62,代码来源:Configure.php
示例9: execute
/**
* Adding new item
*
* @return \Magento\Framework\Controller\Result\Redirect
* @throws NotFoundException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
if (!$this->formKeyValidator->validate($this->getRequest())) {
return $resultRedirect->setPath('*/');
}
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
throw new NotFoundException(__('Page not found.'));
}
$session = $this->_customerSession;
$requestParams = $this->getRequest()->getParams();
if ($session->getBeforeWishlistRequest()) {
$requestParams = $session->getBeforeWishlistRequest();
$session->unsBeforeWishlistRequest();
}
$productId = isset($requestParams['product']) ? (int) $requestParams['product'] : null;
if (!$productId) {
$resultRedirect->setPath('*/');
return $resultRedirect;
}
try {
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
$product = null;
}
if (!$product || !$product->isVisibleInCatalog()) {
$this->messageManager->addErrorMessage(__('We can\'t specify a product.'));
$resultRedirect->setPath('*/');
return $resultRedirect;
}
try {
$buyRequest = new \Magento\Framework\DataObject($requestParams);
$result = $wishlist->addNewItem($product, $buyRequest);
if (is_string($result)) {
throw new \Magento\Framework\Exception\LocalizedException(__($result));
}
$wishlist->save();
$this->_eventManager->dispatch('wishlist_add_product', ['wishlist' => $wishlist, 'product' => $product, 'item' => $result]);
$referer = $session->getBeforeWishlistUrl();
if ($referer) {
$session->setBeforeWishlistUrl(null);
} else {
$referer = $this->_redirect->getRefererUrl();
}
$this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
$this->messageManager->addComplexSuccessMessage('addProductSuccessMessage', ['product_name' => $product->getName(), 'referer' => $referer]);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addErrorMessage(__('We can\'t add the item to Wish List right now: %1.', $e->getMessage()));
} catch (\Exception $e) {
$this->messageManager->addExceptionMessage($e, __('We can\'t add the item to Wish List right now.'));
}
$resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]);
return $resultRedirect;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:65,代码来源:Add.php
示例10: execute
/**
* Adding new item
*
* @return \Magento\Framework\Controller\Result\Redirect
* @throws NotFoundException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function execute()
{
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
throw new NotFoundException(__('Page not found.'));
}
$session = $this->_customerSession;
$requestParams = $this->getRequest()->getParams();
if ($session->getBeforeWishlistRequest()) {
$requestParams = $session->getBeforeWishlistRequest();
$session->unsBeforeWishlistRequest();
}
$productId = isset($requestParams['product']) ? (int) $requestParams['product'] : null;
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
if (!$productId) {
$resultRedirect->setPath('*/');
return $resultRedirect;
}
try {
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
$product = null;
}
if (!$product || !$product->isVisibleInCatalog()) {
$this->messageManager->addError(__('We can\'t specify a product.'));
$resultRedirect->setPath('*/');
return $resultRedirect;
}
try {
$buyRequest = new \Magento\Framework\Object($requestParams);
$result = $wishlist->addNewItem($product, $buyRequest);
if (is_string($result)) {
throw new \Magento\Framework\Exception\LocalizedException(__($result));
}
$wishlist->save();
$this->_eventManager->dispatch('wishlist_add_product', ['wishlist' => $wishlist, 'product' => $product, 'item' => $result]);
$referer = $session->getBeforeWishlistUrl();
if ($referer) {
$session->setBeforeWishlistUrl(null);
} else {
$referer = $this->_redirect->getRefererUrl();
}
$this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
$message = __('%1 has been added to your wishlist. Click <a href="%2">here</a> to continue shopping.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getName()), $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeUrl($referer));
$this->messageManager->addSuccess($message);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError(__('An error occurred while adding item to wish list: %1', $e->getMessage()));
} catch (\Exception $e) {
$this->messageManager->addError(__('An error occurred while adding item to wish list.'));
$this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
}
$resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]);
return $resultRedirect;
}
开发者ID:opexsw,项目名称:magento2,代码行数:64,代码来源:Add.php
示例11: execute
/**
* Adding new item
*
* @return void
* @throws NotFoundException
*/
public function execute()
{
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
throw new NotFoundException();
}
$session = $this->_customerSession;
$requestParams = $this->getRequest()->getParams();
if ($session->getBeforeWishlistRequest()) {
$requestParams = $session->getBeforeWishlistRequest();
$session->unsBeforeWishlistRequest();
}
$productId = isset($requestParams['product']) ? (int) $requestParams['product'] : null;
if (!$productId) {
$this->_redirect('*/');
return;
}
$product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->load($productId);
if (!$product->getId() || !$product->isVisibleInCatalog()) {
$this->messageManager->addError(__('We can\'t specify a product.'));
$this->_redirect('*/');
return;
}
try {
$buyRequest = new \Magento\Framework\Object($requestParams);
$result = $wishlist->addNewItem($product, $buyRequest);
if (is_string($result)) {
throw new \Magento\Framework\Model\Exception($result);
}
$wishlist->save();
$this->_eventManager->dispatch('wishlist_add_product', array('wishlist' => $wishlist, 'product' => $product, 'item' => $result));
$referer = $session->getBeforeWishlistUrl();
if ($referer) {
$session->setBeforeWishlistUrl(null);
} else {
$referer = $this->_redirect->getRefererUrl();
}
/**
* Set referer to avoid referring to the compare popup window
*/
$session->setAddActionReferer($referer);
/** @var $helper \Magento\Wishlist\Helper\Data */
$helper = $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
$message = __('%1 has been added to your wishlist. Click <a href="%2">here</a> to continue shopping.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getName()), $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeUrl($referer));
$this->messageManager->addSuccess($message);
} catch (\Magento\Framework\Model\Exception $e) {
$this->messageManager->addError(__('An error occurred while adding item to wish list: %1', $e->getMessage()));
} catch (\Exception $e) {
$this->messageManager->addError(__('An error occurred while adding item to wish list.'));
$this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
}
$this->_redirect('*', array('wishlist_id' => $wishlist->getId()));
}
开发者ID:aiesh,项目名称:magento2,代码行数:59,代码来源:Add.php
示例12: execute
/**
* Add all items from wishlist to shopping cart
*
* @return void
*/
public function execute()
{
if (!$this->formKeyValidator->validate($this->getRequest())) {
$this->_forward('noroute');
return;
}
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
$this->_forward('noroute');
return;
}
$redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty'));
$this->getResponse()->setRedirect($redirectUrl);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Allcart.php
示例13: testExecutePassed
public function testExecutePassed()
{
$url = 'http://redirect-url.com';
$wishlist = $this->getMock('Magento\Wishlist\Model\Wishlist', [], [], '', false);
$this->formKeyValidator->expects($this->once())
->method('validate')
->with($this->request)
->will($this->returnValue(true));
$this->request->expects($this->once())
->method('getParam')
->with('qty')
->will($this->returnValue(2));
$this->wishlistProvider->expects($this->once())
->method('getWishlist')
->will($this->returnValue($wishlist));
$this->itemCarrier->expects($this->once())
->method('moveAllToCart')
->with($wishlist, 2)
->willReturn($url);
$this->resultRedirectMock->expects($this->once())
->method('setUrl')
->with($url)
->willReturnSelf();
$this->assertSame($this->resultRedirectMock, $this->getController()->executeInternal());
}
开发者ID:nblair,项目名称:magescotch,代码行数:27,代码来源:AllcartTest.php
示例14: execute
/**
* Add wishlist item to shopping cart and remove from wishlist
*
* If Product has required options - item removed from wishlist and redirect
* to product view page with message about needed defined required options
*
* @return ResponseInterface
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function execute()
{
$itemId = (int) $this->getRequest()->getParam('item');
/* @var $item \Magento\Wishlist\Model\Item */
$item = $this->itemFactory->create()->load($itemId);
if (!$item->getId()) {
return $this->_redirect('*/*');
}
$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist) {
return $this->_redirect('*/*');
}
// Set qty
$qty = $this->getRequest()->getParam('qty');
if (is_array($qty)) {
if (isset($qty[$itemId])) {
$qty = $qty[$itemId];
} else {
$qty = 1;
}
}
$qty = $this->quantityProcessor->process($qty);
if ($qty) {
$item->setQty($qty);
}
$redirectUrl = $this->_url->getUrl('*/*');
$configureUrl = $this->_url->getUrl('*/*/configure/', ['id' => $item->getId(), 'product_id' => $item->getProductId()]);
try {
/** @var \Magento\Wishlist\Model\Resource\Item\Option\Collection $options */
$options = $this->optionFactory->create()->getCollection()->addItemFilter([$itemId]);
$item->setOptions($options->getOptionsByItem($itemId));
$buyRequest = $this->productHelper->addParamsToBuyRequest($this->getRequest()->getParams(), ['current_config' => $item->getBuyRequest()]);
$item->mergeBuyRequest($buyRequest);
$item->addToCart($this->cart, true);
$this->cart->save()->getQuote()->collectTotals();
$wishlist->save();
if (!$this->cart->getQuote()->getHasError()) {
$message = __('You added %1 to your shopping cart.', $this->escaper->escapeHtml($item->getProduct()->getName()));
$this->messageManager->addSuccess($message);
}
if ($this->cart->getShouldRedirectToCart()) {
$redirectUrl = $this->cart->getCartUrl();
} else {
$refererUrl = $this->_redirect->getRefererUrl();
if ($refererUrl && $refererUrl != $configureUrl) {
$redirectUrl = $refererUrl;
}
}
} catch (ProductException $e) {
$this->messageManager->addError(__('This product(s) is out of stock.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addNotice($e->getMessage());
$redirectUrl = $configureUrl;
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Cannot add item to shopping cart'));
}
$this->helper->calculate();
return $this->getResponse()->setRedirect($redirectUrl);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:69,代码来源:Cart.php
示例15: execute
/**
* Wishlist rss feed action
* Show all public wishlists and private wishlists that belong to current user
*
* @return void
*/
public function execute()
{
if (!$this->rssWishlistHelper->isRssAllow()) {
$this->_forward('noroute');
return;
}
/** @var \Magento\Wishlist\Model\Wishlist $wishlist */
$wishlist = $this->wishlistProvider->getWishlist();
if ($wishlist && ($wishlist->getVisibility() || $this->customerSession->authenticate($this) && $wishlist->getCustomerId() == $this->rssWishlistHelper->getCustomer()->getId())) {
$this->getResponse()->setHeader('Content-Type', 'text/xml; charset=UTF-8');
$this->_view->loadLayout(false);
$this->_view->renderLayout();
return;
}
/** @var \Magento\Rss\Helper\Data $rssHelper */
$rssHelper = $this->rssHelperFactory->create();
$rssHelper->sendEmptyRssFeed($this->getResponse());
}
开发者ID:aiesh,项目名称:magento2,代码行数:24,代码来源:Rss.php
示例16: execute
/**
* Display customer wishlist
*
* @return void
* @throws NotFoundException
*/
public function execute()
{
if (!$this->wishlistProvider->getWishlist()) {
throw new NotFoundException();
}
$this->_view->loadLayout();
$session = $this->_customerSession;
$block = $this->_view->getLayout()->getBlock('customer.wishlist');
$referer = $session->getAddActionReferer(true);
if ($block) {
$block->setRefererUrl($this->_redirect->getRefererUrl());
if ($referer) {
$block->setRefererUrl($referer);
}
}
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
}
开发者ID:aiesh,项目名称:magento2,代码行数:24,代码来源:Index.php
示例17: execute
/**
* Add all items from wishlist to shopping cart
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
if (!$this->formKeyValidator->validate($this->getRequest())) {
$resultForward->forward('noroute');
return $resultForward;
}
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
$resultForward->forward('noroute');
return $resultForward;
}
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty'));
$resultRedirect->setUrl($redirectUrl);
return $resultRedirect;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:24,代码来源:Allcart.php
示例18: testExecutePassed
public function testExecutePassed()
{
$wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
$this->formKeyValidator->expects($this->once())->method('validate')->with($this->request)->will($this->returnValue(true));
$this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2));
$this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com'));
$this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist));
$this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com'));
$this->getController()->execute();
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:AllcartTest.php
示例19: execute
/**
* Action to accept new configuration for a wishlist item
*
* @return void
*/
public function execute()
{
$productId = (int) $this->getRequest()->getParam('product');
if (!$productId) {
$this->_redirect('*/');
return;
}
try {
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
$product = null;
}
if (!$product || !$product->isVisibleInCatalog()) {
$this->messageManager->addError(__('We can\'t specify a product.'));
$this->_redirect('*/');
return;
}
try {
$id = (int) $this->getRequest()->getParam('id');
/* @var \Magento\Wishlist\Model\Item */
$item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item');
$item->load($id);
$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist) {
$this->_redirect('*/');
return;
}
$buyRequest = new \Magento\Framework\Object($this->getRequest()->getParams());
$wishlist->updateItem($id, $buyRequest)->save();
$this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
$this->_eventManager->dispatch('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $wishlist->getItem($id)]);
$this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
$message = __('%1 has been updated in your wish list.', $product->getName());
$this->messageManager->addSuccess($message);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('An error occurred while updating wish list.'));
$this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
}
$this->_redirect('*/*', ['wishlist_id' => $wishlist->getId()]);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:47,代码来源:UpdateItemOptions.php
示例20: getWishlist
/**
* Retrieve wishlist by logged in customer
*
* @return \Magento\Wishlist\Model\Wishlist
*/
public function getWishlist()
{
if ($this->_wishlist === null) {
if ($this->_coreRegistry->registry('shared_wishlist')) {
$this->_wishlist = $this->_coreRegistry->registry('shared_wishlist');
} else {
$this->_wishlist = $this->wishlistProvider->getWishlist();
}
}
return $this->_wishlist;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:Data.php
注:本文中的Magento\Wishlist\Controller\WishlistProviderInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论