Create manual order
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!
-
- Posts: 40
- Joined: 12 Jul 2018, 19:57
Create manual order
Hi there;
Given a product code (SKU) how can I create a manual order with that ?
Thanks
Given a product code (SKU) how can I create a manual order with that ?
Thanks
--
Jorge A Ramirez
System Engineer
PHP Developer
Jorge A Ramirez
System Engineer
PHP Developer
Re: Create manual order
Use something like this:
You also have to add a billing address and a delivery and payment option to the basket. Use the "customer" and "service" controller for that. Then, you can use "$basketcntl->store()" to create an order. Using the "order" controller, you can create an order item with a payment status of "authorized" or "received" so your order gets processed normally in the further steps (send e-mails, push to ERP system, etc.)
For more information about the controllers, please have a look at the API docs:
https://aimeos.org/api/latest/namespace ... ntend.html
In 2019.x versions, the interfaces of the controllers changes a bit to simplify things.
Code: Select all
$prodcntl = \Aimeos\Controller\Frontend\Product\Factory::createController( $context );
$prodId = $prodcntl->findItem( '<sku>' )->getId();
$basketcntl = \Aimeos\Controller\Frontend\Basket\Factory::createController( $context );
$basketcntl->addProduct( $prodId );
For more information about the controllers, please have a look at the API docs:
https://aimeos.org/api/latest/namespace ... ntend.html
In 2019.x versions, the interfaces of the controllers changes a bit to simplify things.
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
-
- Posts: 40
- Joined: 12 Jul 2018, 19:57
Re: Create manual order
findItem doesn't exists, I used the manager instead of factory
1. I extended the coupon manager to add an sku,
2. That code will be redeemed.
3. As that code has associated a sku I need to create a complete order, set price in 0, and put it as authorized, and generate the billing.
Thks
When I sotre the basket with $basketcntl->store(), it creates a record in order_base, but it doesn't create records in order and order_base_products$prodcntl = \Aimeos\Controller\Frontend\Product\Factory::createController( $context );
$prodId = $prodcntl->findItem( '<sku>' )->getId();
What is my case:$basketcntl = \Aimeos\Controller\Frontend\Basket\Factory::createController( $context );
$basketcntl->addProduct( $prodId );
1. I extended the coupon manager to add an sku,
2. That code will be redeemed.
3. As that code has associated a sku I need to create a complete order, set price in 0, and put it as authorized, and generate the billing.
Thks
--
Jorge A Ramirez
System Engineer
PHP Developer
Jorge A Ramirez
System Engineer
PHP Developer
Re: Create manual order
If you are implementing something in the mshoplib, you must not use the controllers but the managers directly instead.
Then it will be something like this:
Then it will be something like this:
Code: Select all
$product = \Aimeos\MShop\Factory::createManager( $context, 'product' )->findItem( '<sku>', ['text', 'media', 'price'] );
$orderProduct = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem()->copyFrom( $product );
$orderProduct->getPrice()->setValue( '0.00' );
$baseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
$basket = $baseManager->createItem()->addProduct( $orderProduct );
// add address (if authenticated customer), delivery (e.g. 'Manual') and payment option (e.g. 'Postpay')
$basket = $baseManager->store( $basket );
$orderManager = \Aimeos\MShop\Factory::createManager( $context, 'order' );
$orderItem = $orderManager->createItem()->setBaseId( $basket->getId() )->setPaymentStatus( 5 )->setType( 'coupon' );
$orderManager->saveItem( $orderItem );
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
-
- Posts: 40
- Joined: 12 Jul 2018, 19:57
Re: Create manual order
Thanks, I have a good progress with that.
When I wnat to add a product to order/base with $baseManager->createItem()->addProduct( $orderProduct ); the product isn't added to order base neither order base product table, always the product should be a variant of a parent product,
I've tried pass the parent product id and the variant id, also pass the product id, but in those cases i can't get it in the order base information.
Thanks
When I wnat to add a product to order/base with $baseManager->createItem()->addProduct( $orderProduct ); the product isn't added to order base neither order base product table, always the product should be a variant of a parent product,
I've tried pass the parent product id and the variant id, also pass the product id, but in those cases i can't get it in the order base information.
Thanks
--
Jorge A Ramirez
System Engineer
PHP Developer
Jorge A Ramirez
System Engineer
PHP Developer
Re: Create manual order
Only after storing the order/base object (basket), the content is persisted in the database:jramirezgranada wrote: When I wnat to add a product to order/base with $baseManager->createItem()->addProduct( $orderProduct ); the product isn't added to order base neither order base product table, always the product should be a variant of a parent product,
Code: Select all
$baseManager->store( $basket );
For selection products, you might find it helpful to investigate how the basket frontend controller handles them:jramirezgranada wrote:I've tried pass the parent product id and the variant id, also pass the product id, but in those cases i can't get it in the order base information.
https://github.com/aimeos/ai-controller ... Select.php
Most important: The product ID in the order/base/product item is the ID of the selection product but the code is the SKU of the variant article.
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
-
- Posts: 7
- Joined: 03 Aug 2020, 13:30
Re: Create manual order
Hello,
One question, please.
How can I add multiple products in single order? At the end, I need sum of price and quantites for an order like:
And I want to use managers like you described before:
One question, please.
How can I add multiple products in single order? At the end, I need sum of price and quantites for an order like:
Code: Select all
$order = [
0 => [
"product_id" => "17"
"quantity" => "3"
]
1 => [
"product_id" => "27"
"quantity" => "4"
]
]
Code: Select all
$product = \Aimeos\MShop\Factory::createManager( $context, 'product' )->findItem( '<sku>', ['text', 'media', 'price'] );
$orderProduct = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' )->createItem()->copyFrom( $product );
$orderProduct->getPrice()->setValue( '0.00' );
$baseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
$basket = $baseManager->createItem()->addProduct( $orderProduct );
// add address (if authenticated customer), delivery (e.g. 'Manual') and payment option (e.g. 'Postpay')
$basket = $baseManager->store( $basket );
$orderManager = \Aimeos\MShop\Factory::createManager( $context, 'order' );
$orderItem = $orderManager->createItem()->setBaseId( $basket->getId() )->setPaymentStatus( 5 )->setType( 'coupon' );
$orderManager->saveItem( $orderItem );
Re: Create manual order
You can use:
Code: Select all
$prodcntl = \Aimeos\Controller\Frontend::create( $this->getContext(), 'product' );
$basketcntl = \Aimeos\Controller\Frontend::create( $this->getContext(), 'basket' );
foreach( ['17' => 3, '27' => 4] as $prodid => $qty )
{
$product = $prodcntl->get( $prodid, ['price', 'text', 'media'] );
$basketcntl->addProduct( $product, $qty );
}
$price = $basketcntl->get()->getPrice()->getValue();
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
-
- Posts: 7
- Joined: 03 Aug 2020, 13:30
Re: Create manual order
Hello,
Thanks for help.
I have one more queston about this.
We want to have simple shop like: products and orders.
So we don't have catalogs, categories, etc.
And now I have bug usning frontend controllers you sent me in code snippet:
Thanks in advance,
Milos Stankovic
Thanks for help.
I have one more queston about this.
We want to have simple shop like: products and orders.
So we don't have catalogs, categories, etc.
And now I have bug usning frontend controllers you sent me in code snippet:
Is there a way to skip those and add multiple products to one order ID?Aimeos\Controller\Frontend\Basket\Exception
Adding product with ID "17" is not allowed
Thanks in advance,
Milos Stankovic
-
- Posts: 7
- Joined: 03 Aug 2020, 13:30
Re: Create manual order
Hello,
Just to let you know, I ended up with something like this:
Just to let you know, I ended up with something like this:
Code: Select all
$context = app()->make('aimeos.context')->get();
$productManager = \Aimeos\MShop::create($context, 'product');
// ORDER BASE PRODUCT
$orderProduct = \Aimeos\MShop::create($context, 'order/base/product');
$orderedProducts = [];
foreach (['17' => 3, '27' => 4] as $prodid => $qty) {
$product = $productManager->getItem($prodid, ['text', 'media', 'price']);
$price = $product->getRefItems('price')->first();
$orderedProducts[] = $orderProduct
->createItem()
->setQuantity($qty)
->setPrice($price)
->copyFrom($product);
}
// ORDER BASE
$baseManager = \Aimeos\MShop::create($context, 'order/base');
$baseItem = $baseManager->createItem();
$basketProducts = $baseItem->setProducts($orderedProducts);
$basket = $baseManager->store($basketProducts);
// ORDER
$orderManager = \Aimeos\MShop::create($context, 'order');
$orderItem = $orderManager->createItem();
$orderItem->setBaseId($basket);
$orderManager->saveItem($orderItem);