U
U
unlik2016-06-07 21:58:54
CMS
unlik, 2016-06-07 21:58:54

Automatic meta tags?

Who knows how to auto-generate meta tags in opencart?
It is necessary according to the principle "Buy 'Product Name' in Moscow"
But I need to save those meta tags that are already registered. And for the rest, set according to the template.
Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladislav Startsev, 2016-06-07
@esvlad

The simplest, in the file site_name/admin/model/catalog/product.php
At the end you add your own method, for example:

private function getMyKeywords($data){
  $keyword_array = array(
    'Купить '.$data.' в Москве';
    //Тут собственно додумываешь как организовать шаблон
  ); 
  return implode(', ', $keyword_array);
}

Next, in the addProduct method, you find
foreach ($data['product_description'] as $language_id => $value)
I have line 14.
and add the following before loading the data:
$value['meta_keyword'] .= $this->getMyKeywords($value['name']);

W
web-mechanic, 2016-06-09
@amfetamine

Some wild things went...
For a product card:
Meta tags are set in /catalog/controller/product/product.php here prntscr.com/befqtm
In your case prntscr.com/beft8i
If you do not need the first letter in the product name to lowercase, then remove the lcfirst() function.
The ucfirst() function is written in the screenshot, I made a typo, I need lcfirst()

S
Serge Tkach, 2021-03-02
@SergeTkach

Probably, for such a simple phrase, it is enough to enter it directly into the code.
Find the following controller code. To do this, in the file "catalog/controller/product/product.php" we find the following line:

$this->document->setTitle($product_info['meta_title']);

PS
And remember, the client pays for a working solution in the shortest possible time, and not for the amount of code written by himself.
And before it, insert the following code:
// Проверям, что мета-теги не пусты + что контент-менеджер не скопипастил название тоавар, что тоже случается :)
if (!$product_info['meta_title'] && $product_info['meta_title'] != $product_info['name']) {
    $product_info['meta_title'] = 'Купить ' . $product_info['name'] . ' в Москве';
}

if (!$product_info['meta_description'] && $product_info['meta_description'] != $product_info['name']) {
    $product_info['meta_description'] = $product_info['name'] . ' Купить в Москве по выгодным ценам';
}

But such simple meta tags are not always suitable. For example:
  • Multilingual store
  • You want to add numbers to the meta tags. The price is the best. But you can also number of reviews, rating
  • You want to add a city name to the meta tags, but you have more than one city. For example, you have substores for cities (CityManager or multistore is used)
  • Do you want to enter a product category?
  • You want to register significant (key) product attributes
  • You want to automate the completion of meta tags for categories as well. And there use data such as the number of products in the category, the maximum or minimum price in the category

In such cases, writing the code that implements this will take a day or several days, depending on the end goal. And also imagine that you have already handed over the project, and started doing something completely different. And the customer calls in a couple of days and says: you need to change the phrase. And what, again climb into the code and change?
It's easier to use a module in which everything listed is already there. And meta tag formulas are set by the user in the site admin panel. For example, there is a module for automatically filling meta tags SEO Tags Generator .
By the way, there is a setting for automatic substitution only if the meta tags are not filled. Extra spaces are removed (which just doesn’t happen when importing goods from 1C ...) You can use the condition that if a product costs more than 1500 r, delivery is free (also a good advantage among competitive snippets).
You can also set up separate rules for products of some individual categories, because not all stores sell the same type of product.
The most interesting thing is that the price of the module is only 3 hours of a programmer's work (average salary 68,791 ₽) as of 03/02/2021
P.S.
And remember, the client pays for a working solution in a reasonably fast time frame, not for the amount of code they write themselves!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question