Search code examples
prestashopprestashop-1.7

Reduce product price from php script


I am trying to make a php script that reduces the base price of a product by 20 but it instead changes the base price with the discounted price. I can't figure out what is wrong with the code.

        $product_baseprice = round(1.19*($product->base_price));
        $product->base_price = $product_baseprice - 20;
        $product->update();

Solution

  • There's no "base_price" property in the Product class object. The base price must be updated with the $product->price property.

    Or, like suggested, you can create a new SpecificPrice() where you can apply a percentage-based discount on the product.