Jump to content

Help with a module


waldette

Recommended Posts

Hello, im programming a module for prestashop.

 

I want to this module add a product with a discount, like "DISCOUNT CUPON -1.26€". Is it possible to add a product with custom discount?

 

Ah, if is not possible, then its possible to change the final priece of the cart with a discount?

 

Another problem i have is when i install the module. I want to redirect to configuration page automaticaly. Is it possible do it and not go again to module's page?

 

Tanks!

 

PD: Sorry my english, im spanish but i post here too because there are more ppl. ty

Edited by waldette (see edit history)
Link to comment
Share on other sites

Yes, it's possible to add a product to the cart from module. Just use

$this->context->cart->updateQty($qty, $id_product, $id_product_attribute, $customization_id, 'up');

where id_product_attribute and customization_id are optional or NULL.

 

After install it's not possible to redirect directly to module's configuration page.

Link to comment
Share on other sites

First of all thanks for the answers, it's perfect for me add a new product with negative priece for the discount. And with the configuration page it's a secundary thing, i will make a guide for the installation.

 

I have another cuestion now.

 

1. First of all the module ask the client a movile and how much discount want apply.

2. Then the bussiness send a movile message with a code. Then the module ask the PIN code sended.

3. And finally add and apply the discount if is able.

 

Questions:

1. Is it possible make all three steps in ajax, including the product discount add?

2. If not, is it possible to make the two first steps in ajax and then reload the page with this product discount added?

 

Thanks for all! :)

Link to comment
Share on other sites

First of all thanks for the answers, it's perfect for me add a new product with negative priece for the discount. And with the configuration page it's a secundary thing, i will make a guide for the installation.

 

I have another cuestion now.

 

1. First of all the module ask the client a movile and how much discount want apply.

2. Then the bussiness send a movile message with a code. Then the module ask the PIN code sended.

3. And finally add and apply the discount if is able.

 

Questions:

1. Is it possible make all three steps in ajax, including the product discount add?

2. If not, is it possible to make the two first steps in ajax and then reload the page with this product discount added?

 

Thanks for all! :)

Yes, that should be possible (first 2 steps using form and/or modal (Fancybox) popup, last step is to replicate the step and ajax/JSON answer like blockcart module/ajaxcart to add product and refresh cart block/order summary)
  • Like 1
Link to comment
Share on other sites

Thanks but prestashop integrates fancybox and ajax itself? You mean that blockcart is it possible to refresh alone in ajax?

Depends on what you mean with integrates itself. The Prestashop has the jQuery source and Fancybox plugin packed in the source files, jQuery is loaded into each page invocation, Fancybox plugin however is not loaded into each page by default.

Ajax can always be used using your own loaded Javascript in template or using the addJS Frontcontroller function (hook your module to Header and call function $this->AddJS(yourjavascriptfile.js)).

The blockcart module uses ajaxcart.js and hookAjax function in blockcart.php module file to capture a click on 'Add to Cart' button to add the product to the cart object and uses JSON return value and Ajaxcart object function to update the cart block dynamically.

  • Like 1
Link to comment
Share on other sites

Depends on what you mean with integrates itself. The Prestashop has the jQuery source and Fancybox plugin packed in the source files, jQuery is loaded into each page invocation, Fancybox plugin however is not loaded into each page by default.

Ajax can always be used using your own loaded Javascript in template or using the addJS Frontcontroller function (hook your module to Header and call function $this->AddJS(yourjavascriptfile.js)).

The blockcart module uses ajaxcart.js and hookAjax function in blockcart.php module file to capture a click on 'Add to Cart' button to add the product to the cart object and uses JSON return value and Ajaxcart object function to update the cart block dynamically.

 

Only one thing more. Are there any site where can i find focumentation about ajaxcart object or somthing similar for my module? Because the function that u said:

$this->context->cart->updateQty($qty, $id_product, $id_product_attribute, $customization_id, 'up');

dont add the product dinamicaly?

Ok, i find how to do the first two steps with ajax but i dont find the method for add the product dynamicaly....

What i need? I need include any js or php in my module? I need make the product previusly in my installation? I dont understand it...

Edited by waldette (see edit history)
Link to comment
Share on other sites

Only one thing more. Are there any site where can i find focumentation about ajaxcart object or somthing similar for my module? Because the function that u said:

$this->context->cart->updateQty($qty, $id_product, $id_product_attribute, $customization_id, 'up');

dont add the product dinamicaly?

Ok, i find how to do the first two steps with ajax but i dont find the method for add the product dynamicaly....

What i need? I need include any js or php in my module? I need make the product previusly in my installation? I dont understand it...

Check out the blockcart module and see for yourself how that module works in terms of adding product to the cart object using ordercontroller in ajax call and refreshing cart block contents after adding using the ajax return JSON value.
Link to comment
Share on other sites

Ok, thanks for all. I try to execute the functions in this module but the products isnt load in ajax. It's add to the cart, but only when i refresh the page.

 

Can you make a example pls?

 

Aaaah, but i dont want to add a existing product to cart!!! I want add a dynamically price product, like a coupon with dinamic priece sended by the form.... Is it possible with this module?

Edited by waldette (see edit history)
Link to comment
Share on other sites

Ok, thanks for all. I try to execute the functions in this module but the products isnt load in ajax. It's add to the cart, but only when i refresh the page.

 

Can you make a example pls?

 

Aaaah, but i dont want to add a existing product to cart!!! I want add a dynamically price product, like a coupon with dinamic priece sended by the form.... Is it possible with this module?

Products and coupons prices/values are not dynamically changeable on add to cart.

What you could do is set discount rates/values as product attributes and use attribute combinations on the "discount" product.

You can then use the id_product_attribute when adding to cart using Ajax to set the correct discount.

Link to comment
Share on other sites

Thanks, but to do that i need a existing product? Because if i need an existing product, i dont know how can i create it in install module method....

 

For me its perfect to add a discount, really i need only this option for do it. If its possible to change the final price with a discount and show it to my module (on cart) its perfect.

 

Help me pls.

Link to comment
Share on other sites

Thanks, but to do that i need a existing product? Because if i need an existing product, i dont know how can i create it in install module method....

 

For me its perfect to add a discount, really i need only this option for do it. If its possible to change the final price with a discount and show it to my module (on cart) its perfect.

 

Help me pls.

Like any other object/class a Product can be dynamically created. Just create an empty product using $product = new Product(); and fill in the object variables according to the construct definition and use $product->add(); to finally add the product to the database. Same goes for attributes and combinations.
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...