0

I have code for test a customer session....

$sessionOrderBy = $this->_customerSession->setSortOrderBy('2');
echo $this->_customerSession->getSortOrderBy();

return is: 2 value

after commented

 // $sessionOrderBy = $this->_customerSession->setSortOrderBy('2');
and run 

return : null;

So, how do save $sessionOrderBy in _customerSession?

2
  • are you tried saved in you controller file?
    – Abdul
    Dec 9 '15 at 10:04
  • this code in Myblock. it extends product_view. so how save it? @Abdul
    – xanka
    Dec 9 '15 at 10:10
0

Bellow code add you block file

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Customer\Model\Session as CustomerSession;


    protected $customerSession;

    protected $customerFactory;

    protected $customerRepository;

    public function __construct(
        CustomerSession $customerSession,
        CustomerInterfaceFactory $customerFactory,
        CustomerRepositoryInterface $customerRepository,
    ) {
        $this->customerSession = $customerSession;
        $this->customerFactory = $customerFactory;
        $this->customerRepository = $customerRepository;
    }

    public function setSortOrderBy($sortOrder)
    {
        $sortOrder = 2;
        $this->customerSession->setSortOrderBy($sortOrder);
    }
1
  • thanks @Abdul. i tried it. when i run $this->customerSession->getSortOrderBy() return Null;
    – xanka
    Dec 9 '15 at 10:21
0

When i add

$this->_customerSession->regenerateId();
$sessionOrderBy = $this->_customerSession->setSortOrderBy('2');

it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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