How i can add text item to product

How to configure and adapt Aimeos based shops as developer
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!
malik_kat
Posts: 11
Joined: 09 Jan 2024, 09:20

How i can add text item to product

Post by malik_kat » 01 May 2024, 11:36

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:

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);
When i print $item variable the text.id is null like this.

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
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).

malik_kat
Posts: 11
Joined: 09 Jan 2024, 09:20

Re: How i can add text item to product

Post by malik_kat » 02 May 2024, 11:49

My problem is solved
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);	

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

Re: How i can add text item to product

Post by aimeos » 02 May 2024, 19:00

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

Post Reply