Post by reygoch » Sat Sep 16, 2017 5:37 pm

Hi,
I'm making an extension that needs to update just some product details like price and availability. When looking through product model, editProduct function in particular, code is really weird and seemingly doesn't allow updating just some product attributes, but all possible attributes have to be passed in each time.

For example, every time product is updated it first deletes all existing product descriptions and than recreates them again. Sure, that is fine if you are only using data that is coming directly from product form in admin area since it populates all existing fields, but if I only want to update particular feature of my product from some other code than this is frankly stupid. I have to send in a whole nested array of attributes just to update 2 or 3 features.

For example, this code :

Code: Select all

$this->db->query("DELETE FROM "...

if (isset($data['product_image'])) {
	foreach ($data['product_image'] as $product_image) {
		$this->db->query("INSERT INTO "...
	}
}
Wouldn't it make much more sense this way? :

Code: Select all

if (isset($data['product_image'])) {
	$this->db->query("DELETE FROM "...
	foreach ($data['product_image'] as $product_image) {
		$this->db->query("INSERT INTO "...
	}
}
That way I can reuse product model in my code, pass in only attributes which I want to update, and not be afraid of accidentally deleting other fields on my product that I did not wish to delete.

Am I missing something, or is it really this stupid? If so, why?

Newbie

Posts

Joined
Mon Aug 10, 2015 12:40 am
Who is online

Users browsing this forum: No registered users and 7 guests