Skip to content

Commit

Permalink
Implement ActionInterface for Wishlist/Shared
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudolf Vince committed Mar 30, 2020
1 parent 176ba2b commit a4c74d8
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions app/code/Magento/Wishlist/Controller/Shared/Allcart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,68 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Wishlist\Controller\Shared;

use Magento\Framework\App\Action\Context;
use Magento\Wishlist\Model\ItemCarrier;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\Result\Forward;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Wishlist\Model\ItemCarrier;

class Allcart extends \Magento\Framework\App\Action\Action
class Allcart implements HttpGetActionInterface
{
/**
* @var ItemCarrier
*/
private $itemCarrier;

/**
* @var WishlistProvider
*/
protected $wishlistProvider;
private $wishlistProvider;

/**
* @var \Magento\Wishlist\Model\ItemCarrier
* @var RequestInterface
*/
protected $itemCarrier;
private $request;

/**
* @param Context $context
* @param WishlistProvider $wishlistProvider
* @param ItemCarrier $itemCarrier
* @var ResultFactory
*/
private $resultFactory;

public function __construct(
Context $context,
WishlistProvider $wishlistProvider,
ItemCarrier $itemCarrier
ItemCarrier $itemCarrier,
RequestInterface $request,
ResultFactory $resultFactory,
WishlistProvider $wishlistProvider
) {
$this->wishlistProvider = $wishlistProvider;
$this->itemCarrier = $itemCarrier;
parent::__construct($context);
$this->request = $request;
$this->resultFactory = $resultFactory;
$this->wishlistProvider = $wishlistProvider;
}

/**
* Add all items from wishlist to shopping cart
*
* @return \Magento\Framework\Controller\ResultInterface
* @inheritDoc
*/
public function execute()
{
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
/** @var Forward $resultForward */
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
$resultForward->forward('noroute');
return $resultForward;
}
$redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty'));
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->request->getParam('qty'));
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl($redirectUrl);
return $resultRedirect;
Expand Down

0 comments on commit a4c74d8

Please sign in to comment.