List items explanation

Help for integrating the Laravel package
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!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

List items explanation

Post by MikaelNazarenko » 12 Sep 2019, 05:14

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.

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();

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

Code: Select all

php artisan aimeos:setup --option=setup/default/demo:1
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:

Code: Select all

$product->addListItem( 'text', $textListItem, $textItem );
$this->productManager->saveItem($product);
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 ?

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: List items explanation

Post by aimeos » 12 Sep 2019, 07:31

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:

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]);
To delete prices or other references including the referenced items itself, you can use:

Code: Select all

$product->deleteListItems($product->getListItems('price', null, null, false), true);
$product = $productManager->saveItem($product);
The last parameter ("true") for deleteListItems() removes the referenced items too.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: List items explanation

Post by MikaelNazarenko » 12 Sep 2019, 08:15

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:

Code: Select all

        $indexManager = \Aimeos\MShop\Index\Manager\Factory::create($context);
        $indexManager->rebuildIndex();
        $indexManager->optimize();
And not every time for each product as you said:

Code: Select all

$indexManager = \Aimeos\MShop::create($context, 'index')->rebuild([$product->getId() => $product]);

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: List items explanation

Post by aimeos » 12 Sep 2019, 08:18

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, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: List items explanation

Post by MikaelNazarenko » 12 Sep 2019, 10:04

Thank you very much! And one more moment: I have some texts assigned to specific product, and when I do

Code: Select all

$product->getListItems('text', null, null, false)
- 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 ?

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: List items explanation

Post by aimeos » 13 Sep 2019, 09:06

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.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply