aimeos / aimeos-core

Aimeos PHP e-commerce framework for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
https://aimeos.org
Other
3.4k stars 118 forks source link

Order/Base/Service iface doesn't works #254

Closed msofiullahs closed 2 years ago

msofiullahs commented 3 years ago

Hi, I've tried to use aimeos for laravel API, and then I need to use order flow by following aimeos order data flow. But, I found that order/base/service iface doesn't works well. When i try use any function in that iface, nothing can works like order/base/product did. https://github.com/aimeos/aimeos-core/blob/ae22729af4d99038825de4a2dd8d02db0a1942d4/lib/mshoplib/src/MShop/Order/Item/Base/Service/Iface.php#L21

This is my code for adding product into order

$orderProduct = MShop::create($context, 'order/base/product');
$productManager = MShop::create($context, 'product');
$product = $productManager->get($item['product_id'], ['attribute', 'text', 'media', 'price']);
$getprice = $product->getRefItems('price')->first();
$baseProduct = $orderProduct->create(['additional'=>json_encode($additional)])
    ->copyFrom($product)
    ->setProducts($attributes)
    ->setQuantity($item['qty'])
    ->setStockType('default')
    ->setPrice($getPrice);

$basketProduct = $baseItem->addProduct($baseProduct);
$baseManager->store($basketProduct);

and then this is for adding service into order

$servManager = MShop::create($context, 'service');
$servItem = $servManager->find('max-100', ['price']);
$servPrice = $servItem->getRefItems('price')->first();

$service = MShop::create($context, 'order/base/service');
$saveServ = $service->create($servItem->toArray())->setPrice($servPrice);

$basketService = $baseItem->addService($saveServ, $servItem->getType());
$baseManager->store($basketService);
aimeos commented 3 years ago

What's the problem besides that you should use:

$saveServ = $service->create()->copyFrom($servItem)->setPrice($servPrice);
msofiullahs commented 3 years ago

I try to use some sets function, it gives me error for example I try to use setBaseId("1") and then it gives me error unknown ->setBaseid("1")

aimeos commented 3 years ago

setBaseId() is called automatically if you call store() so there's no need for. Your example code doesn't contain any call to setBaseId() so we have no clue what you are doing and why it doesn't work. Please be more precise in what's the problem.

nvindice commented 3 years ago

@msofiullahs Maybe the typo in your call ->setBaseid("1") is the problem here?