Set a basket custom rebate & multiple rebates
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!
Set a basket custom rebate & multiple rebates
Hello,
1/
For a special offer, when some particular products are bought together following their given category, I would like to set a custom fixed calculated rebate on my current basket with a basket plugin.
I was hoping that something like :
could work ...
but If i'm not wrong, I realize that setRebate() method is related to a product price only.
And the basket rebate is the sum of the product rebates. Is that right?
So, i'm wondering what is the best way (do you think) to add a "global" fixed rebate to the current basket?
2/
In some case I would like to add a percentRebate on basket total, so the basket rebate will contain the sum of 2 reductions. What is the best way to manage multiple rebates together?
Thank you very much,
sbn
1/
For a special offer, when some particular products are bought together following their given category, I would like to set a custom fixed calculated rebate on my current basket with a basket plugin.
I was hoping that something like :
Code: Select all
<check if products are in the given categories == true >
$myspecialcalculatedrebate = 5.00;
$basket->getPrice()->setRebate($myspecialcalculatedrebate );
but If i'm not wrong, I realize that setRebate() method is related to a product price only.
And the basket rebate is the sum of the product rebates. Is that right?
So, i'm wondering what is the best way (do you think) to add a "global" fixed rebate to the current basket?
2/
In some case I would like to add a percentRebate on basket total, so the basket rebate will contain the sum of 2 reductions. What is the best way to manage multiple rebates together?
Thank you very much,
sbn
Re: Set a basket custom rebate & multiple rebates
You are right, the basket rebate value is automatically calculated by the product rebate values.sixbynine wrote: but If i'm not wrong, I realize that setRebate() method is related to a product price only.
And the basket rebate is the sum of the product rebates. Is that right?
So, i'm wondering what is the best way (do you think) to add a "global" fixed rebate to the current basket?
The best way is to add a rebate product which you can name, add an image and calculate a price for. It's also easy to remove that product from the basket if the rebate conditions doesn't apply any more, e.g. due to the customer deleted a product from the basket.
Easiest is to use two rebate products because of the things said before. Otherwise, you will run into edge cases that may be hard to fix.sixbynine wrote: In some case I would like to add a percentRebate on basket total, so the basket rebate will contain the sum of 2 reductions. What is the best way to manage multiple rebates together?
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: Set a basket custom rebate & multiple rebates
Thank you very much for your answer.
Just to be sure I correctly understand by a "rebate product", you mean a default product where I set a negative price?
Which code do I use to add a given product to the basket in my plugin?
Is there an example somewhere?
Thank you very much,
sbn
Just to be sure I correctly understand by a "rebate product", you mean a default product where I set a negative price?
Which code do I use to add a given product to the basket in my plugin?
Is there an example somewhere?
Thank you very much,
sbn
Re: Set a basket custom rebate & multiple rebates
Here is my code :
But I finally get this error : Type error: Argument 1 passed to Aimeos\MShop\Order\Item\Base\Base::addProduct() must implement interface Aimeos\MShop\Order\Item\Base\Product\Iface, instance of Aimeos\MShop\Product\Item\Standard given
EDIT : this problem was the same as explained here : help-f15/basket-controller-addproduct-d ... -t855.html
Code: Select all
$value = <mynewnegativevalue>;
$manager = \Aimeos\MShop\Factory::createManager( $context, 'product' );
$product = $manager->getItem($myid, array( 'product','price'));
$prices = $product->getRefitems( 'price', 'default', 'default' );
foreach($prices as $p){
$p->setValue($value);
}
$basket->addProduct($product);
EDIT : this problem was the same as explained here : help-f15/basket-controller-addproduct-d ... -t855.html
Re: Set a basket custom rebate & multiple rebates
I finally have 2 last questions :
1/
returns NULL instead of the expected product position in the basket when $myproductid is in the basket.
I don't understand why.
2/
I would like to finally override the price value of my product :
The var_dump gives me the expected result but when I check the basket in the frontend, myproductid is well there but the price is not the "$value" one. Not sure about the reason why...
Thank you very much in advance,
sbn
1/
Code: Select all
foreach ($basket->getProducts() as $basketItem) {
if($myproductid == $basketItem->getProductId()){
var_dump($basketItem->getPosition());
}
}
I don't understand why.
2/
I would like to finally override the price value of my product :
Code: Select all
$myvalue = <mynegativevalue>;
$tobasket->addProduct($myproductid, 1);
$basket = $controller->get();
foreach ($basket->getProducts() as $basketItem) {
if($basketItem->getProductId() == $myproductid){
$price = $basketItem->getPrice();
$price->setValue($value);
$basketItem->setPrice($price);
var_dump( $basketItem)
}
}
Thank you very much in advance,
sbn
Re: Set a basket custom rebate & multiple rebates
A "rebate product" is a simple article which is not associated to a category and is used to add a rebate value to the basket. It can have a negative price associated but more often the price is dynamically calculated and added to the order base product by your own code:
The position of the product in the basket is undefined until it's stored in the mshop_order_base_product table.
If you use the basket controller (which you should not in a basket plugin!), the basket needs to be saved to the session to persist the changes using $cntl->save()
Code: Select all
$product = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' )->findItem( '<your code>', ['text', 'media'] );
$orderProduct = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/product' )->createItem();
$orderProduct->copyFrom( $product )->getPrice()->setValue( -5 )->setRabate( 5 );
// basket is passed to the basket plugins as first parameter
$basket->addProduct( $orderProduct );
If you use the basket controller (which you should not in a basket plugin!), the basket needs to be saved to the session to persist the changes using $cntl->save()
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: Set a basket custom rebate & multiple rebates
Thank you !
It works perfectly.
It works perfectly.
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Set a basket custom rebate & multiple rebates
Sorry to hijack this thread, its been helpful but im having some issues relating to the same questions. I notice that when creating the rebate order product we now have to set the stock type, else the productStock throws an error.
Im wanting to add single article to adjust the price of the customers basket from my plugin based on condition(s) im defining. The problems I am now encountering is the user can modify the quantity of the rebate product in the basket, and I am unable to add unless I set a quantity on the order item.
Is this something I need to guard against? Am I still missing some things that have changed in 2020.10.*?
My code is as follows:
Once I get it added, I notice I get errors then reporting that "Product not available" which is an exception thrown from the \Aimeos\MShop\Order\Item\Base\Base class when calling getProduct.
Thanks
Im wanting to add single article to adjust the price of the customers basket from my plugin based on condition(s) im defining. The problems I am now encountering is the user can modify the quantity of the rebate product in the basket, and I am unable to add unless I set a quantity on the order item.
Is this something I need to guard against? Am I still missing some things that have changed in 2020.10.*?
My code is as follows:
Code: Select all
public function update(\Aimeos\MW\Observer\Publisher\Iface $order, string $action, $value = null)
{
...
$code = $this->getConfigValue('productcode');
$product = \Aimeos\MShop::create($this->getContext(), 'product')->findItem($code, ['text', 'media', 'price']);
$orderProduct = \Aimeos\MShop::create($this->getContext(), 'order/base/product')->create()->copyFrom($product);
$orderProduct->getPrice()->setValue(-5)->setRebate(5);
$orderProduct->setQuantity(1)->setStockType('default');
$order->addProduct( $orderProduct );
return $value;
}
Thanks
Re: Set a basket custom rebate & multiple rebates
To prevent customers to change the rebate product, set the immutable flag for the order product like done in the coupon providers:
https://github.com/aimeos/aimeos-core/b ... e.php#L238
https://github.com/aimeos/aimeos-core/b ... e.php#L238
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: 72
- Joined: 22 Mar 2021, 16:56
Re: Set a basket custom rebate & multiple rebates
Everyday is a school day, thanks again for this it works perfectly and does exactly what I want.