0

I have set cookies in js with bellow code

 getSelectedValuecc: function() {
            jQuery(function () {
            jQuery("#paytm_payment_profile_id").change(function () {
            //alert('select chnage');
            var selectedValue = jQuery(this).val();
            alert("Value: " + selectedValue);
            $.cookie('cookie_name', selectedValue,{ path: 'http://vaibhav.local/complaint/customer/index' });
            var temp = $.cookie('cookie_name');
            alert("cookie - " +temp);
            //jQuery('input[name="payment[method]"]').attr("disabled",true);
           if (selectedValue !=''){
               jQuery("#pay").show();
               jQuery("#address").show();
            }else{
                jQuery("#pay").hide();
                jQuery("#address").hide();
            }
            alert("Value: " + selectedValue);
            if(selectedValue == 'vsquare'){
               jQuery("#address").html("V Square Building 1st Lane, DwarakaNagar,Visakhapatnam-530016,AP.,India").show();
               jQuery("#paytm").click();
               return true;
            }
            if(selectedValue == 'pavanpalace'){
               jQuery("#address").html("A-1,Pavan Palace,near telugu thalli Flyover,Station Road, Dwaraka Nagar,Visakhapatnam-530016,AP.,India").show();
               jQuery("#paytm").click();
               return true;
            }
            return selectedValue;
        });
    });
    },

I want to get this cookies on observer with bellow code

public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $cookieValue = $this->_cookieManager->getCookie(\Iksula\Complaint\Controller\Customer\Index::cookie_name);
        echo($cookieValue);
}

i am getting error Undefined class constant 'cookie_name'

1 Answer 1

0

Change following line

\Iksula\Complaint\Controller\Customer\Index::cookie_name

To

cookie_name

Now your code looks like


public function execute(\Magento\Framework\Event\Observer $observer)
{
    $cookieValue = $this->_cookieManager->getCookie('cookie_name');
    echo($cookieValue);
}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.