List items explanation
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
List items explanation
Good morning, Aineos community.
I need little help with understanding of DB structure of lists.
I am trying to create short text and attach it to new created product.
it adds rows to the mshop_text and mshop_text_list tables. But texts are not shown in front-end. And the mshop_index_text table is empty.. But I did index rebuilding..
But when I add demo data with then the texts are shown, but mshop_text and mshop_text_list tables don't consists data regarding texts! Seems texts data only inside : mshop_index_text table.. So what is mshop_text_list for ? This table stores temporary data which will be deleted by aimeos after it creates data in mshop_index_text table ?
Please make it clear for me. Great thank you!
I noticed if I add:
It works!
Also I would like to ask how can I delete all prices for specific product ? I mean data from all related tables. Price, price_list, price_index ?
I need little help with understanding of DB structure of lists.
I am trying to create short text and attach it to new created product.
Code: Select all
$textItem = $textManager->createItem();
$textItem->setDomain('text');
$textItem->setType('short');
$textItem->setLanguageId('de');
$textItem->setContent($shortDescription);
$textItem->setLabel(substr($shortDescription, 0, 255));
$textItem->setStatus(1);
$textManager->saveItem($textItem);
$textListItem = $textListsManager->createItem();
$textListItem->setParentId($textItem->getId());
$textListItem->setDomain('text');
$textListItem->setType('default');
$textListItem->setStatus(1);
$textListItem->setRefId($product->getId());
$textListsManager->saveItem($textListItem);
$indexManager = \Aimeos\MShop\Index\Manager\Factory::create($context);
$indexManager->rebuildIndex();
$indexManager->optimize();
But when I add demo data with
Code: Select all
php artisan aimeos:setup --option=setup/default/demo:1
Please make it clear for me. Great thank you!
I noticed if I add:
Code: Select all
$product->addListItem( 'text', $textListItem, $textItem );
$this->productManager->saveItem($product);
Also I would like to ask how can I delete all prices for specific product ? I mean data from all related tables. Price, price_list, price_index ?
Re: List items explanation
If you want to add a text to a product, the text needs to be stored in the mshop_text table and the product<->text relation in the mshop_product_list table. The mshop_text_list table contains references to other domains like the customer groups that the text is available for, so:
Product with text:
mshop_product -> mshop_product_list -> mshop_text
Text with customer group:
mshop_text -> mshop_text_list -> mshop_customer_group
The best way to add a new text item to a product and reindex it is:
To delete prices or other references including the referenced items itself, you can use:
The last parameter ("true") for deleteListItems() removes the referenced items too.
Product with text:
mshop_product -> mshop_product_list -> mshop_text
Text with customer group:
mshop_text -> mshop_text_list -> mshop_customer_group
The best way to add a new text item to a product and reindex it is:
Code: Select all
$textItem = $textManager->createItem()->setType('short')->setLanguageId('de');
->setContent($shortDescription)->setLabel(substr($shortDescription, 0, 255));
$listItem = $productManager->createListsItem()->setType('default')->setRefId($product->getId());
$product->addListItem('text', $listItem, $textItem);
$product = $productManager->saveItem($product);
$indexManager = \Aimeos\MShop::create($context, 'index')->rebuild([$product->getId() => $product]);
Code: Select all
$product->deleteListItems($product->getListItems('price', null, null, false), true);
$product = $productManager->saveItem($product);
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: List items explanation
I am very thankful! Really good explanation. But, tell me, please, if I add several types of related data to products: texts, prices, etc. It is import process. So in such case may I do rebuildIndex only one time after complete process:
And not every time for each product as you said:
Code: Select all
$indexManager = \Aimeos\MShop\Index\Manager\Factory::create($context);
$indexManager->rebuildIndex();
$indexManager->optimize();
Code: Select all
$indexManager = \Aimeos\MShop::create($context, 'index')->rebuild([$product->getId() => $product]);
Re: List items explanation
Sure, that's more efficient if you import data from external systems.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: List items explanation
Thank you very much! And one more moment: I have some texts assigned to specific product, and when I do
- it doesn't retrieve the texts which have languageId = 'de'. Probably it gets only items with language equals to admin panel language.. But how can I get all entities, no considering the language ?
Code: Select all
$product->getListItems('text', null, null, false)
Re: List items explanation
In the admin interface, you should get all text items for a product with that line of code.
If you've set up your own context/locale item, make sure that language and currency is set to NULL.
If you've set up your own context/locale item, make sure that language and currency is set to NULL.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star