Reputation: 45
I am trying to put dynamic data drawn from a database (or flat-file even if this would work better) into the description field of products in Opencart3, based on the local store that the customer will be visiting.
What I have done on a previous website is, using the nearest store id, pull the data specific for the product and store from a database and display it in the description
An trivial example is for the Description to say "ask for Joe" for shoppers near store A and "ask for Sarah" if the shoppers are near store B.
So I'm looking for a way to do that with Opencart 3.0.3.2 on an Ubuntu 18.04 server with PHP 7.2, Mariadb 10.1 (and PostgreSQL 10).
The standard editor (Summernote) removes PHP tags, though I've read that this may be configurable, but I can't see where. Summernote allows Javascript tags but that is client side so I cannot pull data from the database with that.
Any suggestions for configuring the editor to leave the PHP tags, or some other suggestion for retrieving the data and inserting it into the webpage, will be very gratefully received.
Upvotes: 0
Views: 203
Reputation: 2295
I think your best option would be to work with the index action of the product controller: /catalog/controller/product/product.php
You'll need to get your current store_id
:
$store_id = $this->config->get('config_store_id');
And then edit this line to call another method that retrieves your data from the external database:
$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
Best practise here would be to add a new method to the product model in the file \catalog\model\catalog\product.php
Create a new method:
public function getExternalDescription($store_id, $product_id) {
// your logic here
}
Then have your product's controller file changed like this:
$data['description'] = $this->model_catalog_product->getExternalDescription($store_id, $product_id);
I would also suggest doing all of the above in an OCMOD or VQMOD rather than changing the core files. More on this here: OCMOD Wiki
Upvotes: 1