How i can add text item to product
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
How i can add text item to product
I am working to build cron job to add text item type meta-description to each product do not have meta-description.
firstly i tried to add text item like this:
When i print $item variable the text.id is null like this.
For this reason i can not refer text item to product.
But if the text item exist in table 'mshop_text' no problem to refer it to product by 'text.id'.
PHP Version 8.2.12
Laravel version: 10
Aimeos version: 2023.10
Environment: windows (XAMPP cross-platform web server).
firstly i tried to add text item like this:
Code: Select all
$context = app('aimeos.context')->get();
$managerText = \Aimeos\MShop::create( $context, 'text' );
$textData = [
"text.languageid" => null,
"text.type" => "meta-description",
"text.label" => "text-item-meta",
"text.domain" => "product",
"text.content" => "add new text item job meta-description",
"text.status" => 1,
];
$item = $managerText->create($textData);
$item = $managerText->save( $item);
dd($item);
Code: Select all
Aimeos\MShop\Text\Item\Standard^ {#845
#available: true
#modified: false
#bprefix: "text."
#type: null
#bdata: array:9 [
"text.id" => null
"text.languageid" => null
"text.type" => "meta-description"
"text.label" => "text-item-meta"
"text.domain" => "product"
"text.content" => "add new text item job meta-description"
"text.status" => 1
"text.siteid" => "1."
".languageid" => "ar"
]
-langid: "ar"
-listPrepared: true
-listItems: []
-listRefItems: []
-listRmItems: []
-listRmMap: []
-listMap: []
-listMax: 0
} // app\Console\Commands\AddMetaDataProducts.php:43
But if the text item exist in table 'mshop_text' no problem to refer it to product by 'text.id'.
PHP Version 8.2.12
Laravel version: 10
Aimeos version: 2023.10
Environment: windows (XAMPP cross-platform web server).
Re: How i can add text item to product
My problem is solved
I found my error.
When i used this code, inserted the text item data is stored correctly.
I found my error.
When i used this code, inserted the text item data is stored correctly.
Code: Select all
$managerText = \Aimeos\MShop::create( $context, 'text' );
$textItem = $managerText->create();
$textItem->setDomain('product');
$textItem->setLabel('text-item-meta');
$textItem->setStatus(1);
$textItem->setContent('add new text item job meta-description');
$textItem->setType('meta-description');
$textItem = $managerText->save($textItem, true);
Re: How i can add text item to product
You can also use fromArray() as a one liner. When passing data to create(), the modified flag won't be set and items not saved by save()
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
![Image](https://aimeos.org/fileadmin/aimeos.org/icons/star.png)