Interacting with the Basket

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!
jafo66
Posts: 75
Joined: 06 Mar 2024, 04:42

Interacting with the Basket

Post by jafo66 » 14 Jul 2024, 16:50

Based on how we built our custom frontend, we are looking to process a number of rows sent from the client and then add / update / delete each one in the basket.

I have been able to create an empty basket and then add a product BUT it doesn't save from call to call which tells me that I've missed a critical step. The controller method should be returning a JSON object with the updated basket.

We are using 2024.04.1 and Php 8.3

Code: Select all

        $context = app('aimeos.context')->get(true);
        $controller = new \Aimeos\Controller\Frontend\Basket\Standard($context);
        $include = ['basket/address', 'basket/coupon', 'basket/product'];

        $basket = $controller->get()->setCustomerId($context->user());
        Log::debug('created basket: ' . json_encode($basket));

        $product = MShop::create($context, 'product')->get('7', ['text', 'media', 'price']);

        $orderProduct = MShop::create($context, 'order/product')->create();
        $orderProduct->copyFrom($product);
        $basket->addProduct($orderProduct, 0);

        return response(json_encode($basket));
I also don't see the basket getting created in the mshop_order_basket table.

My overall goal is to do the following from within a controller:
  1. Get the basket from the user's session and create one if it doesn't exist
  2. add / update / remove products based on what is passed into the controller
  3. "save" the basket so it is ready for check out
Can you point out what I need to do differently?

Thanks!

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

Re: Interacting with the Basket

Post by aimeos » 15 Jul 2024, 21:17

Call the save() method to store the updated basket:
https://github.com/aimeos/ai-controller ... hp#L45-L50
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

jafo66
Posts: 75
Joined: 06 Mar 2024, 04:42

Re: Interacting with the Basket

Post by jafo66 » 15 Jul 2024, 23:40

Thanks! Do you have any example code of adding attributes (custom or otherwise) to the product in the basket?


Post Reply