[Solved] Wishlistlisting a product through ajax call
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: 02 Dec 2021, 17:18
[Solved] Wishlistlisting a product through ajax call
How can I use an ajax call to add a product to wishlist ?
again I need to show them under a profile section
Kindly let me know how to add it via ajax and fetch on page load ?
TIA
again I need to show them under a profile section
Kindly let me know how to add it via ajax and fetch on page load ?
TIA
Last edited by kartikbhat on 24 Apr 2023, 02:47, edited 1 time in total.
Re: Wishlistlisting a product through ajax call
Use the customer relations resource from the JSON API:
https://aimeos.org/docs/latest/frontend ... relations/
https://aimeos.org/docs/latest/frontend ... relations/
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: 02 Dec 2021, 17:18
Re: Wishlistlisting a product through ajax call
How can I insert Favorite product from laravel controller ?
tried following approach
response returning 302 status code
help me to find correct approach
TIA
tried following approach
Code: Select all
$favoriteData = [
'token' => csrf_token(),
'fav_action'=>$favorite['fav_action'],
'fav_id'=>$favorite['fav_id'],
'd_name'=>$favorite['d_name'],
'd_prodid'=>$favorite['d_prodid']
];
$request = Request::create($postUrl, 'POST',$favoriteData);
$request->headers->set('X-CSRF-TOKEN', csrf_token());
$request->headers->set('Content-Type', 'application/json');
$response = Route::dispatch($request);
response returning 302 status code
help me to find correct approach
TIA
Re: Wishlistlisting a product through ajax call
Don't use a network request if you can use the PHP API instead!
In a Laravel controller use:
In a Laravel controller use:
Code: Select all
$context = app('aimeos.context')->get();
$manager = \Aimeos\MShop::create( $context, 'customer' );
// if you know that the customer doesn't have that item as favorite yet:
$item = $manager->get( '<customer ID>' );
$item->addListItem( 'product', $manager->createListItem()->setType( 'favorite' )->setRefId( '<product ID>' ) );
// else if you need to check if the product is already a favorite of the customer:
$item = $manager->get( '<customer ID>', ['product' => ['favorite']] );
if( $item->getListItem( 'product', 'favorite', '<product ID>', false ) === null ) {
$item->addListItem( 'product', $manager->createListItem()->setType( 'favorite' )->setRefId( '<product ID>' ) );
}
$manager->save( $item );
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: 02 Dec 2021, 17:18
Re: Wishlistlisting a product through ajax call
Thank you for this solution