Jump to content

[FREE MODULE] Link to Add products


Recommended Posts

This simple module gives us a link to add a product to the cart and do the checkout directly outside from Prestashop. Useful for mailing, landing pages etc..

At this moment for PS 1.5 (tested with the latest 1.5.4.1).


In the configuration section we see a random 9-digit key (can change) and the ability to enable or disable it.

In the next section the module facilitates looking for a product and its combinations, if it has some, to get the final Url.

JUPvjQd.png
The Url obtained it’s of this type:


As variables are the id_product, the ipa combination and the key stored in the system, everything else is constant for a given store (the amount of product is 1).

In general there are three situations, in three different scenarios depending on the browser in which the link it’s opened:

  • The user/browser has not entered our store for 20 days or more (or ever), so he hasn’t the cookie of Prestashop.
  • The user/browser entered our store for less than 20 days and therefore has the cookie.
  • The user/browser is also logged in the store.

Note: By default the cookie is active 480 hours (20 days), configurable from the back office.

In any of the three situations the link provided works.

Technical notes:

It has been used the possibility to override classes in the module installation. This has the disadvantage that if the method being used was already overwritten, Prestashop shows an error and you will have to do the mixing by hand. So in case you already have some method in CartController overwritten you must look that no equal method exists inside of the same class in the override module folder, in that case you’ll have to do the installation by hand.

About the Url used:



You should wonder why it works in the first situation. This is because even though Prestashop 1.5 looks before adding the product to the cart if exists the cookie (to aboid boots adding products in our store), if we use the cart.php in the url, Prestashop makes a 301 redirection to the right Url (index.php? controller = cart) since cart.php is "deprecated" (and will disappear in 1.6) so that the cookie it’s always added (if not having it yet) and the trick works.

 

pele_linktoaddproduct.zip

Edited by Enrique Gómez (see edit history)
  • Like 4

Share this post


Link to post
Share on other sites
  • 3 months later...
  • 2 weeks later...
  • 3 weeks later...

Amazing! Thanks a Lot, Enrique!

 

Two question:

 

- Everyone accessing the url will have the product added to his cart or is a one time use only url?

- What it is exactly the random key used for?

Share this post


Link to post
Share on other sites

Amazing! Thanks a Lot, Enrique!

 

Two question:

 

- Everyone accessing the url will have the product added to his cart or is a one time use only url?

- What it is exactly the random key used for?

Everyone will have the product added using the link obtained with the module

 

The random key is to tell the module "open the doors" to whoever has the key to allow them add the product to cart with the given link. Think that is dangerous allow add to cart with links since it's possible that 'boots' use this to create 'ghost carts'.

It's also possible change the key.

  • Like 1

Share this post


Link to post
Share on other sites

Hi! I install this module. The key is generated and saved, but in Get URL menu i can't see any Url: fileld like in your samle, only Product filed, which not search for my products? please help me?

Share this post


Link to post
Share on other sites

Hi! I install this module. The key is generated and saved, but in Get URL menu i can't see any Url: fileld like in your samle, only Product filed, which not search for my products? please help me?

You have to fill in the product box with more than 3 chars to start searching (if some product matches of course). Sometimes the search is slow depending of your hosting

 

zneu.jpg

Share this post


Link to post
Share on other sites
  • 3 months later...

Hi, great module. I am using it for far different purpose. We have a flash app that makes the customer build its product (jewelry) and I`m using your module to add the made product to product cart BUT I want to modify the price of the product, too.

 

I saw in the code that you use processChangeProductInCart() and started altering it, before I changed the Product:getPriceStatic method to change the price from url parameter so now I`m able to say price=1 and the price is one, but here after the Product object is created I say $product->wholesale_price = $_GET['price']; and if I say ddd($product) it is changed, but when it still displays and handles the product default price. Can you give me a hand here.

 

Greetings!

Share this post


Link to post
Share on other sites

A worthwhile opportunity to generate a list of such links with thumbnails and the ability to send such a list to the specified email address

Share this post


Link to post
Share on other sites

Hi, great module. I am using it for far different purpose. We have a flash app that makes the customer build its product (jewelry) and I`m using your module to add the made product to product cart BUT I want to modify the price of the product, too.

 

I saw in the code that you use processChangeProductInCart() and started altering it, before I changed the Product:getPriceStatic method to change the price from url parameter so now I`m able to say price=1 and the price is one, but here after the Product object is created I say $product->wholesale_price = $_GET['price']; and if I say ddd($product) it is changed, but when it still displays and handles the product default price. Can you give me a hand here.

 

Greetings!

 

To modify the product price in the cart you have to go through overriding Cart methods getOrderTotal and getProducts. It has nothing to do with my module. Probably it's better that you create a new Topic

 

Another strategy is use cartrules (vouchers) to add a discount and that way you don't need to do more Class overriding and probably inside the overwritten processChangeProductInCart()  you can create the voucher checking some info of the url.

  • Like 1

Share this post


Link to post
Share on other sites
  • 1 month later...
  • 1 month later...

Hello, I'm use the module, and is good work.

 

But have question. In something if open link don't add to cart in the first click, click again the link and yes, add to cart.

 

what is the fail?

 

I think maybe cookies or something for use external site to add to cart?

 

Thanks

 

Regards from Costa Rica

Share this post


Link to post
Share on other sites
  • 3 months later...
  • 4 months later...
  • 4 weeks later...
  • 2 months later...

Hi, I fix the module and work in all PS 1.6.x

 

Thanks

Hi, i can't install module on PS 1.6.0.14

When I try, i have this error:

Non è stato possibile installare correttamente i seguenti moduli:

  • pele_linktoaddproduct : 

        Impossibile installare l'override: Il metodo postProcess nella classe CartController è già stato annullato.

  • Impossible to install ovverride: metod pstProcess in the class CartController was already been cancelled

PS: I've the version 0.1

 

How can Install by hand? Sorry, but I'm not too expert of prestashop

Edited by mushino (see edit history)

Share this post


Link to post
Share on other sites

I install module by hand:

Copy all files (but not "override" folder) by FTP in "modules" folder of PS.

Activate module in Back Office.

 

 

It works only if user is not logged in.

Elsewhere the link goes to the homepage.

 

EDIT:

I disable token in Preference, and it works fine.

Edited by mushino (see edit history)

Share this post


Link to post
Share on other sites

Hi, i can't install module on PS 1.6.0.14

When I try, i have this error:

Non è stato possibile installare correttamente i seguenti moduli:

  • pele_linktoaddproduct : 

        Impossibile installare l'override: Il metodo postProcess nella classe CartController è già stato annullato.

  • Impossible to install ovverride: metod pstProcess in the class CartController was already been cancelled

PS: I've the version 0.1

 

How can Install by hand? Sorry, but I'm not too expert of prestashop

Hi, the module was tested in 1.5 but it seems you have already the postprocess method overrwritten by another module so the only chance is do the mix by hand.

Share this post


Link to post
Share on other sites
  • 3 months later...

Hi....

 

This is a very useful module...

 

Is it possible to add in the url some custom fields??

 

i tried the following:

<?php

class CartController extends CartControllerCore
{

	public function postProcess(){
		//If the key is active and the value is the configured.
		if(Configuration::get('PELE_LINK_IS_KEY_ACTIVE') && Tools::getIsset(Configuration::get('PELE_LINK_KEY_TO_ADD_PRODUCT'))){
			$this->processChangeProductInCart();
			if (!$this->errors){
	
				if(isset($this->submitCustomizedDatas)){
					if(isset($this->textField7)){$text7=$this->textField7}else{$text7=''};
					if(isset($this->textField8)){$text8=$this->textField8}else{$text8=''};
					$customdata='textField7='.$text7.'&'.'textField8='.$text8;
				}
				Tools::redirect('index.php?controller=order&'.(isset($this->id_product) ? 'ipa='.$this->id_product.'&submitCustomizedDatas=1&'.$customdata : ''));
			}
		}else{//as usual
			parent::postProcess();
		}
	}
	
}
public function postProcess()
{
    if (Tools::isSubmit('submitCustomizedDatas') && Configuration::get('PELE_LINK_IS_KEY_ACTIVE'))
    {
        
            $this->context->cart->add();
        
        
        $this->textRecord();
        
 
        if($this->errors)
        {
            $error_list = implode('; ', $this->errors);
            die(Tools::jsonEncode(array('errors' => $error_list)));
        } else
            die(Tools::jsonEncode(array('success' => true)));
             
    }
}

But the redirect request to http://localhost/shop/index.php?controller=order&ipa=19  don't get the custom fields....

 

Please help.

Edited by kilbourne (see edit history)

Share this post


Link to post
Share on other sites

Hi....

 

This is a very useful module...

 

Is it possible to add in the url some custom fields??

 

i tried the following:

<?php

class CartController extends CartControllerCore
{

	public function postProcess(){
		//If the key is active and the value is the configured.
		if(Configuration::get('PELE_LINK_IS_KEY_ACTIVE') && Tools::getIsset(Configuration::get('PELE_LINK_KEY_TO_ADD_PRODUCT'))){
			$this->processChangeProductInCart();
			if (!$this->errors){
	
				if(isset($this->submitCustomizedDatas)){
					if(isset($this->textField7)){$text7=$this->textField7}else{$text7=''};
					if(isset($this->textField8)){$text8=$this->textField8}else{$text8=''};
					$customdata='textField7='.$text7.'&'.'textField8='.$text8;
				}
				Tools::redirect('index.php?controller=order&'.(isset($this->id_product) ? 'ipa='.$this->id_product.'&submitCustomizedDatas=1&'.$customdata : ''));
			}
		}else{//as usual
			parent::postProcess();
		}
	}
	
}
public function postProcess()
{
    if (Tools::isSubmit('submitCustomizedDatas') && Configuration::get('PELE_LINK_IS_KEY_ACTIVE'))
    {
        
            $this->context->cart->add();
        
        
        $this->textRecord();
        
 
        if($this->errors)
        {
            $error_list = implode('; ', $this->errors);
            die(Tools::jsonEncode(array('errors' => $error_list)));
        } else
            die(Tools::jsonEncode(array('success' => true)));
             
    }
}

But the redirect request to http://localhost/shop/index.php?controller=order&ipa=19  don't get the custom fields....

 

Please help.

 

Taking into account that you need a two steep process to add a customization field in prestashop I think it will be a little more difficult to do than add a parameter to the url..

Share this post


Link to post
Share on other sites
  • 9 months later...

Hi,

Is the module still avaiable for use?

I'm using Prestashop 1.5.2.0.

 

It would be very useful for my e-commerce to create a cart from another website and don't be redirect back.

 

Thank you

Share this post


Link to post
Share on other sites
  • 2 months later...

Hi, I fix the module and work in all PS 1.6.x

 

Thanks

Hi Alfredo!

 

Can you please publish or send this fixed module for PS 1.6.x to me?

 

Cheers! ;)

Share this post


Link to post
Share on other sites
  • 3 weeks later...

I would to download this usefull module. Please where i can find the download link? Thanks

 

Hi Manfro88!

 

Did you finally download the module? Can you please publish it or send it to me? 

 

Cheers,

Share this post


Link to post
Share on other sites
  • 1 year later...
  • 6 months later...

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More