1
Assuming you're getting product_id from ajax call then I think there is a minor problem in your jquery. It should be $(".product-id-"+wislistAddedProductId).addClass('in-wishlist') not
$(".product-id"+wislistAddedProductId).addClass('in-wishlist'). Check your div class name. Try below :
<script>
require(['jquery'], function($){
...
1
as discussed, i see that a few corrections are needed:
you should call the 'test_testmodule/index/test' url as you defined your frontName as 'test_testmodule'
you should use the 'standard' routerId if you are working on the frontend side with this call
you are expecting a JSON formatted response as per your AJAX call definition, so you will have to format ...
1
Using a custom controller to change Wishlist button(icon) color once the product added to Wishlist.
app/code/vendor/module/Controller/Index/Wishlist.php
<?php
namespace Vendor\Module\Controller\Index;
class Wishlist extends \Magento\Framework\App\Action\Action {
public function __construct(
\Magento\Framework\App\Action\Context $context,
...
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
controllers × 935magento2 × 369
magento-1.9 × 178
module × 104
overrides × 85
ajax × 72
blocks × 71
layout × 41
magento-2.1 × 37
magento-1.8 × 36
admin × 36
adminhtml × 36
magento-1 × 33
redirect × 32
product × 30
php × 30
routing × 29
magento-1.7 × 28
admin-controller × 28
magento2.3 × 27
template × 27
forms × 27
event-observer × 25
url × 25
magento2.2 × 24