chetwyn Posted January 2, 2012 Share Posted January 2, 2012 Hi Guys. I’m running 1.3.7 and having problems removing products from the Home Catalog. For example, I’ll create a new product and assign it to anything else other than home plus set the default cagtegory to what I have selected for example, if I have a catalogue of “handbags” I’’ firstly select the default category to handbags then uncheck the home check box as I don’t want that product to be displayed on the featured products part. Save and continue.. all works. OK, so now I want it to appear on the feature page so I assign that same product to the home category. Cool. All works.. I can now see the product. I then decide to remove it. When I save I get this error... Fatal error: Call to undefined method Product::deleteCategory() in C:\xampp\htdocs\presta1.3.7\classes\Product.php on line 553 The only way to get around this is to delete the product and then re add it... Please help !!! 1st image show the page b4 save, the other after I hit save Link to comment Share on other sites More sharing options...
chetwyn Posted January 2, 2012 Author Share Posted January 2, 2012 After going through the code I notice that Inveostore had updated the code base to 1.4. This seems to not work so I reverted the offending method back to 1.3. seems to work... I updated the product.php from the classes folder and replace new method they put: public function updateCategories($categories, $keepingCurrentPos = false) { if (empty($categories)) return false; $positions = array(); // get max position in each categories $result = Db::getInstance()->ExecuteS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_category` NOT IN('.implode(',', array_map('intval', $categories)).') AND id_product = '. $this->id .''); foreach ($result as $categToDelete){ $this->deleteCategory($categToDelete['id_category']); } // if none are found, it's an error if (!is_array($result)) return (false); if (!$this->addToCategories($categories)) return false; return true; } with the old code: public function updateCategories($categories, $keepingCurrentPos = false) { $positions = array(); $arraystring = implode(',', array_map('intval', $categories)); $result = 0; if (!empty($arraystring)) $result = Db::getInstance()->ExecuteS('SELECT IFNULL(MAX(`position`), 0) + 1 AS max, `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_category` IN('.$arraystring.') GROUP BY `id_category` '); if (!is_array($result)) return (false); foreach ($result AS $position) $positions[$position['id_category']] = $position; /* Product Update, so saving current positions */ if ($keepingCurrentPos) { if (!is_array($oldPositions = Db::getInstance()->ExecuteS('SELECT `id_category`, `id_product`, `position` AS max FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.intval($this->id)))) return false; foreach ($oldPositions AS $position) $positions[$position['id_category']] = $position; } $this->deleteCategories(true); $productCats = array(); foreach ($categories AS &$categorie) $categorie = intval($categorie); foreach ($categories AS $k => $productCategory) $productCats[] = '('.$productCategory.','.$this->id.','.(isset($positions[$productCategory]) ? $positions[$productCategory]['max'] : 0).')'; $result = Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'category_product` (`id_category`, `id_product`, `position`) VALUES '.implode(',', $productCats)); return ($result); } Now I can check and un check the "home" check box so I can add them to the features page. any thoughts ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now