In the online stores on the engine, opencart have such a good property as related products, which when added to the current product-related items are automatically added and selected, for example, if we added to the sink faucet is a companion product to product is automatically added to the mixer and sink. etc
But sometimes this feature is not quite appropriate since we add accessories but as not contrary to most goods.
So in this tutorial I would like to talk about how to fix it.
All the changes we will be carried out in a single file and it is here /admin/model/catalog/product.php
So we find and open the above file and find in it the following code:
1 2 3 4 5 6 7 |
if (isset($data['product_related'])) { foreach ($data['product_related'] as $related_id) { $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); } } |
In this code, we remove or comment on some lines to get as in the example below:
1 2 3 4 5 6 7 |
if (isset($data['product_related'])) { foreach ($data['product_related'] as $related_id) { $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); //$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); //$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); } } |
Next we need to find the code:
1 2 3 4 5 6 7 8 9 10 11 |
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'"); if (isset($data['product_related'])) { foreach ($data['product_related'] as $related_id) { $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); } } |
And it will also remove or comment on how to get in the code below:
1 2 3 4 5 6 7 8 9 10 11 |
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); //$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'"); if (isset($data['product_related'])) { foreach ($data['product_related'] as $related_id) { $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); //$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); //$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); } } |
Well, this latest find and comment the following line:
1 |
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'"); |
Well, in principle, all goods are now made to be added specifically as related products, and feedback will not work, but there is a small flaw, all previously added items will need to add the new ...
No Comment
You can post first response comment.