PHP PDO snippet to get products from your Opecart store by category or manufacturer

Write By: comprido Published In: ROOT Created Date: 2021-09-04 Hits: 95 Comment: 0

Sometimes we want to retrieve information from our store products to display them in another website/s.

With this useful piece of code you can retrieve that information easily. Remember to remove the filters you may not need, as manufacturer, category or store_id as well as change the category id, manufacturer id or store id to match yours.

<?php $pdo = new PDO("mysql:host=$servername;dbname=$database", $username, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
$query = $pdo->prepare("SELECT `oc_product`.`product_id`,`name`,`description`,`image`,`price`,`keyword` FROM `oc_product`
LEFT JOIN `oc_product_to_category`
   ON `oc_product_to_category`.`product_id` = `oc_product`.`product_id`
LEFT JOIN `oc_product_description`
   ON `oc_product_description`.`product_id` = `oc_product`.`product_id`
LEFT JOIN `oc_product_to_store`
   ON `oc_product_to_store`.`product_id` = `oc_product`.`product_id`
LEFT JOIN `oc_url_alias`
   ON (`oc_url_alias`.`query` LIKE  CONCAT('%',`oc_product`.`product_id`,'%'))
WHERE `oc_product_to_category`.`category_id` = 'XXX' AND `oc_product`.`status` = '1' AND `oc_product`.`date_available` <= NOW() AND `oc_product`.`manufacturer_id`='XXX' AND `oc_product_to_store`.`store_id` = 'XXX'
ORDER BY `oc_product`.`product_id` DESC");
$query->execute();
$products = $query->fetchAll(PDO::FETCH_ASSOC);
if ((!$query->rowCount() == 0)) {
 foreach ($products as $row => $result) {
echo $result['name'];
echo  $result['description'];
echo  $result['image'];
echo $result['price'];
echo  $result['keyword'];
 }
}
?>

See on Stackoverflow

Leave A Comment

Captcha


Latest Blog

Read more

PHP PDO snippet to get products from your Opecart store by category or manufacturer

Sometimes we want to retrieve information from our store products to display them in another webs...

Read more

Bookings and Auto Quotes PWA Website based on selections

Bookings and Auto Quotation PWA + AddressFinder plugin + Nexmo SMS...

Read more

justgrass.com.au

Online Sales Of Ornamental Grasses & Groundcovers
Just Grass is an Online Business del...