Price data not copied from Product to OrderProduct

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!
columbo
Advanced
Posts: 158
Joined: 09 Oct 2019, 09:42

Price data not copied from Product to OrderProduct

Post by columbo » 21 Oct 2025, 20:19

Hi,

I need to add products to the order/basket item.
Products including medias are added as expected, but the price domain is missing.

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'order/basket' );
$filter = $manager->filter()
    ->add( 'order.basket.customerid', '==', $context->user() )
    ->add( 'order.basket.id', '==', $basketid );

$basket = $manager->search( $filter )->first();	

if($item = $basket->getItem())
{
    $product = \Aimeos\MShop::create($context, 'product')->get(	$prodid, ['text', 'media', 'price']);
    $orderProduct = \Aimeos\MShop::create($context, 'order/product')->create()->copyFrom($product);			

    $item->addProduct($orderProduct);			
    $manager->save($basket->setItem( $item ));

    Log::info(print_r($orderProduct, true));
}
'price' is added as data domain to the $product, but missing (not copied) in the $orderProduct


log output:

Code: Select all

production.INFO: Aimeos\MShop\Order\Item\Product\Standard Object
(
    [available:protected] => 1
    [modified:protected] => 1
    [bprefix:protected] => order.product.
    [type:protected] => 
    [bdata:protected] => Array
        (
            [.price] => Aimeos\MShop\Price\Item\Standard Object
                (
                    [available:protected] => 1
                    [modified:protected] => 1
                    [bprefix:protected] => price.
                    [type:protected] => 
                    [bdata:protected] => Array
                        (
                            [.currencyid] => EUR
                            [price.taxflag] => 1
                            [price.precision] => 2
                            [price.currencyid] => EUR
                            [price.siteid] => 1.
                        )

                    [precision:Aimeos\MShop\Price\Item\Standard:private] => 2
                    [tax:Aimeos\MShop\Price\Item\Standard:private] => 0
                    [listItems:Aimeos\MShop\Price\Item\Standard:private] => Array
                        (
                        )

                    [listRmItems:Aimeos\MShop\Price\Item\Standard:private] => Array
                        (
                        )

                    [listMap:Aimeos\MShop\Price\Item\Standard:private] => Array
                        (
                        )

                    [listMax:Aimeos\MShop\Price\Item\Standard:private] => 0
                    [propItems:Aimeos\MShop\Price\Item\Standard:private] => Array
                        (
                        )

                    [propRmItems:Aimeos\MShop\Price\Item\Standard:private] => Array
                        (
                        )

                    [propMax:Aimeos\MShop\Price\Item\Standard:private] => 0
                )

            [order.product.siteid] => 1.
            [order.product.prodcode] => 4567
            [order.product.productid] => 123
            [order.product.type] => default
            [order.product.scale] => 1
            [order.product.target] => 
            [order.product.name] => My Product
            [order.product.mediaurl] => prodimg/My_Product.jpeg
        )

    [attributesMap:Aimeos\MShop\Order\Item\Product\Base:private] => 
    [attrRmItems:Aimeos\MShop\Order\Item\Product\Base:private] => Array
        (
        )

)
thank you!

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

Re: Price data not copied from Product to OrderProduct

Post by aimeos » 22 Oct 2025, 08:10

Price calculation is more complex then just copying the first available price:
- https://github.com/aimeos/ai-controller ... #L347-L359
- https://github.com/aimeos/ai-controller ... se.php#L31
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply