Answer the question
In order to leave comments, you need to log in
Is it worth using regular OpenCart methods to change categories and products when importing from 1s?
I wanted to use the edit methods to save categories and products, but something is bothering the query code with its DELETE - INSERT .
$this->db->query("UPDATE " ..... WHERE product_id = '" . (int)$product_id . "'");
if (isset($data['image'])) {
$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'");
}
$this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
foreach ($data['product_description'] as $language_id => $value) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_description .....);
}
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
if (isset($data['product_store'])) {
foreach ($data['product_store'] as $store_id) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store ......);
}
}
$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'");
if (!empty($data['product_attribute'])) {
foreach ($data['product_attribute'] as $product_attribute) {
if ($product_attribute['attribute_id']) {
foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute .......);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
You can always use any import methods.
But using regular methods, it is likely that the developers took into account the update of several database tables, instead of one, which seems obvious.
For example, in Bitrix, when adding elements through the admin panel or api, a whole bunch of fields are automatically filled in, and if you do it yourself manually, you can go crazy.
At the same time, the Bitrix API does not simplify, but even complicates access to the database - your code becomes even more difficult than writing an SQL query. Therefore, we still resort to tricks like "query with SQL, upload via API"
Regarding your example, we see almost pure SQL in Opencart and therefore there is no difference - you will import it through your own database connection, not forgetting to escape special characters, or you will use Opencart, which is free, which means it is not responsible for anything and it is quite likely that such checks are also not made there, which makes a potential hole for hacking.
Another question - does it make sense to break something in an online store? According to the legislation, all payments usually go through payment services, where programmers work, who are responsible, and therefore grandmothers are paid for the service from each sale.
The question is - do you want to be to blame for the fact that someone took away all the client data, or is it easier to transfer it to another company? This is the eternal dilemma between scientists and businessmen. Some want to test everything and, despite the mistakes, make corrections, others want to never be guilty, and therefore they will use any excuse to fuck you with money.
And Hollywood happily sings along to this, saying that because of scientists, evil viruses infect humanity, so in our world it’s better not to do shit at all, but just wait until it happens. And, oddly enough, it won't.
Take a look at your customer. If there is no feeling in him that you need to try before you do it, but there is only “do it for me and quickly” - I would rather sing a song to him about the need to buy other companies, let this be his problem - lawsuits, courts, than yours - that the site was hacked because of you, but how could it be otherwise in their head?
Business as a whole is just three concepts:
1) money belongs to the cunning, not smart. These are different things.
2) never be guilty, your authority and appearance is more important than any work that no one will see, so it’s better not to do anything, but always have an emergency
3) if you see that someone has fallen, help him break more limbs, and tell everyone that "he himself wanted to fall, and you honestly helped"
And all this is achievable only if you yourself do nothing at all, but always have an extreme one.
And realizing this, what will be your actions? From the point of view of logic - do not work for business and for money. But this will make you dig the earth and grow products for yourself, which means quit programming ... so just get in the groove and smile, pretending that you are stupid and do not understand anything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question