V
V
Vlad Bazarov2016-07-01 18:31:54
PHP
Vlad Bazarov, 2016-07-01 18:31:54

Can you help me find a bug in PHP code?

Good afternoon everyone,
Now I am redoing one module for Opencart and the task is to connect to the database.
Any ideas why it doesn't work?
The information that I pull out of the database is in category_description>type_prefix .
Here is the original code:

public function getProducts($allowed_categories, $vendor_required = false) {
$query = $this->db->query("SELECT p.*, pd.name, pd.description, m.name AS manufacturer, p2c.category_id, IFNULL (ps.price, p.price) AS price, ps.price AS special, wcd.unit AS weight_unit,
GROUP_CONCAT(DISTINCT CAST(pr.related_id AS CHAR) SEPARATOR ',') AS rel
FROM " . DB_PREFIX . "product p JOIN " . DB_PREFIX . "product_to_category AS p2c ON (p.product_id = p2c.product_id)
" . ($vendor_required ? '' : 'LEFT ') . "JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m. manufacturer_id)
LEFT JOIN " .DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)
...
GROUP BY p.product_id");
return $query->rows;
}

Here is the modified one:
public function getProducts($allowed_categories, $vendor_required = false) {
$query = $this->db->query("SELECT p.*, pd.name, pd.description, pd.type_prefix , m.name AS manufacturer, p2c .category_id, IFNULL(ps.price, p.price) AS price, ps.price AS special, wcd.unit AS weight_unit,
GROUP_CONCAT(DISTINCT CAST(pr.related_id AS CHAR) SEPARATOR ',') AS rel
FROM " . DB_PREFIX . "product p JOIN " . DB_PREFIX . "product_to_category AS p2c ON (p.product_id = p2c.product_id)
" . ($vendor_required ? '' : 'LEFT ') . "JOIN " . DB_PREFIX . "manufacturer m ON (p. manufacturer_id = m.manufacturer_id)
LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)
LEFT JOIN " . DB_PREFIX . "category_description pd ON (p.type_prefix = pd.type_prefix)
...
GROUP BY p.product_id");
return $query->rows;
}

I would appreciate your help!
Upd
I noticed that it would be nice to add the typePrefix attribute to the module, otherwise Yandex support without it swears. It was decided to fix this. So, I added a new column to the database, added a field for categories, in general, now you can write your typePrefix value to the database through the admin panel category menu. Everything is ok with this.
However, you also need to display this value in a YML list.
At the beginning, I added typePrefix to the allowed fields (changed the catalog/controller/feed/yamarket.php file):
$allowed = array('url', 'price', 'currencyId', 'categoryId', 'picture', 'store', 'pickup', 'delivery', 'name', 'typePrefix', 'vendor', 'vendorCode', ‘model’...

Okay, it works. And now - the moment of truth: you need to display the information that is stored in the database at category_description>type_prefix here:
$data['currencyId'] = $currency_default['code'];
      $data['categoryId'] = $product['category_id'];

      $data['typePrefix'] = $oc_category_description['type_prefix’]; //Вот сюда. Здесь пытался вывести значение.

      $data['vendor'] = $product['manufacturer'];
      $data['vendorCode'] = $product['model'];

Well, that's all. I can't get it, even kill yourself. Did different versions of the code. I also tried to make changes in /catalog/model/yamodel.php, where there is a connection to the database (as far as I understand). Then the part with the offer disappeared altogether.
Both files:
1
2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kravchenko, 2016-07-01
@mydearfriend

LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)
LEFT JOIN " . DB_PREFIX . "category_description pd ON (p.type_prefix = pd.type_prefix)

two identical aliases to different tables

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question