Product Import and Menu items

  • Posts: 64
  • Thank you received: 6
  • Hikashop Business
2 years 9 months ago #339554

-- HikaShop version -- : 4.4.3
-- Joomla version -- : Joomla! 3.9.23
-- PHP version -- : 7.4.28

Hello.

I need to import a fair amount of products from another site to Hika.
The process works, I did a small test and the csv is imported correctly.
Since these test products don't have a menu item, they inherit the template of the listing page they belong to. Which is not what I really want.

Now, since we are talking about 100 products to import, what I need is a suggestion on how to proceed.
Should I manually create a new menu item for each product?

IF NOT:
- How can I assign a template to these pages?
- Or at least, is it possible to assign a class to the page or body? So that you have control over what is displayed on the page. Some modules on the list page are not useful on the product pages and vice versa.

IF YES:
- Is there any way to automate the process of creating menu items from products?
- If not, should I leave the metadata, on J menu item, and only fill in the meta-fields on product?

Thank you!
Davide

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 9 months ago #339557

Hi,

The extension Advanced modules manager Pro ( regularlabs.com/advancedmodulemanager ) has an integration with HikaShop which allows you to restrict the modules based on the category of the product or based on the type of the page (a listing page, a details page, etc).

An alternative is to use the "canonical URL" setting of each product.
This setting allows you to tell the search engines which is the URL you want to be indexed for each product.
In the HikaShop configuration, you have the setting "force canonical URLs on listings". When you activate it, the system will automatically use the canonical URL on the listings instead of dynamically generating the URL.
So you could create an extra hidden menu item of the type "products listing" and use the URL of the product generated for that menu item to fill the "canonical URL".
So for example:
You have the main menu item "shop".
When you access the products in that menu item, you get the URL "shop/product/xx-yy" where xx is the id of the product and yy the alias of the product.
You create a hidden menu item "my-shop" and you enter the URL "my-shop/product/xx-yy" in the "canonical URL" setting of the product with the id xx.
With that "force canonical URLs on listings" setting activated, the link of the product in the "shop" menu item will now be "my-shop/product/xx-yy".
And thus, you'll be able to setup a different template, and different modules between the listing and each product using the "menu assignement" setting of Joomla as they will use a different menu item.
And with a mass action (menu System>Mass actions) with an action "update the values" on the column "product_canonical", you could use the "string" mode to generate the canonical URL for all the products like so:
my-shop/product/{product.product_id}-{product.product_alias}

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 6
  • Hikashop Business
2 years 9 months ago #339643

Hi Nicolas, in the next days I'll try your suggestion.
I'll report back if have any problem.

Thank you!
Davide

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 6
  • Hikashop Business
2 years 8 months ago #339699

Hello Nicolas.
I was trying your second solution, to avoid the need of a new extension (Even if Regular Labs creates good products)
I have just a problem with the mass-action.
If I put your string, it doesn't change the {product.product_id}-{product.product_alias} with the correct value.
In the screenshot below you can see the result.
Of course, I've tried different solutions, like without "product.", but nothing does the job.
Where am I wrong?

And one more question: would be possible to add also the manufacturer name in the Canonical URL building process.
My actual folder tree is this:
- Seed
-- Autoflowring
--- Product
Now, as I'm adding new manufacturers, and following what you suggested, the tree will be
- Seed
-- Autoflowering
--- Manufacturer
---- Product

It would be nice to generate, via Mass-Action, a Canonical URL like
seed/autoflowering/{manufacturer_name}/{product_alias}

Thank you!
Davide

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 8 months ago #339700

Hi,

Try like this then:

CONCAT('seed/autoflowering/',product.product_id,'-',product.product_alias)
with the "operation" mode instead of "string".

Last edit: 2 months 2 weeks ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 6
  • Hikashop Business
2 years 8 months ago #339731

It works if I clear all the blank spaces in your string.
Thank you!

About the second question of the previous mail: adding also the manufacturer name inside the canonical URL string, do you have any suggestion?
It seems that this data is stored into another table. Is it possible to recall it with this Mass Action?

It's not a big problem, as we don't have a huge amount of brands, so I can create different Mass Actions for the specifics barnds.

Have a nice day
Davide

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 8 months ago #339732

Hi,

Only product.product_manufacturer_id is available with the "update the values" action.
You could still do it with a mass action, but you would have to switch to a PHP action and write PHP code to do everything.
It's possible but more complex.
I suppose the code would be something like that:

$categoryClass = hikashop_get('class.category');
$brand = $categoryClass->get({product_manufacturer_id});
$productClass = hikashop_get('class.product');
$product = new stdClass();
$product->product_id = {product_id};
$product->product_canonical = 'seed/autoflowering/'.$brand->category_name.'/{product_alias}';
$productClass->save($product);
Note that it's not tested. I wrote this off the top of my head.

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 6
  • Hikashop Business
2 years 8 months ago #339820

Hi Nicolas!
Your script worked perfectly. I've just changed category->name with category->alias as it's an URL
And, looking at it I've managed to retrive the Brand Name in my customized product cards too.
Thanks a lot!

This is solved!


Think about future: maybe I'll have to translate the product for the english and french site.
I'm using Falang; is a mass action able to fill the falang fields too?
One last question about brands.
If you take a look at the attachment you'll see my product listing page for an X brand. It's empty, is that correct?
What is this page thinked for?

Thank you so much!
Davide

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 8 months ago #339821

Hi,

1. Well, nothing is impossible, but instead of a few lines of code I can write off the top of my head, you're looking at a few dozen lines of code to do it. So I guess you would need to hire a developer to work on that.

2. You're looking at a listing of products filtered by their links to categories.
If you select a brand on the explorer there, it's normal you don't get any products since you don't have any brand in the "categories" setting of your products (which you shouldn't).
Instead, you should leave the explorer on the main product category, and use the "brands" filter which will appear if you click on the "filter options" button on the top right corner in order to filter by brand.
HikaShop 4.5.0 actually removes the brands from the categories explorer there to avoid the confusion.

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 6
  • Hikashop Business
2 years 8 months ago #339863

Hi Nicolas.

Thank you for all your tips!
That's all, I guess.

Have a nice day.
Davide

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 6
  • Hikashop Business
2 years 7 months ago #340387

Hello Nicolas,
the client has decided to review the whole product's organization.
The new catories tree will be
- seeds
- > autoflowering
- - > Brand
- > regular
- - > Brand
So the previous code isn't the best solution, cause a brand can be present in both auto and regular seeds categries.

After a lot of tries and research on forum I've created this mass Action

$productClass = hikashop_get('class.product');
$product = new stdClass();
$product->product_id = {product_id};
$productCategories = $productClass->getCategories($product->product_id);

$categoryClass = hikashop_get('class.category');
$canonical ='/it';
foreach ($productCategories as $productCategory) {
        $productCategory = $categoryClass->get($productCategory);
        $canonical .= '/'.$productCategory->category_alias;
}

$product->product_canonical = $canonical.'/{product_alias}';
$productClass->save($product);

It works, so I paste it here for someone who maybe could have the same problem.
But as I'm not a developer maybe could be better written. Any suggestion?

Thanks.
Davide

Last edit: 2 years 7 months ago by nicolas.
The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 7 months ago #340389

Hi,

That code looks good. I've cleaned it a bit directly in your message but it's roughly the same. Thanks for sharing !

Last edit: 2 years 7 months ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 6
  • Hikashop Business
2 years 7 months ago #340605

A little side note.
You probably need to add this line before the foreach loop
$productCategories = array_reverse($productCategories);

This strange behaviour seems to happens only on some products; still investigating

UPDATE:
The order of the categories in the array seems to be random; or, probably, I'm missing something...

nad a little thing more:
I recive this error as I try to delete one category from the catgory list, using both Mass Action, or Action (Inside products list page)

Notice: Undefined property: stdClass::$categories in F:\siti\zoe-brand\plugins\hikashop\massaction_product\massaction_product.php on line 929

Warning: array_search() expects parameter 2 to be array, null given in F:\siti\zoe-brand\plugins\hikashop\massaction_product\massaction_product.php on line 929

Notice: Undefined variable: key in F:\siti\zoe-brand\plugins\hikashop\massaction_product\massaction_product.php on line 930

Last edit: 2 years 7 months ago by Jokingmind.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 7 months ago #340620

Hi,

The order of the categories returned by getCategories should be the order in which you have the categories in the "categories" setting of the product.

Regarding the warnings, I've added a patch to fix these. Download again the install package of HikaShop on our website and install it on yours to get the patch.

Please Log in or Create an account to join the conversation.

Time to create page: 0.088 seconds
Powered by Kunena Forum