Jump to content

Option for a product with static price.


KramarSenior

Recommended Posts

Hello guys.

I am creating new shop and I have a problem. I don't know how to even approach it. I am creating a shop in Prestashop. I have products with combinations. I need some variant for this product to be set in static price. Let's say I have a scooter and can manage combinations with different colors, batteries, etc. Different combinations have different prices. But I need to be able to let's customers buy this product as a "test drive". So, I want another button on my page, with add to cart - test drive and when customer press this button and add this scooter to a cart with variety of combination, the price should always be 500. How can I do it?

 

Is there maybe a module that can allow it? I mean, I am a developer but I have no clue how to even start it. If this was a single product, there won't be any problems because I would create a module that can handle it and check how product was added to cart and set price with hooks.

Link to comment
Share on other sites

  • 2 weeks later...

However as these changes will require a technical expertise
In your product template file (usually product.tpl or a similar file in your theme), add an additional button beside the regular Add to Cart button.
Add JavaScript to handle the "Test Drive" button click event. This script should:

$('#test-drive-button').click(function() {
var productId = $('#product-id').val();
var combinationId = $('#combination-id').val();

$.ajax({
type: 'POST',
url: '/your-custom-url-to-handle-test-drive',
data: {
action: 'addTestDrive',
productId: productId,
combinationId: combinationId,
price: 500
},
success: function(response) {
alert('Test drive item added to cart at a fixed price of $500.');
// Update cart or redirect if needed
}
});
});
Create a custom PrestaShop controller or override the existing cart functionality to handle the "test drive" option.
parent::initContent();

$productId = (int)Tools::getValue('productId');
$combinationId = (int)Tools::getValue('combinationId');
$price = (float)Tools::getValue('price'); $cart = $this->context->cart;
$cart->updateQty(1, $productId, $combinationId, false, 'up', 0, null, false, $price);

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...