So far i managed to create a table and upload files into the database via the admin side of my opencart 3.0.2.0. Everything is working fine and all the files are uploaded sucessfuly to the database.
After that i have managed to relate each file to a particular product and store that in the databse table product_to_mp3 which contains only the product_id and the mp3_id
Now what I am trying to achieve in the storefront section is to find the filename(i want to display its value) for the particular mp3 file by comparing and checking matching mp3_id for product_id in the table product_to_mp3 and get the filename for that mp3_id from the table mp3
P.S All of the tables are with the standart Prefix OC_
Here is the code i have added to catalog/controller/product/product.php:
Code: Select all
$mp3names = $this->model_catalog_product->getProductMP3s($this->request->get['product_id']);
foreach ($mp3names as $mp3name) {
$data['mp3s'][] = array(
'name' => $mp3name['filename'],
);
}
Here is the code i have added to catalog/model/catalog/product.php:
Code: Select all
public function getProductMP3s($mp3_id) {
$product_data = array();
$query = $this->db->query("SELECT filename FROM " . DB_PREFIX . "mp3 m LEFT JOIN " . DB_PREFIX . "product p ON (m.mp3_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_mp3 p2m ON (p.product_id = p2m.product_id)");
foreach ($query->rows as $result) {
$product_data[$result['filename']] = $this->getProduct($result['filename']);
}
return $product_data;
}
Code: Select all
<div id="mp3filename">{{ mp3s.filename }}</div>
I would be very thankfull if you even just give me guidance on how i could solve that.
Thank you in advance