How to create voucher via programmatically?

Help for integrating the Laravel package
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!
Bhautik
Posts: 1
Joined: 16 Sep 2021, 04:58

How to create voucher via programmatically?

Post by Bhautik » 16 Sep 2021, 05:35

I want to create a voucher programmatically and redeeming this voucher to give access/discount to users.
How to write the code in Aimeos and please explain directory structure and coding structure to how can I write my code.
The Aimeos document is very very difficult to understand. I would like to suggest you please upgrade the document for custom features and development like the Laravel document.
Also, I noticed in the Aimeos document, there is some mistake in syntax in the given example. Please upgrade the document to easy to understand and easy to implement.
Attachments
Syntax error in given example in Aimeos official site.
Syntax error in given example in Aimeos official site.
error.png (64.03 KiB) Viewed 617 times

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

Re: How to create voucher via programmatically?

Post by aimeos » 17 Sep 2021, 05:00

Thans for the hint, the code in the documentation has been fixed now.

Do you have more concrete suggestions how to improve the documentation? You can also create a pull request with suggested changes for the docs here: https://github.com/aimeos/aimeos-docs

To create vouchers programatically, use the coupon manager:

Code: Select all

$context = app( 'aimeos.context' )->get();
$manager = \Aimeos\MShop::create( $context, 'coupon' );
$item = $manager->create()
	->setLabel( 'test' )->setProvider( 'FixedRebate' )
	->setConfig( [
		'fixedrebate.productcode' => 'demo-rebate',
		'fixedrebate.rebate' => ['EUR' => 10.0]
	] );
$item = $manager->save( $item );

$codeManager = \Aimeos\MShop::create( $context, 'coupon/code' );
$codeItem = $codeManager->create()
	->setParentId( $item->getId() )
	->setCode( 'ABDC' )
	->setCount( 100 );
$codeManager->save( $codeItem );
You can find the details here:
- https://aimeos.org/docs/latest/laravel/ ... os-objects
- https://aimeos.org/docs/latest/models/managing-items/
- https://github.com/aimeos/aimeos-core/t ... hop/Coupon
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply