Add product to basket

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
marlonsamot
Posts: 9
Joined: 13 Apr 2021, 12:26

Add product to basket

Post by marlonsamot » 13 Apr 2021, 12:32

Hi devs, please help me with this. Please help how to add product in basket in controller. Newbie here thanks!

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

Re: Add product to basket

Post by aimeos » 15 Apr 2021, 06:41

The controllers are available here:
https://github.com/aimeos/ai-controller ... r/Frontend

For the basket controller, have a look at the interface for the available methods:
https://github.com/aimeos/ai-controller ... /Iface.php

To add a product to the basket, use:

Code: Select all

$product = \Aimeos\Controller\Frontend::create( $context, 'product' )->find( 'myprodcode', ['text', 'price', 'media', 'attribute'] );
\Aimeos\Controller\Frontend::create( $context, 'basket' )->addProduct( $product, );
How you get the context object depends on your host application. For Laravel, please read:
https://aimeos.org/docs/latest/laravel/ ... end-aimeos
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
marlonsamot
Posts: 9
Joined: 13 Apr 2021, 12:26

Re: Add product to basket

Post by marlonsamot » 19 Apr 2021, 12:32

What would be the value of context ? i'm just using function from controller. Other programmer just pass me a product id that would be a key to add a basket.

For example, $product_id = 15

What would be the right code to add to basket.

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

Re: Add product to basket

Post by aimeos » 20 Apr 2021, 10:44

For IDs, use get() instead of find().
How to get the context depends on your host application. What do you use? Laravel?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
marlonsamot
Posts: 9
Joined: 13 Apr 2021, 12:26

Re: Add product to basket

Post by marlonsamot » 20 Apr 2021, 11:43

Yes laravel. I want to add to basket using parameter product id

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

Re: Add product to basket

Post by aimeos » 24 Apr 2021, 08:42

Please read this article how to get the context object:
https://aimeos.org/docs/latest/laravel/ ... os-objects
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply