Jump to content

[Guide] The new customization system in PrestaShop 1.7


Tuni-Soft

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 8
Link to comment
Share on other sites

  • 8 months later...

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

Link to comment
Share on other sites

  • 1 year later...
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

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...
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...

Link to comment
Share on other sites

  • 10 months later...

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

Link to comment
Share on other sites

  • 1 year later...

Hello,

Your question is not directly related to this subject

You can move the blocks in the theme template 

Look for blocks product_variants and product_customization in the file /themes/[theme]/templates/catalog/product.tpl

Cheers

  • Like 1
Link to comment
Share on other sites

  • 2 years 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...