Jump to content
Tuni-Soft

[Guide] The new customization system in PrestaShop 1.7

Recommended Posts

Hello,

 

As you might know, the customization system has been modified in PrestaShop 1.7

 

Now customizations can have a price and weight impact much like product combinations. This makes it easier for modules to include custom data in the client cart.
Plus, each customization will be displayed on a row of its own.

post-369615-0-05604600-1471264693_thumb.png

 

 

What has changed:

  • The table structure of `ps_customization_field`
    A new column was added: `is_module` which means that the field belongs to a module
    When this column has a value of 1, the field won't be displayed on the front
    Make sure to set the value to 1 if your module creates a custom field for the product
    Your module can set the value of the input `#product_customization_id` to include the customization in the cart
    Ideal scenario:
    - The client makes a customization and saves it via ajax
    - Your module returns an `id_customization` and puts it in `#product_customization_id`
    - Your module clicks the add to cart button
     
  • The table structure of `ps_customized_data`
    New columns: `id_module`, `price`, `weight`
    When you save a customization, set the `id_module` to the value of your module ID
    Set the `price` and `weight` to the corresponding price & weight of the customization
    Set the `value` to a row ID in your module's custom table where extra data about the customization is stored
    When PrestaShop system finds a customization that has an `id_module` it will trigger a hook
    This hook will be only passed to the concerned module (having an ID equal to the value in `id_module`)
    More on the hook below..
     
  • Saving the customization
    When saving the customization, set the quantity to 0. It will be updated by PrestaShop when the product is added to cart. In fact, the customization will always have the same quantity as the product row because each customization will be assigned to a separate product row in the cart.
     
  • Using the new hook
    This how to register the new hook
    $this->registerHook('displayCustomization')

     

    You can alter the displayed customization by returning some content related to the `value` (html allowed)

    public function hookDisplayCustomization($params)
    {
        $id_row = (int)$params['customization']['value'];
        return $this->functionToDisplayASummaryOf($id_row);
    }
  • Changes on methods
    Here are some method which were modified (Declaration And/Or Body)
    Product::getPriceStatic
    Product::getAllCustomizedDatas
    

     

I hope this is helpful if you're developing a new module or adapting your module for PrestaShop 1.7.

Feel free to ask if you encounter any difficulty. Your feedback will improve this guide.

 

 

  • Like 5

Share this post


Link to post
Share on other sites

Hi,

I put the code but seems it is incorrect. Please help. Can you show the functionToDisplayASummaryOf function code?

My code:

public function hookDisplayCustomization($params)
	{
		//print_r($params);
		$id_row = (int)$params['customization']['value'];
		//print_r($id_row);
		//return $this->functionToDisplayASummaryOf($id_row);
		//echo 'text display here';
		return 'text display here';
	} 

Ofcourse, I have reg this hook 

$this->registerHook('displayCustomization')

My question: Why the code in function hookDisplayCustomization can not run? (I try print or echo but nothing to display)

 

Thanks

Share this post


Link to post
Share on other sites

I am sloved. Because I am not re-install module, so the hook can not execute.

Thanks

Share this post


Link to post
Share on other sites

I'm not seeing any way here to associate a price with a customization as there are no hooks or methods in core classes to save the price.  

Share this post


Link to post
Share on other sites
On 07/08/2018 at 3:14 PM, rever5e said:

I'm not seeing any way here to associate a price with a customization as there are no hooks or methods in core classes to save the price.  

Hi,

It can be done if you save the customization programmatically

I didn't try hooking into the customization save process

Best regards

Share this post


Link to post
Share on other sites

Can I add a required/obligatory customization (with file upload) just to certain combinations and not just to the whole product itself?
If not, is there any module that can do it?

Share this post


Link to post
Share on other sites
En 15/8/2016 a las 2:38 PM, Tuni-Soft dijo:

Hello,

 

As you might know, the customization system has been modified in PrestaShop 1.7

 

Now customizations can have a price and weight impact much like product combinations. This makes it easier for modules to include custom data in the client cart.
Plus, each customization will be displayed on a row of its own.

post-369615-0-05604600-1471264693_thumb.png

 

 

What has changed:

  • The table structure of `ps_customization_field`
    A new column was added: `is_module` which means that the field belongs to a module
    When this column has a value of 1, the field won't be displayed on the front
    Make sure to set the value to 1 if your module creates a custom field for the product
    Your module can set the value of the input `#product_customization_idto include the customization in the cart
    Ideal scenario:
    - The client makes a customization and saves it via ajax
    - Your module returns an `id_customization` and puts it in `#product_customization_id`
    - Your module clicks the add to cart button
     
  • The table structure of `ps_customized_data`
    New columns: `id_module`, `price`, `weight`
    When you save a customization, set the `id_module` to the value of your module ID
    Set the `price` and `weight` to the corresponding price & weight of the customization
    Set the `value` to a row ID in your module's custom table where extra data about the customization is stored
    When PrestaShop system finds a customization that has an `id_module` it will trigger a hook
    This hook will be only passed to the concerned module (having an ID equal to the value in `id_module`)
    More on the hook below..
     
  • Saving the customization
    When saving the customization, set the quantity to 0. It will be updated by PrestaShop when the product is added to cart. In fact, the customization will always have the same quantity as the product row because each customization will be assigned to a separate product row in the cart.
     
  • Using the new hook
    This how to register the new hook
    
    $this->registerHook('displayCustomization')

     

    You can alter the displayed customization by returning some content related to the `value` (html allowed)

    
    public function hookDisplayCustomization($params)
    {
        $id_row = (int)$params['customization']['value'];
        return $this->functionToDisplayASummaryOf($id_row);
    }
  • Changes on methods
    Here are some method which were modified (Declaration And/Or Body)
    
    Product::getPriceStatic
    Product::getAllCustomizedDatas

     

I hope this is helpful if you're developing a new module or adapting your module for PrestaShop 1.7.

Feel free to ask if you encounter any difficulty. Your feedback will improve this guide.

 

 

I am creating a module of customization and I don't understand de mechanic of this tables.

 

For example where is the input #product_customization_id ?

I don't know how integrate my customization on the chart.

Now I make the customization for the product and in the product page I have de id of this customization but I don't know how to continue...

Share this post


Link to post
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

×

Important Information

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