PrestaShop开发的基础知识

PrestaShop的构想是第三方模块可以轻松的构建在其基础上, 从而让它成为一个比较容易定制的电商软件.

PrestaShop的定制基于三种可能性:

  • 主题(Themes)
  • 模块(Modules),
  • 重写(Overriding).

主题在设计师指南里有全面的探讨.

模块和系统重写在开发者指南中探讨, 从下面的概念一节开始. 你可以在下面其各自的章节了解到更多信息:

默认, PrestaShop提供了超过100个模块, 使你可以快速免费的启动你的在线业务.

另外在插件(Addons)市场上还有超过3000个可用的模块. 这些额外的模块有些是Prestashop公司开发,有些是社区的成员开发,并以实惠的价格出售. 作为开发者,你也可以在这个网站上分享你的模块, 还能获得你的作品售价70%的金额. 立即注册!

概念

在写你自己的模块之前,你应该要对PHP和面向对象编程熟悉.

你可以在这里学习PHP:

你可以在这里学习面向对象编程:

模块(Modules)是PrestaShop的扩展, 使任何开发者都可以添加以下内容: * 为PrestaShop提供其它的新功能. * View additional items on the site (product selection, etc.). * 与其它电商服务(购买指南, 支付平台, 物流等等)通信.

重写(Overriding)本身就是一个系统, PrestaShop使用完全的面向对象代码. 这样做的一个优点是, 使用正确的代码体系结构, 可以使用自己的自定义代码轻松的替代或扩展核心代码的一部分, 而无需改动核心代码. It is not recommended to use an override in a module that you intend to distribute (for instance through the PrestaShop Addons marketplace), and they are forbidden in partner modules. Keep them for your own shop.

PrestaShop的技术架构

PrestaShop 基于三层架构:

  • 对象/数据. 数据库的访问是通过classes目录下的文件控制.
  • 数据控制. 用户提供的内容由根目录下的文件控制.
  • 设计. 所有的主题文件在themes目录下.

这与Model>View>Controller (MVC) 架构原则相同, only in a simpler and more accessible way.

While all versions of PrestaShop up to 1.6 took pride in only using a custom architecture, it was decided to incorporate the Symfony PHP framework starting with PrestaShop 1.7.

The driving idea is that we want our code to be more robust, more modular, and fully testable. The 1.6 architecture, inherited from version 1.5 and years of PrestaShop development, is not getting any younger, and its age is really starting to show.

Using a proven and popular open-source framework will allow us to focus on our core business code (managing a cart, handling orders, calculating prices and taxes, generating invoices, etc.) with greater efficiency, while enjoying the stability of a globally recognized framework.

三层架构有许多优势:

  • It’s easier to read the software’s code.
  • Developers can add and edit code faster.
  • Graphic designer and HTML integrators can work with the confines of the /themes folder without having to understand or even read a single line of PHP code.
  • Developers can work on additional data and modules that the HTML integrators can make use of.

Model

A model represents the application’s behavior: 数据处理,数据库交互等.

It describes or contains the data that have been processed by the application. It manages this data and guarantees its integrity.

View

view是与用户交互的界面

它的第一个角色是显示由model提供的数据.它的第二个角色是处理所有用户的行为(鼠标点击,元素选择,按钮等), 并且将这些事件发送给controller.

view不做任何处理; 它只显示model处理的结果, 并与用户交互.

Controller

Controller管理着Model和View之间的同步事件,并根据需要进行更新。 它接收所有的用户事件并触发要执行的操作。

If an action needs data to be changed, the Controller will “ask” the Model to change the data, and in turn the Model will notify the View that the data has been changed, so that the View can update itself.