Can not place order after change price to 0 programmatically

by Alkos   Last Updated February 26, 2019 07:09 AM - source

I'm changing price to 0.00 when adding product to cart with my custom flag. So I have override method addProduct() in Magento\Quote\Model\Quote.php here is my changes in this method:

            if (!$item) {
                $productName = $candidate->getData('name');
                $candidate->setData('name', $sampleName);
                $item = $this->itemProcessor>init($candidate,$request);
                $item->setData('sample', 1);
                $item = $this->itemProcessor->init($candidate, $request);

            // Add only item that is not in quote already

The product goes to cart perfectly with price 0, but when I am going to checkout and trying to place the order, I'm getting this exception -

The requested Payment Method is not available . I checked network in console and it there was payment method in post parameters - "free".

Also, the payment methods are not showing in checkout if there are no any products with changed custom prices. It shows - No Payment Information Required .

If I go to admin and set price 0 for any product there and try to place order with it so it path through perfectly.

I assume the issue with price changes. If I change price to 1 (not 0) payment methods are appears perfectly.

How can I change price to 0 programmatically and place the order?

Related Questions

Custom price does not reflect on the cart

Updated April 19, 2018 09:09 AM

Request for quote and checkout at same time

Updated October 15, 2018 08:09 AM