Mpower Posted October 27, 2015 Share Posted October 27, 2015 Im looking to concatenate a sub-string of the product description on to the meta description when there is no product meta description being called. bellow is the section of seo.class.php i was trying to alter but as far as i can make out the smarty variable does not work in the seo.class.php file. Any suggestions ?public function meta_description($glue = ' - ') { if ($GLOBALS['config']->has('config', 'seo_metadata') && $GLOBALS['config']->get('config', 'seo_metadata') && !empty($this->_meta_data['description'])) { switch ((int)$GLOBALS['config']->get('config', 'seo_metadata')) { case self::TAGS_MERGE: if ($GLOBALS['config']->get('config', 'store_meta_description') && $this->_meta_data['description']) { $description[] = $this->_meta_data['description']; $description[] = $GLOBALS['config']->get('config', 'store_meta_description'); } else if ($this->_meta_data['description']) { $description = $this->_meta_data['description']; } else { $description = $GLOBALS['config']->get('config', 'store_meta_description'); } break; case self::TAGS_REPLACE: $description = $this->_meta_data['description']; break; } return (is_array($description)) ? implode($glue, $description) : $description; } else { return $GLOBALS['config']->get('config', 'store_meta_description') . $PRODUCT.description, 120; } } Quote Link to comment Share on other sites More sharing options...
bsmither Posted October 27, 2015 Share Posted October 27, 2015 Welcome MPower! Glad to see you made it to the forums.The above seems like a good choice to make an edit, but it's the wrong choice for a few reasons.Let's look instead at /classes/catalogue.class.php, near line 248 - the displayProduct() function.One of the first things this function does to gather the seo meta data from the product's database record and gives it to the SEO class.According to your objective:'description' => $product['seo_meta_description'], Change to: 'description' => ($product['seo_meta_description']) ? $product['seo_meta_description'] : strip_tags($product['description']),The product's actual description is used, but since the description is from the rich text editor, we need to strip out any HTML tags so they won't appear in the meta-description.Also, instead of ['description'], you could use the product's ['description_short'].Rendering the template is the second to the very last thing CubeCart does, so the Smarty variables (in that form) are not available yet. Quote Link to comment Share on other sites More sharing options...
Mpower Posted October 27, 2015 Author Share Posted October 27, 2015 hi bsmither i tried that and i didn't seem to have any effect at all. also looking back at my previous post i noticed i didn't clearly describe my objective. The store im working on has its store settings meta description set to merge product meta description. unfortunately this store has a lot of products without product meta descriptions so what happens is that a lot of products end up with generic and duplicate meta descriptions. My objective is to use the product description as the meta description, but only for products who are missing their product meta descriptions in the first place Quote Link to comment Share on other sites More sharing options...
bsmither Posted October 27, 2015 Share Posted October 27, 2015 I wonder if the array assignment operator is not compatible with the ternary operator.So, getting back to this:The original code: $meta_data = array( 'name' => $product['name'], 'path' => null, 'description' => $product['seo_meta_description'], 'keywords' => $product['seo_meta_keywords'], 'title' => $product['seo_meta_title'], ); On a new line after, add: $meta_data['description'] = (!empty($meta_data['description'])) ? $meta_data['description'] : $product['description_short'] ;The above statement says, if the description is not false-looking (actually has some content in it), then use it, otherwise use the product's short description.The function being edited applies to the page that gets displayed when viewing a Product Details page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.