Post by Reptile » Sun Jul 23, 2017 11:00 pm

What's the best way in Opencart 3.x to add data to tables?
As from Opencart 3.x you are no longer aloud to add data to existing tables other then the settings table.
Some of my extensions add data to for example oc.product.description.
What is the best way/place to store data and call it for these extensions?

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by artcore » Mon Jul 24, 2017 2:23 am

You have to create a new table and then use JOIN on an existing one from oc

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by Reptile » Mon Jul 24, 2017 2:34 am

But what is wise?
Create a new table per extension or create 1 new table and use it for all my extensions which need it?

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by artcore » Mon Jul 24, 2017 4:26 am

I would create a table for each mod when needed.
One table to support all your extensions would be hard to maintain and possibly have a lot of overhead for unused columns.

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by Reptile » Mon Jul 24, 2017 5:05 am

Yeah you are right I thought so.
Any tips on how to use the left joins for a table like oc_product_description.

Normally I would add a new column to it and it is linked to the product.

But when I create a new table I don't have all the product id's from the oc_product_description.
How would I link them with a left join?

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by daveyoi » Mon Jul 24, 2017 5:12 am

For performance reasons, you should try to join on a primary key or an indexed field. For us, this means we are creating a table per data item in the default opencart dataset for each module.

oc_product.product_id
oc_mymodule_product with your additional columns and joined on product_id

Code: Select all

select * from oc_product p
left join oc_mymodule_product mp on p.product_id = mp.product_id
oc_information.information_id
oc_mymodule_information with your additional columns and joined on information_id

Code: Select all

select * from oc_information i
left join oc_mymodule_information mi on i.information_id = mi.information_id

Image
Tristar Web Solutions


New member

Posts

Joined
Sun Oct 05, 2014 2:38 am

Post by Reptile » Fri Jul 28, 2017 8:07 pm

Thank you I will give it a try

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by Reptile » Wed Nov 15, 2017 10:07 pm

How would you fill your own table with the right amount of product_ids ?
To join them you’ll need matching product_ids but with your own custom table you won’t have them.

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by straightlight » Wed Nov 15, 2017 10:20 pm

As from Opencart 3.x you are no longer aloud to add data to existing tables other then the settings table.
That analogy would be incorrect. What it simply requires with your own modules is to load the database models. On this topic, the products are being used as an example. In this case, assuming you are posting your values from an HTML form:

Code: Select all

$this->load->model('catalog/product');

$product_id = $this->model_catalog_product->addProduct($this->request->post);
which does not require any settings to be first gathered. As for the product IDs, that would be one way to see it. However, take note that the product model and / or the product sku is also another way to gather the data especially with the use of APIs.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: niagato, TheDeerKami and 448 guests