I have a product for which another product needs to be added in the cart.

For this I need to check if the quantity of said product is changed in order to change the number of associated products.

I wrote a Plugin on the SetQty function in order to get this information:

    class ChangeQtyPlugin
    protected $checkoutSession;
    protected $cartRepository;
    protected $logger;

    public function __construct(
        Session $checkoutSession,
        CartRepositoryInterface $cartRepository,
        LoggerInterface $logger
    ) {
        $this->checkoutSession = $checkoutSession;
        $this->cartRepository  = $cartRepository;
        $this->logger    = $logger;

    public function beforeSetQty(Item $subject, $result) : array
        $oldQty   = $subject->getOrigData('qty');
        $addingQty   = $subject->getData('qty');
        $this->logger->info(print_r($oldQty, true));
        $this->logger->info(print_r($addingQty, true));

        return [$result];

When I change the qty how, it returns:

[2021-10-11 12:52:51] main.INFO: testOld [] []

[2021-10-11 12:52:51] main.INFO: 10.0000 [] []

[2021-10-11 12:52:51] main.INFO: testNew [] []

[2021-10-11 12:52:51] main.INFO: 10.0000 [] []

Which is the New quantity. How can I retrieve the old Qty before the change?

1 Answer 1


You can get all the params value using this code


You can get all the post value using this way,


  • getRequest seems undifined here. It's a plugin, that might have something to do with it? Commented Oct 12, 2021 at 7:12

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.