Custom order creation
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- ZaurHuseynzade
- Posts: 3
- Joined: 17 May 2024, 11:24
Custom order creation
Good afternoon.
To begin with, I would like to thank you for your work.
I took Aimeos as the basis for my project. And I ran into a problem at one point. The fact is that I plan to sell not only physical but also digital goods. Their sale is carried out through a third-party service and does not go through adding to the cart and placing an order in the usual sense. But I need the order to get into the database and be visible in the admin panel like everyone else. I'm trying to call the add to cart and checkout methods directly in the controller. But I get errors. Could you look at my code and help? Thank you in advance.
$serviceId = $request->input('service_id');
$productCode = $request->input('product_code');
$productManager = MShop::create($context, 'product');
$productItem = $productManager->find($productCode);
if ($productItem === null) {
return response()->json(['error' => 'Product not found'], 404);
}
if (!$productItem->getStatus()) {
return response()->json(['error' => 'Product is not available for purchase'], 400);
}
$categoryItems = $productItem->getRefItems('catalog');
if (empty($categoryItems)) {
return response()->json(['error' => 'Product does not belong to any category'], 400);
}
$basketController = Frontend::create($context, 'basket');
$basket = $basketController->addProduct($productItem, 1, [], []);
$orderBase = $basket->getOrderBase();
$orderManager = MShop::create($context, 'order');
$orderItem = $orderManager->create();
$orderItem->setBase($orderBase);
$orderItem->setLocale($basket->getLocale());
$orderManager->save($orderItem);
dd($orderItem);
To begin with, I would like to thank you for your work.
I took Aimeos as the basis for my project. And I ran into a problem at one point. The fact is that I plan to sell not only physical but also digital goods. Their sale is carried out through a third-party service and does not go through adding to the cart and placing an order in the usual sense. But I need the order to get into the database and be visible in the admin panel like everyone else. I'm trying to call the add to cart and checkout methods directly in the controller. But I get errors. Could you look at my code and help? Thank you in advance.
$serviceId = $request->input('service_id');
$productCode = $request->input('product_code');
$productManager = MShop::create($context, 'product');
$productItem = $productManager->find($productCode);
if ($productItem === null) {
return response()->json(['error' => 'Product not found'], 404);
}
if (!$productItem->getStatus()) {
return response()->json(['error' => 'Product is not available for purchase'], 400);
}
$categoryItems = $productItem->getRefItems('catalog');
if (empty($categoryItems)) {
return response()->json(['error' => 'Product does not belong to any category'], 400);
}
$basketController = Frontend::create($context, 'basket');
$basket = $basketController->addProduct($productItem, 1, [], []);
$orderBase = $basket->getOrderBase();
$orderManager = MShop::create($context, 'order');
$orderItem = $orderManager->create();
$orderItem->setBase($orderBase);
$orderItem->setLocale($basket->getLocale());
$orderManager->save($orderItem);
dd($orderItem);
Re: Custom order creation
Which Aimeos version do you use?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- ZaurHuseynzade
- Posts: 3
- Joined: 17 May 2024, 11:24
Re: Custom order creation
I'm using 2023 version
- ZaurHuseynzade
- Posts: 3
- Joined: 17 May 2024, 11:24
Re: Custom order creation
$basketController = Frontend::create($context, 'basket');
$basketController->clear();
$basket = $basketController->addProduct($productItem, 1, [], []);
$addressManager = MShop::create($context, 'customer/address');
$addressItem = $addressManager->create();
$basket->addAddress('payment', [$addressItem]);
$serviceManager = MShop::create($context, 'service');
$serviceItem = $serviceManager->get(6, ['option', 'media', 'text', 'price']);
$basket->addService($serviceItem);
$basketController->store($basket);
$orderManager = MShop::create($context, 'order');
$orderItem = $orderManager->create();
$orderItem->setDatePayment(now());
$orderItem->setStatusPayment(1);
$orderItem->setStatusDelivery(1);
$orderItem->setInvoiceNumber('1234567890');
$orderManager->save($orderItem);
dump(get_class_methods($orderItem));
dump(get_class_methods($orderManager));
dd($orderItem);
I made references in the code. But again I encounter one serious mistake. With my code I get 2 entries into the database instead of one. One is empty, but connected with the rest of the information. And the second one is full. I need to understand what I'm doing wrong, Since I want to get the information into one entry.
$basketController->clear();
$basket = $basketController->addProduct($productItem, 1, [], []);
$addressManager = MShop::create($context, 'customer/address');
$addressItem = $addressManager->create();
$basket->addAddress('payment', [$addressItem]);
$serviceManager = MShop::create($context, 'service');
$serviceItem = $serviceManager->get(6, ['option', 'media', 'text', 'price']);
$basket->addService($serviceItem);
$basketController->store($basket);
$orderManager = MShop::create($context, 'order');
$orderItem = $orderManager->create();
$orderItem->setDatePayment(now());
$orderItem->setStatusPayment(1);
$orderItem->setStatusDelivery(1);
$orderItem->setInvoiceNumber('1234567890');
$orderManager->save($orderItem);
dump(get_class_methods($orderItem));
dump(get_class_methods($orderManager));
dd($orderItem);
I made references in the code. But again I encounter one serious mistake. With my code I get 2 entries into the database instead of one. One is empty, but connected with the rest of the information. And the second one is full. I need to understand what I'm doing wrong, Since I want to get the information into one entry.
Re: Custom order creation
Only use the order manager and its sub-managers to create the order and not the frontend controllers.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star