Injecting coupon by url parameters
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!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 41
- Joined: 03 Jun 2023, 17:30
Injecting coupon by url parameters
Hello,
Laravel Framework 10.13.1, php8.1-fpm, aimeos/aimeos-laravel 2023.04.2
When I setup ad campaigns, im thinking I would create different URL's for advertised discounts, ex:
:
New Fishing Reels! - Free Shipping
https://mysite/shop/new-reels?code=free ... rer=google
10% Off All Plastic Fishing Lures!
https://mysite/shop/plastic-lures?code= ... r=facebook
The discounts would only be available if you came in from the given URL and then the coupon persisted in a cookie for X number of days.
What would be the best approach to accomplish this (if even done by URL parameters?)? If by URL parameters, where would be the best place to intercept/evaluate the request and start processing it to add a coupon?
Laravel Framework 10.13.1, php8.1-fpm, aimeos/aimeos-laravel 2023.04.2
When I setup ad campaigns, im thinking I would create different URL's for advertised discounts, ex:
:
New Fishing Reels! - Free Shipping
https://mysite/shop/new-reels?code=free ... rer=google
10% Off All Plastic Fishing Lures!
https://mysite/shop/plastic-lures?code= ... r=facebook
The discounts would only be available if you came in from the given URL and then the coupon persisted in a cookie for X number of days.
What would be the best approach to accomplish this (if even done by URL parameters?)? If by URL parameters, where would be the best place to intercept/evaluate the request and start processing it to add a coupon?
Re: Injecting coupon by url parameters
It may be possible to add a coupon code from a link but only in the basket view using the b_coupon parameter:
https://aimeos.org/docs/latest/frontend ... es/#basket
If you want to show another page, you have to create a Laravel controller which intercepts the request first, adds the coupon to the basket and than redirects to the target page.
https://aimeos.org/docs/latest/frontend ... es/#basket
If you want to show another page, you have to create a Laravel controller which intercepts the request first, adds the coupon to the basket and than redirects to the target page.
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: 41
- Joined: 03 Jun 2023, 17:30
Re: Injecting coupon by url parameters
Hello,
Could you expand on adding a coupon into the cart from my own controller?
I been looking at example code and documentation, but I'm not fully understanding..
Currently I am only as far as doing the following:
Then I assume from $orderManager I can somehow access a basket object and use the addCoupon() method? But I am having a hard time bridging the gap.
Could you expand on adding a coupon into the cart from my own controller?
I been looking at example code and documentation, but I'm not fully understanding..
Currently I am only as far as doing the following:
Code: Select all
class CampaignController extends Controller
{
public function handleOffer(Request $request, $key)
{
$context = app('aimeos.context')->get(true);
$orderManager = \Aimeos\MShop::create( $context, 'order' );
-
- Posts: 41
- Joined: 03 Jun 2023, 17:30
Re: Injecting coupon by url parameters
Hello,
I may, or may not, have got a little further, my code now:
Im thinking this would add the default 10% percentage coupon that comes with Aimeos.
I then redirect to the desired product, but I dont see any discounts applied. From what I read, it sounds like I am suppose to use these methods to add a coupon to an item in an order? Do I actually need to add the product to the users basket and then apply the coupon? Or can I have the coupon applied only if they end up adding the item to the basket..
Thanks
I may, or may not, have got a little further, my code now:
Code: Select all
class CampaignController extends Controller
{
public function handleOffer(Request $request, $key)
{
$context = app('aimeos.context')->get(true);
$orderManager = \Aimeos\MShop::create( $context, 'order' );
$basket = $orderManager->getSession();
$test = $basket->addCoupon('percent');
return redirect()->route('aimeos_shop_detail', [$key,'0']);
I then redirect to the desired product, but I dont see any discounts applied. From what I read, it sounds like I am suppose to use these methods to add a coupon to an item in an order? Do I actually need to add the product to the users basket and then apply the coupon? Or can I have the coupon applied only if they end up adding the item to the basket..
Thanks
Re: Injecting coupon by url parameters
Use the addCoupon() method of the basket controller instead:
https://github.com/aimeos/ai-controller ... e.php#L118
For Laravel, there's a facade available:
This only adds the coupon code to the basket and it doesn't reduce the price of the product until it's added to the basket.
https://github.com/aimeos/ai-controller ... e.php#L118
For Laravel, there's a facade available:
Code: Select all
\Aimeos\Shop\Facades\Basket::addCoupon('percent');
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: 41
- Joined: 03 Jun 2023, 17:30
Re: Injecting coupon by url parameters
Hello,
When I try to use '\Aimeos\Shop\Facades\Basket::addCoupon('percent')' in my controller I get:
'Illegal offset type in isset or empty'
Do I need to somehow instantiate an instance of a basket? or an instance of Aimeos? I don't understand how this controller knows anything about Aimeos in order to interact with the basket.
My controller is only this:
Should I be extending from a different Aimeos-specific controller?
Any help is greatly appreciated.
When I try to use '\Aimeos\Shop\Facades\Basket::addCoupon('percent')' in my controller I get:
'Illegal offset type in isset or empty'
Do I need to somehow instantiate an instance of a basket? or an instance of Aimeos? I don't understand how this controller knows anything about Aimeos in order to interact with the basket.
My controller is only this:
Code: Select all
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class CampaignController extends Controller
{
public function handleOffer(Request $request, $key)
{
$test = \Aimeos\Shop\Facades\Basket::addCoupon('percent');
die();
return redirect()->route('aimeos_shop_detail', [$key,'0']);
}
}
Any help is greatly appreciated.
Re: Injecting coupon by url parameters
Do you have a stack trace of the error?
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: 41
- Joined: 03 Jun 2023, 17:30
Re: Injecting coupon by url parameters
Seem like the Aimeos facades needs some love ...
Use this instead:
Use this instead:
Code: Select all
\Aimeos\Controller\Frontend::create( $context, 'basket' )->addCoupon('percent');
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