Basket plugin, add rebate product -> out of stock?
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!
Basket plugin, add rebate product -> out of stock?
Hi.
I'm building a basket plugin that will give a rebate based on how many of certain products is bought.
Example, buy 10 of prod A and pay for 8, each product costs 30.
In this case the total rebate would be 30*2 = 60
So I've got the logic to match the conditions and calculate the rebate amount. It triggers just fine on changes in the basket so that part works.
Then I understood that the principle would be to add a rebate product to the basket with
I've created a rebate product with unlimited stock, no category, no price which I will give the rebate to.
Then I've found old posts here, that I should do like this to add the rebate-product to the basket:
But I'm seeing "products out of stock" on the $order->addProduct( $rebateProduct );
I've dumped the product I created and want to add to the basket and they hold the values I would expect.
What am I missing here?
Thanx/Dan
I'm building a basket plugin that will give a rebate based on how many of certain products is bought.
Example, buy 10 of prod A and pay for 8, each product costs 30.
In this case the total rebate would be 30*2 = 60
So I've got the logic to match the conditions and calculate the rebate amount. It triggers just fine on changes in the basket so that part works.
Then I understood that the principle would be to add a rebate product to the basket with
I've created a rebate product with unlimited stock, no category, no price which I will give the rebate to.
Then I've found old posts here, that I should do like this to add the rebate-product to the basket:
Code: Select all
//$product is the rebate product created earlier.
$rebateProduct = \Aimeos\MShop::create( $this->getContext(), 'order/base/product' )->create();
$rebateProduct->copyFrom( $product )->getPrice()->setValue( '-'.$discount )->setRebate( $discount );
$order->addProduct( $rebateProduct );
I've dumped the product I created and want to add to the basket and they hold the values I would expect.
Code: Select all
[2022-02-24 15:48:57] local.DEBUG: array (
'order.base.product.id' => NULL,
'order.base.product.price' => '-60.00',
'order.base.product.costs' => '0.00',
'order.base.product.rebate' => '60.00',
'order.base.product.taxrate' => '0.00',
'order.base.product.taxrates' =>
array (
),
'order.base.product.type' => 'default',
'order.base.product.stocktype' => '',
'order.base.product.prodcode' => 'bulk-discount',
'order.base.product.productid' => '300',
'order.base.product.supplierid' => '',
'order.base.product.suppliername' => '',
'order.base.product.qtyopen' => 1.0,
'order.base.product.quantity' => 1.0,
'order.base.product.currencyid' => 'SEK',
'order.base.product.taxvalue' => '0.0000',
'order.base.product.taxflag' => true,
'order.base.product.name' => 'Mängdrabatt',
'order.base.product.description' => '',
'order.base.product.mediaurl' => '',
'order.base.product.timeframe' => '',
'order.base.product.position' => NULL,
'order.base.product.notes' => '',
'order.base.product.statuspayment' => NULL,
'order.base.product.statusdelivery' => 1,
'order.base.product.status' => -1,
)
Thanx/Dan
_____________
Laravel 8 with Aimeos 2021.10.7 + Marketplace. Setup via composer. Mac with Valet and MySql 8.0.25
Laravel 8 with Aimeos 2021.10.7 + Marketplace. Setup via composer. Mac with Valet and MySql 8.0.25
Re: Basket plugin, add rebate product -> out of stock?
The item in $product you fetch from the database needs to have a stock item associated (can be unlimited too).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

Re: Basket plugin, add rebate product -> out of stock?
As can be seen in the attached screens, the rebate product I created has unlimited stock.
I don't know why I'm not seeing anything stockrelated though when I do $product->toArray()
This is how I retrieve the product, create a new one for the basket, give it values:
Code: Select all
$prodCodes = array($this->getConfigValue('xfory2.rebatecode'));
$productManager = \Aimeos\MShop::create( $this->getContext(), 'product' );
$search = $productManager->filter( true )->slice( 0, count( $prodCodes ) );
$search->setConditions( $search->and( [
$search->compare( '==', 'product.code', $prodCodes ),
$search->getConditions(),
] ) );
$result = $productManager->search( $search, ['price', 'attribute' => ['custom']] )->col( null, 'product.code' );
$product = $productManager->get($result->first());
$rebateProduct = \Aimeos\MShop::create( $this->getContext(), 'order/base/product' )->create();
$rebateProduct->copyFrom( $product )->getPrice()->setValue( '-'.$discount )->setRebate( $discount );
$rebateProduct->setStatus('1');
$order->addProduct( $rebateProduct );
Code: Select all
[2022-02-28 11:23:22] local.DEBUG: array (
'product.id' => '808',
'product.url' => 'mangd-rabatt',
'product.type' => 'default',
'product.code' => 'mangd-rabatt',
'product.label' => 'Mängdrabatt',
'product.status' => 1,
'product.dataset' => '',
'product.datestart' => NULL,
'product.dateend' => NULL,
'product.config' =>
array (
),
'product.scale' => 1.0,
'product.target' => '',
'product.ctime' => '2021-08-12 09:22:00',
'product.rating' => '0.00',
'product.ratings' => 0,
)
Code: Select all
[2022-02-28 12:29:45] local.DEBUG: rebateProd:
[2022-02-28 12:29:45] local.DEBUG: array (
'order.base.product.id' => NULL,
'order.base.product.price' => '-60.00',
'order.base.product.costs' => '0.00',
'order.base.product.rebate' => '60.00',
'order.base.product.taxrate' => '0.00',
'order.base.product.taxrates' =>
array (
),
'order.base.product.type' => 'default',
'order.base.product.stocktype' => '',
'order.base.product.prodcode' => 'mangd-rabatt',
'order.base.product.productid' => '808',
'order.base.product.supplierid' => '',
'order.base.product.suppliername' => '',
'order.base.product.qtyopen' => 1.0,
'order.base.product.quantity' => 1.0,
'order.base.product.name' => 'Mängdrabatt',
'order.base.product.description' => '',
'order.base.product.mediaurl' => '',
'order.base.product.timeframe' => '',
'order.base.product.position' => NULL,
'order.base.product.status' => 1,
'order.base.product.notes' => '',
)
/Dan
- Attachments
-
- Screenshot 2022-02-28 at 11.57.46.png (218.62 KiB) Viewed 4398 times
-
- Screenshot 2022-02-28 at 11.58.11.png (214.3 KiB) Viewed 4398 times
_____________
Laravel 8 with Aimeos 2021.10.7 + Marketplace. Setup via composer. Mac with Valet and MySql 8.0.25
Laravel 8 with Aimeos 2021.10.7 + Marketplace. Setup via composer. Mac with Valet and MySql 8.0.25
Re: Basket plugin, add rebate product -> out of stock?
Most likely because you don't set the stock type in the order base product item.
Use the "createRebateProducts()" from the Base coupon provider class so you don't have to care about the details:
https://github.com/aimeos/aimeos-core/b ... te.php#L96
Use the "createRebateProducts()" from the Base coupon provider class so you don't have to care about the details:
https://github.com/aimeos/aimeos-core/b ... te.php#L96
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

Re: Basket plugin, add rebate product -> out of stock?
Thank you, been searching for examples, did not find this oneaimeos wrote: ↑01 Mar 2022, 14:31 Use the "createRebateProducts()" from the Base coupon provider class so you don't have to care about the details:
https://github.com/aimeos/aimeos-core/b ... te.php#L96

Will try this.
_____________
Laravel 8 with Aimeos 2021.10.7 + Marketplace. Setup via composer. Mac with Valet and MySql 8.0.25
Laravel 8 with Aimeos 2021.10.7 + Marketplace. Setup via composer. Mac with Valet and MySql 8.0.25
Re: Basket plugin, add rebate product -> out of stock?
That did indeed work a lot better, now I'm going to dig around on how to remove rebate prod from the basket when needed.
Thank you.
/Dan
Thank you.
/Dan
_____________
Laravel 8 with Aimeos 2021.10.7 + Marketplace. Setup via composer. Mac with Valet and MySql 8.0.25
Laravel 8 with Aimeos 2021.10.7 + Marketplace. Setup via composer. Mac with Valet and MySql 8.0.25