Add custom "Option" to Coupon - how to retrieve in checkout?

Questions around the TYPO3 integration and plugins
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
cyrotek
Posts: 58
Joined: 27 Jun 2019, 16:43

Re: Add custom "Option" to Coupon - how to retrieve in checkout?

Post by cyrotek » 01 Aug 2019, 07:19

Thats the whole point of that option, we use moodle as elearning tool and there is a rest api we use to pass the course on so if i use the options, i'll just add another course with the api.

So, how would i get the options?

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

Re: Add custom "Option" to Coupon - how to retrieve in checkout?

Post by aimeos » 01 Aug 2019, 09:13

You can get the config with:
$couponItem->getConfig()
// or
$couponItem->getConfigValue( 'key' )
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

cyrotek
Posts: 58
Joined: 27 Jun 2019, 16:43

Re: Add custom "Option" to Coupon - how to retrieve in checkout?

Post by cyrotek » 01 Aug 2019, 13:06

In which context is that supposed to work?

I retrieve the Coupon with

Code: Select all

$coupons = $this->summaryBasket->getCoupons();
and loop through them with foreach, your code throws an exception?

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

Re: Add custom "Option" to Coupon - how to retrieve in checkout?

Post by aimeos » 02 Aug 2019, 07:47

Only for the coupon item, the order coupon item doesn't have that methods.

You have to get the coupon item for the code first:

Code: Select all

$manager = \Aimeos\MShop::create( $this->getContext(), 'coupon' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'coupon.coupon.code', array_keys( $coupons ) ) );
$couponItems = $manager->searchItems( $search );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

cyrotek
Posts: 58
Joined: 27 Jun 2019, 16:43

Re: Add custom "Option" to Coupon - how to retrieve in checkout?

Post by cyrotek » 12 Sep 2019, 10:34

Throws an exception:

Class "\Aimeos\MW\View\Helper\GetContext\Standard" not available

I mean, it seriously cant be that hard to access that option....

cyrotek
Posts: 58
Joined: 27 Jun 2019, 16:43

Re: Add custom "Option" to Coupon - how to retrieve in checkout?

Post by cyrotek » 12 Sep 2019, 11:36

Okay, so I've added a decorator. Everything fine, just how do i access the coupon code? Whatever i try to retrieve with $view->get throws an error or null....

Decorator is included as:
plugin.tx_aimeos.settings.client.html.checkout.confirm.decorators.global{
0 = CouponCourse
}

Code is

Code: Select all

public function addData( \Aimeos\MW\View\Iface $view, array &$tags = array(), &$expire = null )
    {
        $view = parent::addData( $view, $tags, $expire );
         // access already added data
        $products = $view->get( 'listsItems', [] );
 		var_dump($products);
        // fetch some items from the database
        $view->couponCourseCodes = '';
 
        return $view;
    }

cyrotek
Posts: 58
Joined: 27 Jun 2019, 16:43

Re: Add custom "Option" to Coupon - how to retrieve in checkout?

Post by cyrotek » 12 Sep 2019, 12:07

Alright.... fixed that too now. Another error popped up...

Code: Select all

2019-09-12 12:00:37	client/html	4	df61f077a8341b8da5fd7778fa060c3b	Invalid name "coupon.coupon.code
Here is my Decorator right now...

Code: Select all

public function addData( \Aimeos\MW\View\Iface $view, array &$tags = array(), &$expire = null )
    {
        $view = parent::addData( $view, $tags, $expire );
         // access already added data
        $coupons = $view->summaryBasket->getCoupons();
 		
		$manager = \Aimeos\MShop::create( $this->getContext(), 'coupon' );
		
		$search = $manager->createSearch();
		
		$search->setConditions( $search->compare( '==', 'coupon.coupon.code', array_keys( $coupons ) ) );
		$couponItems = $manager->searchItems( $search );
		
		
        // fetch some items from the database
        $view->couponCourseCodes = '';
 
        return $view;
    }
EDIT: Okay, seemingly its not coupon.coupon.code but coupon.code.code, after some digging into the core, i found that and it seems to work.

Post Reply