Hello,
I'm new on OpenCart but I worked before on Magento, Prestashop and Tomatocart. Each addXXX functions in models (ex. addManufacturer(), addProduct()...) have no return value. Shouldn't it be more useful to add one which can be the id of the inserted record. For example in model/catalog/manufacturer:
public function addManufacturer($data) {
$this->db->query("INSERT INTO " . DB_PREFIX . "manufacturer SET name = '" . $this->db->escape($data['name']) . "', sort_order = '" . (int)$data['sort_order'] . "'");
.....//....
$this->cache->delete('manufacturer');
return $manufacturer_id;
}
This way, we can recover directly the id of an added manufacturer.
It's very useful in my case because I'm developping an import module and I have a table oc_import_manufacturer which I use to synchronize data with my supplier external data. The aim is when I decide to import the data of this table in the oc_manufacturer, I can recover directly the id from the record inserted to put it back in the table oc_import_manufacturer.
But it's not the only use.
Thanks in advance,
Helgvor STOLL
I'm new on OpenCart but I worked before on Magento, Prestashop and Tomatocart. Each addXXX functions in models (ex. addManufacturer(), addProduct()...) have no return value. Shouldn't it be more useful to add one which can be the id of the inserted record. For example in model/catalog/manufacturer:
public function addManufacturer($data) {
$this->db->query("INSERT INTO " . DB_PREFIX . "manufacturer SET name = '" . $this->db->escape($data['name']) . "', sort_order = '" . (int)$data['sort_order'] . "'");
.....//....
$this->cache->delete('manufacturer');
return $manufacturer_id;
}
This way, we can recover directly the id of an added manufacturer.
It's very useful in my case because I'm developping an import module and I have a table oc_import_manufacturer which I use to synchronize data with my supplier external data. The aim is when I decide to import the data of this table in the oc_manufacturer, I can recover directly the id from the record inserted to put it back in the table oc_import_manufacturer.
But it's not the only use.
Thanks in advance,
Helgvor STOLL
Use :
Code: Select all
$this->db->query("INSERT INTO " . DB_PREFIX . "manufacturer SET name = '" . $this->db->escape($data['name']) . "', sort_order = '" . (int)$data['sort_order'] . "'");
$manufacturer_id = $this->db->getLastId();
TOP 5 Opencart Extensions:
1:Opencart Reservations
2:Stock Report, import/export stock levels with Excel
3:3D Carousel
4:Product Price Changer by Category
5:Set price Inclusive Taxes
DEMO SHOP
Hi daik01,
Thank you for the solution but if I well understand the model concept, it matches with the "business rules/layer". So, your solution deals with the Data Layer of the architecture and then, all the business rules are shunted and then the modifications of these rules will not be taken into account.
I think it's more coherent to use the addManufacturer or addProduct function to insert a new object in the database instead of inserting records of each concerned tables which can then breaks some business rules of the system (and perhaps break the consistency of the database, for example in a calculated field).
I change the product, the manufacturer & the category model on my dev (it's only one line of code in each file!!!) but I think it more useful to change this definitively in the core.
Best regards,
Helgvor STOLL
Thank you for the solution but if I well understand the model concept, it matches with the "business rules/layer". So, your solution deals with the Data Layer of the architecture and then, all the business rules are shunted and then the modifications of these rules will not be taken into account.
I think it's more coherent to use the addManufacturer or addProduct function to insert a new object in the database instead of inserting records of each concerned tables which can then breaks some business rules of the system (and perhaps break the consistency of the database, for example in a calculated field).
I change the product, the manufacturer & the category model on my dev (it's only one line of code in each file!!!) but I think it more useful to change this definitively in the core.
Best regards,
Helgvor STOLL
I made the same suggestion some weeks ago, and also posted it as an issue on github.
So far Daniel (the lead developer) hasn't introduced requested change. When I have time I'll add a more detailed pull request for this on github.
So far Daniel (the lead developer) hasn't introduced requested change. When I have time I'll add a more detailed pull request for this on github.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Wahou, it's exactly what I mean (for te return id).
My second step in this forum was to propose a better overriding system (or engine as for the module you linked me). Vqmod is nice to place personal hooks but it can become heavy when we want to specialize (inherit) other classes by adding new fields for example. My idea was to add a folder "components" (or override but it looks like Prestashop, grrrr....) at the root folder. In this case, instead of putting the traditional file structure, the aim was to package all the component files in the same folder.
Example: Imagine we would like to create a new component "Import", I would then have:
components/import/admin/controller
components/import/admin/model
components/import/admin/view
components/import/catalog/controller
components/import/catalog/model
components/import/catalog/view
After this, we can modify the loader to first look for the model, template & controller files in the components folder and then in the traditional folders. I will develop when I will have a little more time.
Regards.
Helgvor STOLL
My second step in this forum was to propose a better overriding system (or engine as for the module you linked me). Vqmod is nice to place personal hooks but it can become heavy when we want to specialize (inherit) other classes by adding new fields for example. My idea was to add a folder "components" (or override but it looks like Prestashop, grrrr....) at the root folder. In this case, instead of putting the traditional file structure, the aim was to package all the component files in the same folder.
Example: Imagine we would like to create a new component "Import", I would then have:
components/import/admin/controller
components/import/admin/model
components/import/admin/view
components/import/catalog/controller
components/import/catalog/model
components/import/catalog/view
After this, we can modify the loader to first look for the model, template & controller files in the components folder and then in the traditional folders. I will develop when I will have a little more time.
Regards.
Helgvor STOLL
Have you had a look at our Override Engine? It would use something like this in its directory structure:helgvor_stoll wrote:Wahou, it's exactly what I mean (for te return id).
My second step in this forum was to propose a better overriding system (or engine as for the module you linked me). Vqmod is nice to place personal hooks but it can become heavy when we want to specialize (inherit) other classes by adding new fields for example. My idea was to add a folder "components" (or override but it looks like Prestashop, grrrr....) at the root folder. In this case, instead of putting the traditional file structure, the aim was to package all the component files in the same folder.
Example: Imagine we would like to create a new component "Import", I would then have:
components/import/admin/controller
components/import/admin/model
components/import/admin/view
components/import/catalog/controller
components/import/catalog/model
components/import/catalog/view
After this, we can modify the loader to first look for the model, template & controller files in the components folder and then in the traditional folders. I will develop when I will have a little more time.
Regards.
Helgvor STOLL
override/addon-name/admin/controller
override/addon-name/admin/model
override/addon-name/admin/language
override/addon-name/catalog/controller
override/addon-name/catalog/model
override/addon-name/catalog/language
As regards overriding templates: OpenCart already has this feature. You can define your own webtheme. In an ideal scenario all your new web theme needs is the modified CSS and images, in real world web theme you'd probably also have modified common/header.tpl and common/footer.tpl templates.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Hi,
I didn't have time yet. I'm developping now an import module to synchronize my (future!!!) website with my supplier catalog. I must finish it before this tuesday but I will have a look after this. I hope I could at this time have my website online.
I really think, compared to other e-commerce platforms I used before, that OpenCart could be one of the best e-commerce platform with a few improvements.
Thanks to the developpers team and to Mr Daniel Kerr for this initiative.
I let you know when I look at your engine.
Regards.
Helgvor STOLL
I didn't have time yet. I'm developping now an import module to synchronize my (future!!!) website with my supplier catalog. I must finish it before this tuesday but I will have a look after this. I hope I could at this time have my website online.
I really think, compared to other e-commerce platforms I used before, that OpenCart could be one of the best e-commerce platform with a few improvements.
Thanks to the developpers team and to Mr Daniel Kerr for this initiative.
I let you know when I look at your engine.
Regards.
Helgvor STOLL
Hi, I just put my website online (http://www.ebizness-services.com) and despite of the very good quality of OpenCart, some changes in the can really improve this framework: factorization (a lot of code looks like cutted and pasted as the breadcrumbs call in the tpl file, ..), this famous id as in the title is really important when we want to import external data, changing the place of some codes like calculated fields (put it in the model instead of the controller which prevent the duplication of the calculus), ....
@+
@+
Who is online
Users browsing this forum: No registered users and 4 guests