concept.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. *******
  2. Concept
  3. *******
  4. .. image:: images/configuration-process-diagram.png
  5. :align: center
  6. :alt: alternate text
  7. Configurable Template (product.template)
  8. ----------------------------------------
  9. Product Templates with the boolean config_ok field checked become Configurable Templates.
  10. When config_ok is True the template does not generate variants automatically anymore.
  11. The attributes set on the template are only mere instructions for a configurator to generate a user
  12. friendly interface.
  13. Configuration interfaces
  14. ------------------------
  15. In order to give control to the user on the options he can pick we must generate a user friendly interface.
  16. We have provided at the time of this writing two configuration interfaces: The Backend Wizard and Website / Ecommerce Configurator.
  17. These interfaces read data from the configurable templates (Attributes, Values, Configuration Restrictions / Steps / Images etc).
  18. Using this information we are able to generate an interface that allows the user to select the available options on the product.
  19. We also have quite a few handy helper methods on the product.template to operate a configuration interface.
  20. The most important part is enforcing restrictions so users cannot make mistakes and generate unbuildable variants.
  21. Configuration Session (product.config.session)
  22. ----------------------------------------------
  23. Whenever a user starts a configuration process, his selections must be saved in a session.
  24. This way the user does not loose his progress when moving through multiple steps and he can also save his configuration.
  25. Configuration sessions store the options selected by the user in either interface and validates them according to the restrictions applied on the product.template
  26. Configurable Products (product.product)
  27. ---------------------------------------
  28. Same as the product.template the configurable products or variants have a config_ok boolean field.
  29. After a configuration session is valid and findal we can use the information form the session to generate a new product variant.
  30. *********
  31. Structure
  32. *********
  33. The logic is at the time of this writing divided between 3 modules:
  34. 1. Product Configurator Base
  35. - This module holds the main methods required to build configuration interfaces, this includes:
  36. a. Prevention of automatically generated variants.
  37. b. Introduction of Required, Multi, Custom fields for attribute lines.
  38. c. Configuration restrictions or configuration rules.
  39. d. Configuration steps.
  40. e. Configuration images.
  41. f. Linking attribute values to product variants.
  42. g. Managing active configuration sessions for external configurators.
  43. h. Helper methods for creating, validating, searching configurable variants and more.
  44. 2. Product Configurator Wizard
  45. - Based on the Product Configurator Base module it provides a native Odoo wizard with dynamically generated content.
  46. - Integrated with backend models such as sale.order, mrp.production etc. can directly create and edit configurable variants directy to the related lines of the model.
  47. 3. Website Product Configurator
  48. - Provides a web based form in the front-end for users to generate variants fully integrated with the e-shop module.
  49. **********************
  50. product.template model
  51. **********************
  52. The product.template object has a boolean field 'config_ok' that is used to determine if it is a regular template product or a configurable one. This is the marker that activates all the related functionality, without it behavior of the original model remains completely unchanged.
  53. Once this is checked the product.template:
  54. 1. No longer generated variants automatically
  55. 2. Has 3 extra fields on the attribute lines (Required, Multi, Custom) added by the base
  56. 3. Shows the 'Configurator' tab reveiling configuration information also added by the base.
  57. ****************************
  58. Website Product Configurator
  59. ****************************
  60. As with all the website_* modules, most of the logic lies in the controllers (commonly located in module/controllers/). In our controller located at the aformentioned location in website_product_config/controllers/main.py we have our main class WebsiteProductConfig.
  61. At the beginning of the class we define our two main routes used: cfg_tmpl_url, cfg_step_url. These can be changed by importing the class and overriding the properties with new values if one wishes to change the route.
  62. ****
  63. Flow
  64. ****
  65. action_configure()
  66. ==================
  67. By accessing a configurable product using the routes above this is our first method that fires. It will run on every page load
  68. The first job of this method is to generate a dictionary of values that will be later used in the qweb templated also known as updating the qwebcontext
  69. cfg_vars = self.config_vars(product_tmpl, active_step=config_step)
  70. Next we redefine the post argument given by the standard Odoo http layer as this does not support 'multi' data (input radio with same name). So we parse the werkzeug post with a separate method in which we organize multiple values in a list.
  71. post = self.parse_config_post(product_tmpl)
  72. A differentiation must be made between accessing a configurable product (or a different configuration step) or posting configuration data via the form. This is why we look for the POST method on the werkzeug httprequest **if request.httprequest.method == 'POST':**
  73. Sanitization of data to prevent invalid / malicious input is done via config_parse. We will use only the output from this method to update configuration values
  74. parsed_vals = self.config_parse(product_tmpl, post, config_step)
  75. If no errors were returned from the parsing method we can update the configuration for this user. This is used to retrieve the configuration values at a later time to pre-fill the values in the form. Also when the configuration is finished we can just create a new configurable variant using the validated and stored values.
  76. The related product.config.session model is updated with the validated values from the frontend and can be uniquely identified using the unique session id.