new "save basket as template" feature
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!
new "save basket as template" feature
Hi,
I'm looking for a "save basket as template" feature.
I know that baskets can already be saved at checkout, but I need more functionality:
Extend the favorites feature? Or any other suggestions?
Thank you!
I'm looking for a "save basket as template" feature.
I know that baskets can already be saved at checkout, but I need more functionality:
- manage multiple basket templates
- edit saved baskets (remove or add product to template list)
- on catalog- and product detail page: "add product to basket-template"-button, with a "template list" selector
Extend the favorites feature? Or any other suggestions?
Thank you!
Re: new "save basket as template" feature
With the current "save basket" feature, you can save multiple baskets as templates and add the products to the current basket (later) again. It's currently not possible to edit saved baskets, only to apply them to the current (empty) basket, save them again and delete the old basket. Editing baskets feature can be add based on the current implementation I guess.
The "add to template" feature definitively needs some more customization but I would try to use a different basket type for the templates to avoid merging with the current basket.
The "add to template" feature definitively needs some more customization but I would try to use a different basket type for the templates to avoid merging with the current basket.
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
Re: new "save basket as template" feature
Hi,
I am trying to create a new, empty 'order/basket' with a custom name ($baskettemplateName).
It creates a new basket, but also fills it with products from my current frontend basket.
Because of: ->setItem( \Aimeos\Controller\Frontend::create( $context, 'basket' )->get()
Tried with empty ->setItem() and also without ->setItem but its not working.
How can I create a new, empty 'order/basket' ?
Thank you!
I am trying to create a new, empty 'order/basket' with a custom name ($baskettemplateName).
It creates a new basket, but also fills it with products from my current frontend basket.
Because of: ->setItem( \Aimeos\Controller\Frontend::create( $context, 'basket' )->get()
Code: Select all
$manager = \Aimeos\MShop::create( $context, 'order/basket' );
$item = $manager->create()->setId( md5( microtime( true ) . getmypid() . rand() ) )
->setCustomerId( $userId )->setName( $baskettemplateName )
->setItem( \Aimeos\Controller\Frontend::create( $context, 'basket' )->get() );
$manager->save( $item );
How can I create a new, empty 'order/basket' ?
Thank you!
Re: new "save basket as template" feature
Create an empty basket/order using:
Code: Select all
\Aimeos\MShop::create( $context, 'order' )->create()
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
Re: new "save basket as template" feature
unfortunately i'm still struggeling:
to create a new basket template:
add a product to a template:
get all basket templates and their products
I did not receive any errors, but the product is not added to the basket template
thank you
to create a new basket template:
Code: Select all
$manager = \Aimeos\MShop::create( $context, 'order/basket' );
$item = $manager->create()->setId( md5( microtime( true ) . getmypid() . rand() ) )
->setCustomerId( $userId )
->setName( $view->param( 'templatename') )
->setItem( \Aimeos\MShop::create( $context, 'order' )->create() );
$manager->save( $item );
add a product to a template:
Code: Select all
//first get basket
$manager = \Aimeos\MShop::create( $context, 'order/basket' );
$filter = $manager->filter()
->add( 'order.basket.customerid', '==', $context->user() )
->add( 'order.basket.id', '==', $basketid );
$basketCntl = $manager->search( $filter )->getItem() ;
//add Product to basket
$product = \Aimeos\MShop::create($context, 'product')->get( $prodid, ['text', 'media', 'price']);
$orderProduct = \Aimeos\MShop::create($context, 'order/product')->create();
$orderProduct->copyFrom($product);
$basketCntl->addProduct($orderProduct, 1);
Code: Select all
$manager = \Aimeos\MShop::create( $context, 'order/basket' );
$filter = $manager->filter()->order( '-order.basket.mtime' )
->add( 'order.basket.customerid', '==', $context->user() )
->add( 'order.basket.name', '!=', '' );
$view->basketItems = $manager->search( $filter );
thank you
Re: new "save basket as template" feature
Without saving the basket after you've added the product, no changes will persist in the database.
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
Re: new "save basket as template" feature
but how?
tried with manager->save(), but causes
Aimeos\MShop\Order\Manager\Basket\Standard::saveItem(): Argument #1 ($item) must be of type Aimeos\MShop\Order\Item\Basket\Iface, Aimeos\MShop\Order\Item\Standard given...
and causes:
Aimeos\MShop\Order\Manager\Basket\Standard::saveItem(): Argument #1 ($item) must be of type Aimeos\MShop\Order\Item\Basket\Iface, Aimeos\MShop\Order\Item\Product\Standard given
I can't use the frontend controller (\Aimeos\Controller\Frontend::create( $context, 'basket' )) as the product should not be added to the (frontend) basket, only added to the template-basket
tried with manager->save(), but
Code: Select all
$manager->save( $basketCntl );
Aimeos\MShop\Order\Manager\Basket\Standard::saveItem(): Argument #1 ($item) must be of type Aimeos\MShop\Order\Item\Basket\Iface, Aimeos\MShop\Order\Item\Standard given...
and
Code: Select all
$manager->save( $orderProduct );
Aimeos\MShop\Order\Manager\Basket\Standard::saveItem(): Argument #1 ($item) must be of type Aimeos\MShop\Order\Item\Basket\Iface, Aimeos\MShop\Order\Item\Product\Standard given
I can't use the frontend controller (\Aimeos\Controller\Frontend::create( $context, 'basket' )) as the product should not be added to the (frontend) basket, only added to the template-basket
Re: new "save basket as template" feature
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())
{
//add Product to basket
$product = \Aimeos\MShop::create($context, 'product')->get( $prodid, ['text', 'media', 'price']);
$orderProduct = \Aimeos\MShop::create($context, 'order/product')->create()->copyFrom($product);
$item->addProduct($orderProduct, 1);
// save basket again
$manager->save($basket);
}
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
Re: new "save basket as template" feature
Unfortunately it doesn't work - the orderProduct is not saved to the basket.
Then loading order/basket again, right after $manager->save($basket) the product is missing
output:
Then loading order/basket again, right after $manager->save($basket) the product is missing
Code: Select all
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, 1);
$manager->save($basket);
Log::info("item 1:" . print_r(json_encode($item), true));
}
//test output
$manager2 = \Aimeos\MShop::create( $context, 'order/basket' );
$filter2 = $manager2->filter()
->add( 'order.basket.customerid', '==', $context->user() )
->add( 'order.basket.id', '==', $basketid );
$basket2 = $manager2->search( $filter2 )->first();
if($item2 = $basket2->getItem())
{
Log::info("item 2:" . print_r(json_encode($item2), true));
}
Code: Select all
item 1:{"order.siteid":"1.","coupons":[],"products":{"1":{"order.product.siteid":"1.","cgroups":0,"order.product.prodcode":"25025","order.product.productid":"101794","order.product.type":"default","order.product.scale":1,"order.product.target":"","order.product.name":"Product ABC","order.product.mediaurl":"..."}},"services":[],"addresses":[],"price":{...},"locale":{...},"customer":null}
item 2:{"order.siteid":"1.","coupons":[],"products":[],"services":[],"addresses":[],"price":{...},"locale":{...},"customer":null}
Re: new "save basket as template" feature
This is a working example from an unit test for Aimeos 2024.x:
Code: Select all
$product = \Aimeos\MShop::create( $context, 'product' )->find( 'CNE' );
$orderProduct = \Aimeos\MShop::create( $context, 'order/product' )->create()->copyFrom( $product );
$order = \Aimeos\MShop::create( $context, 'order' )->create()->addProduct( $orderProduct );
$manager = \Aimeos\MShop::create( $context, 'order/basket' );
$basket = $manager->save( $manager->create()->setItem( $order )->setId( 'test-1' ) );
$basket2 = $manager->get( $basket->getId() );
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