Wishlist ajax removeHelp overwritting some model file and block of wishlistMagento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCould not create an acl object: Role '9' - how to resolve this?AJAX login, how to pass data response from controller to jQuery with AjaxProduct List Toolbar for WishlistRemove wishlist items when added to cartMagento 2.3 Inject helper into controller object type error?Magento 2.3 Can't view module's front end page output?

How to avoid using System.String with Rfc2898DeriveBytes in C#

Can pay be witheld for hours cleaning up after closing time?

What does it mean to have a subnet mask /32?

Why can't an Airbus A330 dump fuel in an emergency?

Fancy String Replace

How big would a Daddy Longlegs Spider need to be to kill an average Human?

Check in to 2 hotels at same location

Fried gnocchi with spinach, bacon, cream sauce in a single pan

If all stars rotate, why was there a theory developed, that requires non-rotating stars?

Why does my house heat up, even when it's cool outside?

Is it safe to remove the bottom chords of a series of garage roof trusses?

Factoring the square of this polynomial?

Why aren't RCS openings an issue for spacecraft heat shields?

Why is observed clock rate < 3MHz on Arduino Uno?

What professions would a medieval village with a population of 100 need?

Three Singles in Three Clubs

How to write triplets in 4/4 time without using a 3 on top of the notes all the time

Can I switch to third-person while not in 'town' in Destiny 2?

Is it insecure to have an ansible user with passwordless sudo?

Are illustrations in novels frowned upon?

Why don't we use Cavea-B

Defense against attacks using dictionaries

If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?

Why didn’t Doctor Strange stay in the original winning timeline?



Wishlist ajax remove


Help overwritting some model file and block of wishlistMagento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCould not create an acl object: Role '9' - how to resolve this?AJAX login, how to pass data response from controller to jQuery with AjaxProduct List Toolbar for WishlistRemove wishlist items when added to cartMagento 2.3 Inject helper into controller object type error?Magento 2.3 Can't view module's front end page output?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to remove product from wishlist from a custom button on detail. I did a plugin for the MagentoWishlistControllerIndexRemove.php with an aroundExecute but for some reason I can't load/create products as magento does in the default Remove controller. I posted my file



 use MagentoCustomerModelSession;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkExceptionNotFoundException;
use MagentoWishlistControllerWishlistProviderInterface;
use MagentoWishlistModelItem;
use MagentoWishlistModelProductAttributeValueProvider;
use MagentoWishlistModelWishlistFactory;

/**
* Class Remove
* @package CodesicleWishlistAjaxPluginWishlistControllerIndex
*/
class Remove
{
/**
* @var WishlistProviderInterface
*/
protected $wishlistProvider;

/**
* @var AttributeValueProvider
*/
private $attributeValueProvider;


/**
* @var Session
*/
protected $customerSession;

/**
* @var JsonFactory
*/
protected $jsonFactory;

/**
* @var WishlistFactory
*/
protected $wishlistFactory;

public function __construct(
WishlistProviderInterface $wishlistProvider,
AttributeValueProvider $attributeValueProvider = null,
JsonFactory $jsonFactory,
Session $customerSession,
WishlistFactory $wishlistFactory
)

$this->wishlistProvider = $wishlistProvider;
$this->attributeValueProvider = $attributeValueProvider
?: MagentoFrameworkAppObjectManager::getInstance()->get(AttributeValueProvider::class);
$this->jsonFactory = $jsonFactory;
$this->customerSession = $customerSession;
$this->wishlistFactory = $wishlistFactory;


public function aroundExecute($subject, $proceed)


$id = (int)$this->getRequest()->getParam('item');

$item = $subject->_objectManager->create(Item::class)->load($id);

if (!$item->getId())
throw new NotFoundException(__('Page not found.'));

$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist)
throw new NotFoundException(__('Page not found.'));

try
$item->delete();
$wishlist->save();
$productName = $this->attributeValueProvider
->getRawAttributeValue($item->getProductId(), 'name');

$response = [
'errors' => false,
'message' => __('%1 has been removed from your Wish List.', $productName)
];
catch (MagentoFrameworkExceptionLocalizedException $exception)
$response = [
'errors' => true,
'message' => __('We can't delete the item from Wish List right now because of an error: %1.', $exception->getMessage())
];
catch (Exception $exception)
$response = [
'errors' => true,
'message' => __('We can't delete the item from the Wish List right now.')
];

$this->_objectManager->get(MagentoWishlistHelperData::class)->calculate();

$resultJson = $this->jsonFactory->create();
return $resultJson->setData($response);



What am I missing or what did I do wrong?



LE:



Looks like the getItem method from WishlistFactory is returning NULL and I can't get to find out why










share|improve this question


























  • Which error it show?

    – Dhiren Vasoya
    Aug 9 at 12:34











  • I get 500 error on the Post request. from some debugging the problem seems to be here or below $subject->_objectManager->create(Item::class)->load($id) but as I said this is how magento does it

    – Vlad Patru
    Aug 9 at 12:36












  • Create _objectManager then use into your code.

    – Dhiren Vasoya
    Aug 9 at 12:41











  • @DhirenVasoya I did that and still not working I used $this->_objectManager = $context->getObjectManager(); in the constructor and still I get 500 error

    – Vlad Patru
    Aug 9 at 13:17

















0















I want to remove product from wishlist from a custom button on detail. I did a plugin for the MagentoWishlistControllerIndexRemove.php with an aroundExecute but for some reason I can't load/create products as magento does in the default Remove controller. I posted my file



 use MagentoCustomerModelSession;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkExceptionNotFoundException;
use MagentoWishlistControllerWishlistProviderInterface;
use MagentoWishlistModelItem;
use MagentoWishlistModelProductAttributeValueProvider;
use MagentoWishlistModelWishlistFactory;

/**
* Class Remove
* @package CodesicleWishlistAjaxPluginWishlistControllerIndex
*/
class Remove
{
/**
* @var WishlistProviderInterface
*/
protected $wishlistProvider;

/**
* @var AttributeValueProvider
*/
private $attributeValueProvider;


/**
* @var Session
*/
protected $customerSession;

/**
* @var JsonFactory
*/
protected $jsonFactory;

/**
* @var WishlistFactory
*/
protected $wishlistFactory;

public function __construct(
WishlistProviderInterface $wishlistProvider,
AttributeValueProvider $attributeValueProvider = null,
JsonFactory $jsonFactory,
Session $customerSession,
WishlistFactory $wishlistFactory
)

$this->wishlistProvider = $wishlistProvider;
$this->attributeValueProvider = $attributeValueProvider
?: MagentoFrameworkAppObjectManager::getInstance()->get(AttributeValueProvider::class);
$this->jsonFactory = $jsonFactory;
$this->customerSession = $customerSession;
$this->wishlistFactory = $wishlistFactory;


public function aroundExecute($subject, $proceed)


$id = (int)$this->getRequest()->getParam('item');

$item = $subject->_objectManager->create(Item::class)->load($id);

if (!$item->getId())
throw new NotFoundException(__('Page not found.'));

$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist)
throw new NotFoundException(__('Page not found.'));

try
$item->delete();
$wishlist->save();
$productName = $this->attributeValueProvider
->getRawAttributeValue($item->getProductId(), 'name');

$response = [
'errors' => false,
'message' => __('%1 has been removed from your Wish List.', $productName)
];
catch (MagentoFrameworkExceptionLocalizedException $exception)
$response = [
'errors' => true,
'message' => __('We can't delete the item from Wish List right now because of an error: %1.', $exception->getMessage())
];
catch (Exception $exception)
$response = [
'errors' => true,
'message' => __('We can't delete the item from the Wish List right now.')
];

$this->_objectManager->get(MagentoWishlistHelperData::class)->calculate();

$resultJson = $this->jsonFactory->create();
return $resultJson->setData($response);



What am I missing or what did I do wrong?



LE:



Looks like the getItem method from WishlistFactory is returning NULL and I can't get to find out why










share|improve this question


























  • Which error it show?

    – Dhiren Vasoya
    Aug 9 at 12:34











  • I get 500 error on the Post request. from some debugging the problem seems to be here or below $subject->_objectManager->create(Item::class)->load($id) but as I said this is how magento does it

    – Vlad Patru
    Aug 9 at 12:36












  • Create _objectManager then use into your code.

    – Dhiren Vasoya
    Aug 9 at 12:41











  • @DhirenVasoya I did that and still not working I used $this->_objectManager = $context->getObjectManager(); in the constructor and still I get 500 error

    – Vlad Patru
    Aug 9 at 13:17













0












0








0








I want to remove product from wishlist from a custom button on detail. I did a plugin for the MagentoWishlistControllerIndexRemove.php with an aroundExecute but for some reason I can't load/create products as magento does in the default Remove controller. I posted my file



 use MagentoCustomerModelSession;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkExceptionNotFoundException;
use MagentoWishlistControllerWishlistProviderInterface;
use MagentoWishlistModelItem;
use MagentoWishlistModelProductAttributeValueProvider;
use MagentoWishlistModelWishlistFactory;

/**
* Class Remove
* @package CodesicleWishlistAjaxPluginWishlistControllerIndex
*/
class Remove
{
/**
* @var WishlistProviderInterface
*/
protected $wishlistProvider;

/**
* @var AttributeValueProvider
*/
private $attributeValueProvider;


/**
* @var Session
*/
protected $customerSession;

/**
* @var JsonFactory
*/
protected $jsonFactory;

/**
* @var WishlistFactory
*/
protected $wishlistFactory;

public function __construct(
WishlistProviderInterface $wishlistProvider,
AttributeValueProvider $attributeValueProvider = null,
JsonFactory $jsonFactory,
Session $customerSession,
WishlistFactory $wishlistFactory
)

$this->wishlistProvider = $wishlistProvider;
$this->attributeValueProvider = $attributeValueProvider
?: MagentoFrameworkAppObjectManager::getInstance()->get(AttributeValueProvider::class);
$this->jsonFactory = $jsonFactory;
$this->customerSession = $customerSession;
$this->wishlistFactory = $wishlistFactory;


public function aroundExecute($subject, $proceed)


$id = (int)$this->getRequest()->getParam('item');

$item = $subject->_objectManager->create(Item::class)->load($id);

if (!$item->getId())
throw new NotFoundException(__('Page not found.'));

$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist)
throw new NotFoundException(__('Page not found.'));

try
$item->delete();
$wishlist->save();
$productName = $this->attributeValueProvider
->getRawAttributeValue($item->getProductId(), 'name');

$response = [
'errors' => false,
'message' => __('%1 has been removed from your Wish List.', $productName)
];
catch (MagentoFrameworkExceptionLocalizedException $exception)
$response = [
'errors' => true,
'message' => __('We can't delete the item from Wish List right now because of an error: %1.', $exception->getMessage())
];
catch (Exception $exception)
$response = [
'errors' => true,
'message' => __('We can't delete the item from the Wish List right now.')
];

$this->_objectManager->get(MagentoWishlistHelperData::class)->calculate();

$resultJson = $this->jsonFactory->create();
return $resultJson->setData($response);



What am I missing or what did I do wrong?



LE:



Looks like the getItem method from WishlistFactory is returning NULL and I can't get to find out why










share|improve this question
















I want to remove product from wishlist from a custom button on detail. I did a plugin for the MagentoWishlistControllerIndexRemove.php with an aroundExecute but for some reason I can't load/create products as magento does in the default Remove controller. I posted my file



 use MagentoCustomerModelSession;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkExceptionNotFoundException;
use MagentoWishlistControllerWishlistProviderInterface;
use MagentoWishlistModelItem;
use MagentoWishlistModelProductAttributeValueProvider;
use MagentoWishlistModelWishlistFactory;

/**
* Class Remove
* @package CodesicleWishlistAjaxPluginWishlistControllerIndex
*/
class Remove
{
/**
* @var WishlistProviderInterface
*/
protected $wishlistProvider;

/**
* @var AttributeValueProvider
*/
private $attributeValueProvider;


/**
* @var Session
*/
protected $customerSession;

/**
* @var JsonFactory
*/
protected $jsonFactory;

/**
* @var WishlistFactory
*/
protected $wishlistFactory;

public function __construct(
WishlistProviderInterface $wishlistProvider,
AttributeValueProvider $attributeValueProvider = null,
JsonFactory $jsonFactory,
Session $customerSession,
WishlistFactory $wishlistFactory
)

$this->wishlistProvider = $wishlistProvider;
$this->attributeValueProvider = $attributeValueProvider
?: MagentoFrameworkAppObjectManager::getInstance()->get(AttributeValueProvider::class);
$this->jsonFactory = $jsonFactory;
$this->customerSession = $customerSession;
$this->wishlistFactory = $wishlistFactory;


public function aroundExecute($subject, $proceed)


$id = (int)$this->getRequest()->getParam('item');

$item = $subject->_objectManager->create(Item::class)->load($id);

if (!$item->getId())
throw new NotFoundException(__('Page not found.'));

$wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
if (!$wishlist)
throw new NotFoundException(__('Page not found.'));

try
$item->delete();
$wishlist->save();
$productName = $this->attributeValueProvider
->getRawAttributeValue($item->getProductId(), 'name');

$response = [
'errors' => false,
'message' => __('%1 has been removed from your Wish List.', $productName)
];
catch (MagentoFrameworkExceptionLocalizedException $exception)
$response = [
'errors' => true,
'message' => __('We can't delete the item from Wish List right now because of an error: %1.', $exception->getMessage())
];
catch (Exception $exception)
$response = [
'errors' => true,
'message' => __('We can't delete the item from the Wish List right now.')
];

$this->_objectManager->get(MagentoWishlistHelperData::class)->calculate();

$resultJson = $this->jsonFactory->create();
return $resultJson->setData($response);



What am I missing or what did I do wrong?



LE:



Looks like the getItem method from WishlistFactory is returning NULL and I can't get to find out why







magento2.3 controllers backend wishlist interceptor






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 12 at 8:23







Vlad Patru

















asked Aug 9 at 12:27









Vlad PatruVlad Patru

9016 silver badges17 bronze badges




9016 silver badges17 bronze badges















  • Which error it show?

    – Dhiren Vasoya
    Aug 9 at 12:34











  • I get 500 error on the Post request. from some debugging the problem seems to be here or below $subject->_objectManager->create(Item::class)->load($id) but as I said this is how magento does it

    – Vlad Patru
    Aug 9 at 12:36












  • Create _objectManager then use into your code.

    – Dhiren Vasoya
    Aug 9 at 12:41











  • @DhirenVasoya I did that and still not working I used $this->_objectManager = $context->getObjectManager(); in the constructor and still I get 500 error

    – Vlad Patru
    Aug 9 at 13:17

















  • Which error it show?

    – Dhiren Vasoya
    Aug 9 at 12:34











  • I get 500 error on the Post request. from some debugging the problem seems to be here or below $subject->_objectManager->create(Item::class)->load($id) but as I said this is how magento does it

    – Vlad Patru
    Aug 9 at 12:36












  • Create _objectManager then use into your code.

    – Dhiren Vasoya
    Aug 9 at 12:41











  • @DhirenVasoya I did that and still not working I used $this->_objectManager = $context->getObjectManager(); in the constructor and still I get 500 error

    – Vlad Patru
    Aug 9 at 13:17
















Which error it show?

– Dhiren Vasoya
Aug 9 at 12:34





Which error it show?

– Dhiren Vasoya
Aug 9 at 12:34













I get 500 error on the Post request. from some debugging the problem seems to be here or below $subject->_objectManager->create(Item::class)->load($id) but as I said this is how magento does it

– Vlad Patru
Aug 9 at 12:36






I get 500 error on the Post request. from some debugging the problem seems to be here or below $subject->_objectManager->create(Item::class)->load($id) but as I said this is how magento does it

– Vlad Patru
Aug 9 at 12:36














Create _objectManager then use into your code.

– Dhiren Vasoya
Aug 9 at 12:41





Create _objectManager then use into your code.

– Dhiren Vasoya
Aug 9 at 12:41













@DhirenVasoya I did that and still not working I used $this->_objectManager = $context->getObjectManager(); in the constructor and still I get 500 error

– Vlad Patru
Aug 9 at 13:17





@DhirenVasoya I did that and still not working I used $this->_objectManager = $context->getObjectManager(); in the constructor and still I get 500 error

– Vlad Patru
Aug 9 at 13:17










4 Answers
4






active

oldest

votes


















0













I see that you pass parameter of class AttributeValueProvider with null default value. The problem should be caused by the way you pass this parameter in dependency injection. So that when you call $this->attributeValueProvider->getRawAttributeValue($item->getProductId(), 'name') PHP will throw fatal error, because the dependency injection does not pass the AttributeValueProvider instance.



Try removing the null default value while passing AttributeValueProvider instance by changing AttributeValueProvider $attributeValueProvider = null to AttributeValueProvider $attributeValueProvider.



If problem persists, try removing the generated interceptor of your class:
rm generated/code/Codesicle/WishlistAjax/Plugin/Wishlist/Controller/Index/Remove/Interceptor.php, and retry deleting wishlist item.






share|improve this answer

























  • that is not the problem, I tried your version but that was how magento-wishlist module gets the attributeValueProvider for some reason the getItem from the Wishlist model is returning NULL but I can't get to figure out why

    – Vlad Patru
    Aug 12 at 8:22


















0













so I changed the implementation a bit, there was a problem with the getItem() method and I went with the following



  1. get current customer ID
    $customerId = $this->_session->getCustomerId();


  2. get wishlist by customer ID
    $wishlist = $this->_wishlist->loadByCustomerId($customerId, true); I had to set create to true here otherwise the collection was not returning, only wishlist info like ID , name , etc.


  3. get item from that collection
    $item = $wishlist->getItem($id);






share|improve this answer
































    0













    I would approach to this problem with a different way. When I create a plugin, I always try to focus on the purpose, rather than the result. There can be multiple ways to reach the expected result, but which one would serve the purpose the most?



    The purpose here is to return a custom JSON response instead of a redirect. It is not to rewrite a core process to remove a wishlist item.



    Here is a working example, giving the same result you are trying to achieve:



    use MagentoFrameworkMessageManagerInterface;
    use MagentoFrameworkMessageMessageInterface;
    use MagentoFrameworkViewLayoutFactory;
    use MagentoWishlistControllerIndexRemove as Subject;
    use MagentoFrameworkControllerResultJsonFactory;

    /**
    * Class Remove
    */
    class Remove

    /**
    * @var LayoutFactory
    */
    protected $layoutFactory;

    /**
    * @var ManagerInterface
    */
    protected $messageManager;

    /**
    * @var JsonFactory
    */
    protected $jsonFactory;

    /**
    * Remove constructor.
    * @param LayoutFactory $layoutFactory
    * @param ManagerInterface $messageManager
    * @param JsonFactory $jsonFactory
    */
    public function __construct(
    LayoutFactory $layoutFactory,
    ManagerInterface $messageManager,
    JsonFactory $jsonFactory
    )
    $this->layoutFactory = $layoutFactory;
    $this->messageManager = $messageManager;
    $this->jsonFactory = $jsonFactory;


    /**
    * @param Subject $controller
    * @param MagentoFrameworkControllerResultRedirect $result
    * @return MagentoFrameworkControllerResultJson
    */
    public function afterExecute(Subject $controller, $result)

    $messages = $this->messageManager->getMessages(true);
    $messagesBlock = $this->layoutFactory->create()->getMessagesBlock();
    $messagesBlock->setMessages($messages);

    $resultJson = $this->jsonFactory->create();
    $resultJson->setData([
    'errors' => boolval($messages->getCountByType(MessageInterface::TYPE_ERROR)),
    'message' => trim(strip_tags($messagesBlock->getGroupedHtml()))
    ]);
    return $resultJson;




    NOTE: By using the code above, you will need to post form_key parameter too along with the item parameter, as it's validated on the default controller unlike your example code. It may make your job easier to remove that validation, but it is highly unadvised to do so.






    share|improve this answer








    New contributor



    muhammedv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




























      0













      Try this : Tested Code



      Note :Just pass productId parameter in your ajax call & Logged User Id Automatically fetch



      class WishlistRemoveItems extends MagentoFrameworkAppActionAction

      protected $wishlist;

      public function __construct(
      MagentoWishlistModelWishlist $wishlist,
      MagentoFrameworkAppRequestHttp $request,
      MagentoCustomerModelSession $customerSession,
      MagentoFrameworkAppActionContext $context
      )
      $this->wishlist = $wishlist;
      $this->request = $request;
      $this->customerSession = $customerSession;
      parent::__construct($context);


      public function execute()


      $customerId = $this->customerSession->getCustomer()->getId();
      $productId = $this->request->getPostValue('productId');
      $wish = $this->wishlist->loadByCustomerId($customerId);
      $items = $wish->getItemCollection();

      /** @var MagentoWishlistModelItem $item */
      foreach ($items as $item)
      if ($item->getProductId() == $productId)
      $item->delete();
      $wish->save();






      hope it will help you, Thanks






      share|improve this answer



























        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "479"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f284993%2fwishlist-ajax-remove%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0













        I see that you pass parameter of class AttributeValueProvider with null default value. The problem should be caused by the way you pass this parameter in dependency injection. So that when you call $this->attributeValueProvider->getRawAttributeValue($item->getProductId(), 'name') PHP will throw fatal error, because the dependency injection does not pass the AttributeValueProvider instance.



        Try removing the null default value while passing AttributeValueProvider instance by changing AttributeValueProvider $attributeValueProvider = null to AttributeValueProvider $attributeValueProvider.



        If problem persists, try removing the generated interceptor of your class:
        rm generated/code/Codesicle/WishlistAjax/Plugin/Wishlist/Controller/Index/Remove/Interceptor.php, and retry deleting wishlist item.






        share|improve this answer

























        • that is not the problem, I tried your version but that was how magento-wishlist module gets the attributeValueProvider for some reason the getItem from the Wishlist model is returning NULL but I can't get to figure out why

          – Vlad Patru
          Aug 12 at 8:22















        0













        I see that you pass parameter of class AttributeValueProvider with null default value. The problem should be caused by the way you pass this parameter in dependency injection. So that when you call $this->attributeValueProvider->getRawAttributeValue($item->getProductId(), 'name') PHP will throw fatal error, because the dependency injection does not pass the AttributeValueProvider instance.



        Try removing the null default value while passing AttributeValueProvider instance by changing AttributeValueProvider $attributeValueProvider = null to AttributeValueProvider $attributeValueProvider.



        If problem persists, try removing the generated interceptor of your class:
        rm generated/code/Codesicle/WishlistAjax/Plugin/Wishlist/Controller/Index/Remove/Interceptor.php, and retry deleting wishlist item.






        share|improve this answer

























        • that is not the problem, I tried your version but that was how magento-wishlist module gets the attributeValueProvider for some reason the getItem from the Wishlist model is returning NULL but I can't get to figure out why

          – Vlad Patru
          Aug 12 at 8:22













        0












        0








        0







        I see that you pass parameter of class AttributeValueProvider with null default value. The problem should be caused by the way you pass this parameter in dependency injection. So that when you call $this->attributeValueProvider->getRawAttributeValue($item->getProductId(), 'name') PHP will throw fatal error, because the dependency injection does not pass the AttributeValueProvider instance.



        Try removing the null default value while passing AttributeValueProvider instance by changing AttributeValueProvider $attributeValueProvider = null to AttributeValueProvider $attributeValueProvider.



        If problem persists, try removing the generated interceptor of your class:
        rm generated/code/Codesicle/WishlistAjax/Plugin/Wishlist/Controller/Index/Remove/Interceptor.php, and retry deleting wishlist item.






        share|improve this answer













        I see that you pass parameter of class AttributeValueProvider with null default value. The problem should be caused by the way you pass this parameter in dependency injection. So that when you call $this->attributeValueProvider->getRawAttributeValue($item->getProductId(), 'name') PHP will throw fatal error, because the dependency injection does not pass the AttributeValueProvider instance.



        Try removing the null default value while passing AttributeValueProvider instance by changing AttributeValueProvider $attributeValueProvider = null to AttributeValueProvider $attributeValueProvider.



        If problem persists, try removing the generated interceptor of your class:
        rm generated/code/Codesicle/WishlistAjax/Plugin/Wishlist/Controller/Index/Remove/Interceptor.php, and retry deleting wishlist item.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 9 at 15:45









        Rendy Eko PrastiyoRendy Eko Prastiyo

        7713 silver badges15 bronze badges




        7713 silver badges15 bronze badges















        • that is not the problem, I tried your version but that was how magento-wishlist module gets the attributeValueProvider for some reason the getItem from the Wishlist model is returning NULL but I can't get to figure out why

          – Vlad Patru
          Aug 12 at 8:22

















        • that is not the problem, I tried your version but that was how magento-wishlist module gets the attributeValueProvider for some reason the getItem from the Wishlist model is returning NULL but I can't get to figure out why

          – Vlad Patru
          Aug 12 at 8:22
















        that is not the problem, I tried your version but that was how magento-wishlist module gets the attributeValueProvider for some reason the getItem from the Wishlist model is returning NULL but I can't get to figure out why

        – Vlad Patru
        Aug 12 at 8:22





        that is not the problem, I tried your version but that was how magento-wishlist module gets the attributeValueProvider for some reason the getItem from the Wishlist model is returning NULL but I can't get to figure out why

        – Vlad Patru
        Aug 12 at 8:22













        0













        so I changed the implementation a bit, there was a problem with the getItem() method and I went with the following



        1. get current customer ID
          $customerId = $this->_session->getCustomerId();


        2. get wishlist by customer ID
          $wishlist = $this->_wishlist->loadByCustomerId($customerId, true); I had to set create to true here otherwise the collection was not returning, only wishlist info like ID , name , etc.


        3. get item from that collection
          $item = $wishlist->getItem($id);






        share|improve this answer





























          0













          so I changed the implementation a bit, there was a problem with the getItem() method and I went with the following



          1. get current customer ID
            $customerId = $this->_session->getCustomerId();


          2. get wishlist by customer ID
            $wishlist = $this->_wishlist->loadByCustomerId($customerId, true); I had to set create to true here otherwise the collection was not returning, only wishlist info like ID , name , etc.


          3. get item from that collection
            $item = $wishlist->getItem($id);






          share|improve this answer



























            0












            0








            0







            so I changed the implementation a bit, there was a problem with the getItem() method and I went with the following



            1. get current customer ID
              $customerId = $this->_session->getCustomerId();


            2. get wishlist by customer ID
              $wishlist = $this->_wishlist->loadByCustomerId($customerId, true); I had to set create to true here otherwise the collection was not returning, only wishlist info like ID , name , etc.


            3. get item from that collection
              $item = $wishlist->getItem($id);






            share|improve this answer













            so I changed the implementation a bit, there was a problem with the getItem() method and I went with the following



            1. get current customer ID
              $customerId = $this->_session->getCustomerId();


            2. get wishlist by customer ID
              $wishlist = $this->_wishlist->loadByCustomerId($customerId, true); I had to set create to true here otherwise the collection was not returning, only wishlist info like ID , name , etc.


            3. get item from that collection
              $item = $wishlist->getItem($id);







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 13 at 8:22









            Vlad PatruVlad Patru

            9016 silver badges17 bronze badges




            9016 silver badges17 bronze badges
























                0













                I would approach to this problem with a different way. When I create a plugin, I always try to focus on the purpose, rather than the result. There can be multiple ways to reach the expected result, but which one would serve the purpose the most?



                The purpose here is to return a custom JSON response instead of a redirect. It is not to rewrite a core process to remove a wishlist item.



                Here is a working example, giving the same result you are trying to achieve:



                use MagentoFrameworkMessageManagerInterface;
                use MagentoFrameworkMessageMessageInterface;
                use MagentoFrameworkViewLayoutFactory;
                use MagentoWishlistControllerIndexRemove as Subject;
                use MagentoFrameworkControllerResultJsonFactory;

                /**
                * Class Remove
                */
                class Remove

                /**
                * @var LayoutFactory
                */
                protected $layoutFactory;

                /**
                * @var ManagerInterface
                */
                protected $messageManager;

                /**
                * @var JsonFactory
                */
                protected $jsonFactory;

                /**
                * Remove constructor.
                * @param LayoutFactory $layoutFactory
                * @param ManagerInterface $messageManager
                * @param JsonFactory $jsonFactory
                */
                public function __construct(
                LayoutFactory $layoutFactory,
                ManagerInterface $messageManager,
                JsonFactory $jsonFactory
                )
                $this->layoutFactory = $layoutFactory;
                $this->messageManager = $messageManager;
                $this->jsonFactory = $jsonFactory;


                /**
                * @param Subject $controller
                * @param MagentoFrameworkControllerResultRedirect $result
                * @return MagentoFrameworkControllerResultJson
                */
                public function afterExecute(Subject $controller, $result)

                $messages = $this->messageManager->getMessages(true);
                $messagesBlock = $this->layoutFactory->create()->getMessagesBlock();
                $messagesBlock->setMessages($messages);

                $resultJson = $this->jsonFactory->create();
                $resultJson->setData([
                'errors' => boolval($messages->getCountByType(MessageInterface::TYPE_ERROR)),
                'message' => trim(strip_tags($messagesBlock->getGroupedHtml()))
                ]);
                return $resultJson;




                NOTE: By using the code above, you will need to post form_key parameter too along with the item parameter, as it's validated on the default controller unlike your example code. It may make your job easier to remove that validation, but it is highly unadvised to do so.






                share|improve this answer








                New contributor



                muhammedv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.

























                  0













                  I would approach to this problem with a different way. When I create a plugin, I always try to focus on the purpose, rather than the result. There can be multiple ways to reach the expected result, but which one would serve the purpose the most?



                  The purpose here is to return a custom JSON response instead of a redirect. It is not to rewrite a core process to remove a wishlist item.



                  Here is a working example, giving the same result you are trying to achieve:



                  use MagentoFrameworkMessageManagerInterface;
                  use MagentoFrameworkMessageMessageInterface;
                  use MagentoFrameworkViewLayoutFactory;
                  use MagentoWishlistControllerIndexRemove as Subject;
                  use MagentoFrameworkControllerResultJsonFactory;

                  /**
                  * Class Remove
                  */
                  class Remove

                  /**
                  * @var LayoutFactory
                  */
                  protected $layoutFactory;

                  /**
                  * @var ManagerInterface
                  */
                  protected $messageManager;

                  /**
                  * @var JsonFactory
                  */
                  protected $jsonFactory;

                  /**
                  * Remove constructor.
                  * @param LayoutFactory $layoutFactory
                  * @param ManagerInterface $messageManager
                  * @param JsonFactory $jsonFactory
                  */
                  public function __construct(
                  LayoutFactory $layoutFactory,
                  ManagerInterface $messageManager,
                  JsonFactory $jsonFactory
                  )
                  $this->layoutFactory = $layoutFactory;
                  $this->messageManager = $messageManager;
                  $this->jsonFactory = $jsonFactory;


                  /**
                  * @param Subject $controller
                  * @param MagentoFrameworkControllerResultRedirect $result
                  * @return MagentoFrameworkControllerResultJson
                  */
                  public function afterExecute(Subject $controller, $result)

                  $messages = $this->messageManager->getMessages(true);
                  $messagesBlock = $this->layoutFactory->create()->getMessagesBlock();
                  $messagesBlock->setMessages($messages);

                  $resultJson = $this->jsonFactory->create();
                  $resultJson->setData([
                  'errors' => boolval($messages->getCountByType(MessageInterface::TYPE_ERROR)),
                  'message' => trim(strip_tags($messagesBlock->getGroupedHtml()))
                  ]);
                  return $resultJson;




                  NOTE: By using the code above, you will need to post form_key parameter too along with the item parameter, as it's validated on the default controller unlike your example code. It may make your job easier to remove that validation, but it is highly unadvised to do so.






                  share|improve this answer








                  New contributor



                  muhammedv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.























                    0












                    0








                    0







                    I would approach to this problem with a different way. When I create a plugin, I always try to focus on the purpose, rather than the result. There can be multiple ways to reach the expected result, but which one would serve the purpose the most?



                    The purpose here is to return a custom JSON response instead of a redirect. It is not to rewrite a core process to remove a wishlist item.



                    Here is a working example, giving the same result you are trying to achieve:



                    use MagentoFrameworkMessageManagerInterface;
                    use MagentoFrameworkMessageMessageInterface;
                    use MagentoFrameworkViewLayoutFactory;
                    use MagentoWishlistControllerIndexRemove as Subject;
                    use MagentoFrameworkControllerResultJsonFactory;

                    /**
                    * Class Remove
                    */
                    class Remove

                    /**
                    * @var LayoutFactory
                    */
                    protected $layoutFactory;

                    /**
                    * @var ManagerInterface
                    */
                    protected $messageManager;

                    /**
                    * @var JsonFactory
                    */
                    protected $jsonFactory;

                    /**
                    * Remove constructor.
                    * @param LayoutFactory $layoutFactory
                    * @param ManagerInterface $messageManager
                    * @param JsonFactory $jsonFactory
                    */
                    public function __construct(
                    LayoutFactory $layoutFactory,
                    ManagerInterface $messageManager,
                    JsonFactory $jsonFactory
                    )
                    $this->layoutFactory = $layoutFactory;
                    $this->messageManager = $messageManager;
                    $this->jsonFactory = $jsonFactory;


                    /**
                    * @param Subject $controller
                    * @param MagentoFrameworkControllerResultRedirect $result
                    * @return MagentoFrameworkControllerResultJson
                    */
                    public function afterExecute(Subject $controller, $result)

                    $messages = $this->messageManager->getMessages(true);
                    $messagesBlock = $this->layoutFactory->create()->getMessagesBlock();
                    $messagesBlock->setMessages($messages);

                    $resultJson = $this->jsonFactory->create();
                    $resultJson->setData([
                    'errors' => boolval($messages->getCountByType(MessageInterface::TYPE_ERROR)),
                    'message' => trim(strip_tags($messagesBlock->getGroupedHtml()))
                    ]);
                    return $resultJson;




                    NOTE: By using the code above, you will need to post form_key parameter too along with the item parameter, as it's validated on the default controller unlike your example code. It may make your job easier to remove that validation, but it is highly unadvised to do so.






                    share|improve this answer








                    New contributor



                    muhammedv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    I would approach to this problem with a different way. When I create a plugin, I always try to focus on the purpose, rather than the result. There can be multiple ways to reach the expected result, but which one would serve the purpose the most?



                    The purpose here is to return a custom JSON response instead of a redirect. It is not to rewrite a core process to remove a wishlist item.



                    Here is a working example, giving the same result you are trying to achieve:



                    use MagentoFrameworkMessageManagerInterface;
                    use MagentoFrameworkMessageMessageInterface;
                    use MagentoFrameworkViewLayoutFactory;
                    use MagentoWishlistControllerIndexRemove as Subject;
                    use MagentoFrameworkControllerResultJsonFactory;

                    /**
                    * Class Remove
                    */
                    class Remove

                    /**
                    * @var LayoutFactory
                    */
                    protected $layoutFactory;

                    /**
                    * @var ManagerInterface
                    */
                    protected $messageManager;

                    /**
                    * @var JsonFactory
                    */
                    protected $jsonFactory;

                    /**
                    * Remove constructor.
                    * @param LayoutFactory $layoutFactory
                    * @param ManagerInterface $messageManager
                    * @param JsonFactory $jsonFactory
                    */
                    public function __construct(
                    LayoutFactory $layoutFactory,
                    ManagerInterface $messageManager,
                    JsonFactory $jsonFactory
                    )
                    $this->layoutFactory = $layoutFactory;
                    $this->messageManager = $messageManager;
                    $this->jsonFactory = $jsonFactory;


                    /**
                    * @param Subject $controller
                    * @param MagentoFrameworkControllerResultRedirect $result
                    * @return MagentoFrameworkControllerResultJson
                    */
                    public function afterExecute(Subject $controller, $result)

                    $messages = $this->messageManager->getMessages(true);
                    $messagesBlock = $this->layoutFactory->create()->getMessagesBlock();
                    $messagesBlock->setMessages($messages);

                    $resultJson = $this->jsonFactory->create();
                    $resultJson->setData([
                    'errors' => boolval($messages->getCountByType(MessageInterface::TYPE_ERROR)),
                    'message' => trim(strip_tags($messagesBlock->getGroupedHtml()))
                    ]);
                    return $resultJson;




                    NOTE: By using the code above, you will need to post form_key parameter too along with the item parameter, as it's validated on the default controller unlike your example code. It may make your job easier to remove that validation, but it is highly unadvised to do so.







                    share|improve this answer








                    New contributor



                    muhammedv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.








                    share|improve this answer



                    share|improve this answer






                    New contributor



                    muhammedv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.








                    answered Aug 15 at 19:26









                    muhammedvmuhammedv

                    1012 bronze badges




                    1012 bronze badges




                    New contributor



                    muhammedv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.




                    New contributor




                    muhammedv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.


























                        0













                        Try this : Tested Code



                        Note :Just pass productId parameter in your ajax call & Logged User Id Automatically fetch



                        class WishlistRemoveItems extends MagentoFrameworkAppActionAction

                        protected $wishlist;

                        public function __construct(
                        MagentoWishlistModelWishlist $wishlist,
                        MagentoFrameworkAppRequestHttp $request,
                        MagentoCustomerModelSession $customerSession,
                        MagentoFrameworkAppActionContext $context
                        )
                        $this->wishlist = $wishlist;
                        $this->request = $request;
                        $this->customerSession = $customerSession;
                        parent::__construct($context);


                        public function execute()


                        $customerId = $this->customerSession->getCustomer()->getId();
                        $productId = $this->request->getPostValue('productId');
                        $wish = $this->wishlist->loadByCustomerId($customerId);
                        $items = $wish->getItemCollection();

                        /** @var MagentoWishlistModelItem $item */
                        foreach ($items as $item)
                        if ($item->getProductId() == $productId)
                        $item->delete();
                        $wish->save();






                        hope it will help you, Thanks






                        share|improve this answer





























                          0













                          Try this : Tested Code



                          Note :Just pass productId parameter in your ajax call & Logged User Id Automatically fetch



                          class WishlistRemoveItems extends MagentoFrameworkAppActionAction

                          protected $wishlist;

                          public function __construct(
                          MagentoWishlistModelWishlist $wishlist,
                          MagentoFrameworkAppRequestHttp $request,
                          MagentoCustomerModelSession $customerSession,
                          MagentoFrameworkAppActionContext $context
                          )
                          $this->wishlist = $wishlist;
                          $this->request = $request;
                          $this->customerSession = $customerSession;
                          parent::__construct($context);


                          public function execute()


                          $customerId = $this->customerSession->getCustomer()->getId();
                          $productId = $this->request->getPostValue('productId');
                          $wish = $this->wishlist->loadByCustomerId($customerId);
                          $items = $wish->getItemCollection();

                          /** @var MagentoWishlistModelItem $item */
                          foreach ($items as $item)
                          if ($item->getProductId() == $productId)
                          $item->delete();
                          $wish->save();






                          hope it will help you, Thanks






                          share|improve this answer



























                            0












                            0








                            0







                            Try this : Tested Code



                            Note :Just pass productId parameter in your ajax call & Logged User Id Automatically fetch



                            class WishlistRemoveItems extends MagentoFrameworkAppActionAction

                            protected $wishlist;

                            public function __construct(
                            MagentoWishlistModelWishlist $wishlist,
                            MagentoFrameworkAppRequestHttp $request,
                            MagentoCustomerModelSession $customerSession,
                            MagentoFrameworkAppActionContext $context
                            )
                            $this->wishlist = $wishlist;
                            $this->request = $request;
                            $this->customerSession = $customerSession;
                            parent::__construct($context);


                            public function execute()


                            $customerId = $this->customerSession->getCustomer()->getId();
                            $productId = $this->request->getPostValue('productId');
                            $wish = $this->wishlist->loadByCustomerId($customerId);
                            $items = $wish->getItemCollection();

                            /** @var MagentoWishlistModelItem $item */
                            foreach ($items as $item)
                            if ($item->getProductId() == $productId)
                            $item->delete();
                            $wish->save();






                            hope it will help you, Thanks






                            share|improve this answer













                            Try this : Tested Code



                            Note :Just pass productId parameter in your ajax call & Logged User Id Automatically fetch



                            class WishlistRemoveItems extends MagentoFrameworkAppActionAction

                            protected $wishlist;

                            public function __construct(
                            MagentoWishlistModelWishlist $wishlist,
                            MagentoFrameworkAppRequestHttp $request,
                            MagentoCustomerModelSession $customerSession,
                            MagentoFrameworkAppActionContext $context
                            )
                            $this->wishlist = $wishlist;
                            $this->request = $request;
                            $this->customerSession = $customerSession;
                            parent::__construct($context);


                            public function execute()


                            $customerId = $this->customerSession->getCustomer()->getId();
                            $productId = $this->request->getPostValue('productId');
                            $wish = $this->wishlist->loadByCustomerId($customerId);
                            $items = $wish->getItemCollection();

                            /** @var MagentoWishlistModelItem $item */
                            foreach ($items as $item)
                            if ($item->getProductId() == $productId)
                            $item->delete();
                            $wish->save();






                            hope it will help you, Thanks







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Aug 17 at 6:28









                            Shafeel ShaShafeel Sha

                            51615 bronze badges




                            51615 bronze badges






























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Magento Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f284993%2fwishlist-ajax-remove%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

                                Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

                                Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림