Help for integrating the Laravel package
Forum rules: Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#5273 by Kevin
20 Dec 2017, 10:18
Hi all,

I'm using Aimeos for single products and subscriptions. So far, everything is working pretty fine. The last step to finalize the platform is to receive a webhook from Stripe when the subscription auto-renews.

When a subscription renews, I would like to add an order in the same way a normal order is placed via the backend. In other words, I want the order to appear in the order history of the client, I want the order to appear in my list of order to handle etc...

Someone has experience with this? Or someone can advise me on the best way to set this up?
I can directly input the database, but that would not be so clean. So I assume there are better options to build this.

Thanks for advising me on this one.

Regards,
Kevin
#5281 by aimeos
20 Dec 2017, 22:07
You only have to create an additional record in the mshop_order table, best using the order manager:
Code: Select all$manager = \Aimeos\MShop\Factory::createManager( $context, 'order' );
$invoice = $manager->createItem();
$invoice->setBaseId( '<ID of mshop_order_base table with the related order>' );
$invoice->setType( \Aimeos\MShop\Order\Item\Base::TYPE_REPEAT );
$invoice->setDatePayment( date( 'Y-m-d H:i:s' ) );
$invoice->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED );
$manager->saveItem( $invoice );

You only need the Aimeos context for this.
#5297 by Kevin
22 Dec 2017, 16:11
Thank you for the feedback. Looking at your code I assume you attach an order to an already existing base item. That could work for me. But how do I use the code you provide into a standard Laravel controller?

I defined context like:
Code: Select all$context = app( '\Aimeos\Shop\Base\Context' )->get( false );


But I receive following error "Locale object not available"...

Can you guide me on this please?

K.
#5298 by Travin
24 Dec 2017, 18:11
Hi Kevin!
Could you tell me how do you use Stripe subscriptions? Are you use ai-payments for this? Will you create a new order type at db and at Aimeos for subscriptions?
#5300 by aimeos
25 Dec 2017, 13:42
Kevin wrote:I defined context like:
Code: Select all$context = app( '\Aimeos\Shop\Base\Context' )->get( false );

But I receive following error "Locale object not available"...


If you use false for the get() method, no locale object is added. Using no parameter will add the locale object:
https://aimeos.org/docs/Laravel/Extend_Aimeos
#5692 by Kevin
15 Feb 2018, 14:43
Hi!

Everything is working fine, except the mailing is send in English... Not in the language defined in the base item. How can I use the language that was defined in the base?

Code: Select all$context = app( '\Aimeos\Shop\Base\Context' )->get(  );
      
      $manager = \Aimeos\MShop\Factory::createManager( $context, 'order' );
      $invoice = $manager->createItem();
      $invoice->setBaseId(101);
      $invoice->setType( \Aimeos\MShop\Order\Item\Base::TYPE_REPEAT );
      $invoice->setDatePayment( date( 'Y-m-d H:i:s' ) );
      $invoice->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED );
      $invoice->setDeliveryStatus(\Aimeos\MShop\Order\Item\Base::STAT_PROGRESS);
      $manager->saveItem( $invoice );
#5693 by aimeos
15 Feb 2018, 21:08
In the released versions, the language ID of the address is used for the e-mail language. In the dev-master branch a fall-back to the language of the order is now implemented