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) {
            if($request->getData('sample')){
                $productName = $candidate->getData('name');
                $sampleName=$productName.'-SAMPLE';
                $candidate->setData('name', $sampleName);
                $candidate->setPrice('0.0000');
                $item = $this->itemProcessor>init($candidate,$request);
                $item->setQuote($this);
                $item->setOptions($candidate->getCustomOptions());
                $item->setProduct($candidate);
                $item->setData('sample', 1);
            }else{
                $item = $this->itemProcessor->init($candidate, $request);
                $item->setQuote($this);
                $item->setOptions($candidate->getCustomOptions());
                $item->setProduct($candidate);
            }

            // Add only item that is not in quote already
            $this->addItem($item);
        }

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