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

I added some customization fields to my products. And now, if I add an order via the BO it always puts 2 items in the cart instead of 1. Does someone know why this is happening in the BO?

Share this post


Link to post
Share on other sites

The hook ActionCartSave will run 2 times :).

That hook added for both action add new and update cart on prestashop core.

You  can try solution:

- Try update again your cart

- Remove old cart then add insert new by manual

- override or make new controll for that

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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