Unable to store new product

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!
User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Unable to store new product

Post by ahmed31916 » 05 May 2022, 12:54

Hello,

I'm trying to create a new product like this:

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'product' );
$item = $manager->create([
    'product.code' => $code, 
    'product.type' => 'default',
    'product.label' => $request->label, 
    'product.status' => 1,
    'price' => [[
        'price.label' => 'Demo: Article from 1',
        'price.value' => $request->price, 
        'price.costs' => '0.00', 
        'price.rebate' => '0.00', 
        'price.taxrate' => $request->tax,
        'price.quantity' => 1, 
        'price.type' => 'default', 
        'price.currencyid' => 'USD', 
        'price.status' => 1,
        'product.lists.type' => 'default', 
        'product.lists.position' => 0
        ]],
]);

$item = $manager->save($item, true);
No error appear. But, it was not stored in the database.

this is the result

Code: Select all

^ Aimeos\MShop\Product\Item\Standard {#339 ▼
  -date: "2022-05-05 12:20:00"
  -available: true
  -modified: false
  -prefix: "product."
  #bdata: array:7 [▼
    "product.code" => 476145
    "product.type" => "default"
    "product.label" => "Enim ea quos omnis i"
    "product.status" => 1
    "price" => array:1 [▶]
    "product.siteid" => "1."
    ".date" => "2022-05-05 12:20:00"
  ]
  -listItems: []
  -listRefItems: []
  -listRmItems: []
  -listPrepared: true
  -listRmMap: []
  -listMap: []
  -listMax: 0
  -propItems: []
  -propRmItems: []
  -propMax: 0
}

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

Re: Unable to store new product

Post by aimeos » 09 May 2022, 13:32

If you hand over the properties to create(), the item is not marked as modified and therefore not stored. Use fromArray() instead if you want to import/update products.

Adding prices that way doesn't work, you have to use addListItem() instead:
https://aimeos.org/docs/latest/models/m ... ated-items
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply