From 527c15e2c320d411bd79d3bcfcd1a46be45db4e3 Mon Sep 17 00:00:00 2001 From: Ahe Date: Mon, 11 Nov 2013 12:15:55 +0000 Subject: [PATCH] #200: check for empty categories and categoryTypes in observer to prevent warning during auto meta generation --- .../FireGento/GermanSetup/Model/Observer.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/code/community/FireGento/GermanSetup/Model/Observer.php b/src/app/code/community/FireGento/GermanSetup/Model/Observer.php index 5685b0e..cf7995f 100644 --- a/src/app/code/community/FireGento/GermanSetup/Model/Observer.php +++ b/src/app/code/community/FireGento/GermanSetup/Model/Observer.php @@ -152,11 +152,18 @@ public function autogenerateMetaInformation(Varien_Event_Observer $observer) * Get the categories of the current product * * @param Mage_Catalog_Model_Product $product Product - * @return array Categories + * @return string Keywords */ protected function _getCategoryKeywords($product) { $categories = $product->getCategoryIds(); + + //Check for empty categories + if (true === empty($categories)) { + return array(); + } + + //If product categories were given fetch their names and build the keyword string $categoryArr = $this->_fetchCategoryNames($categories); $keywords = $this->_buildKeywords($categoryArr); @@ -221,6 +228,12 @@ protected function _fetchCategoryNames($categories) protected function _buildKeywords($categoryTypes) { $keywords = ''; + + //Check for empty category types + if (true === empty($categoryTypes)) { + return $keywords; + } + foreach ($categoryTypes as $categories) { $keywords .= implode(', ', $categories); }