qruim Posted August 11, 2023 Share Posted August 11, 2023 My problem is that I want to make a voucher with a custom price, so that the user enters the amount of money he wants to buy a voucher in the input field I am using Prestashop 1.7 Link to comment Share on other sites More sharing options...
Eutanasio Posted August 11, 2023 Share Posted August 11, 2023 why don't you make a product for 1€ value, so then the customer has to purchase as much quantities as he wants the voucher value to be? Link to comment Share on other sites More sharing options...
qruim Posted August 14, 2023 Author Share Posted August 14, 2023 On 8/12/2023 at 12:15 AM, Eutanasio said: why don't you make a product for 1€ value, so then the customer has to purchase as much quantities as he wants the voucher value to be? I proposed this solution, but the customer refused it (God knows why). Now I'm trying to implement this mechanic as follows: the base price of the voucher is 50 conventional units, to this value is added the value from input I wrote such a module, but I don't think it works, I'm quite new to Prestashop so I don't understand why it doesn't work class CustomPriceAdjustment extends Module { public function __construct() { $this->name = 'custompriceadjustment'; $this->tab = 'pricing_promotion'; $this->version = '1.0.0'; $this->author = 'name'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Custom Price Adjustment'); $this->description = $this->l('Allows customers to adjust product prices.'); $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); } public function install() { return parent::install() && $this->registerHook('displayProductAdditionalInfo') && $this->registerHook('actionCartSave'); } public function hookActionCartSave($params) { $this->updatePriceWithAdjustment($params['cart']); } private function updatePriceWithAdjustment($cart) { $priceAdjustment = (float) Tools::getValue('priceAdjustment', 0); // Loop through cart products and update their prices foreach ($cart->getProducts() as $product) { if ($priceAdjustment > 0) { $productPrice = $product['price']; $newProductPrice = $productPrice + $priceAdjustment; $cart->updateQty( $product['quantity'], $product['id_product'], $product['id_product_attribute'], null, 'up', 0, null, false, $newProductPrice ); } } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now