controller/jobs/src/Controller/Jobs/Order/Email/Voucher/Standard.php
protected function createCoupons( \Aimeos\MShop\Order\Item\Base\Iface $orderBaseItem )
	{
		$map = [];
		$manager = \Aimeos\MShop::create( $this->getContext(), 'order/base/product/attribute' );

		foreach( $orderBaseItem->getProducts() as $pos => $orderProductItem )
		{
			if( $orderProductItem->getType() === 'voucher'
				&& $orderProductItem->getAttribute( 'coupon-code', 'coupon' ) === null
			) {
				$codes = [];

				for( $i = 0; $i < $orderProductItem->getQuantity(); $i++ )
				{
					$str = $i . getmypid() . microtime( true ) . $orderProductItem->getId();
					$code = substr( strtoupper( sha1( $str ) ), -8 );
					$map[$code] = $orderProductItem->getId();
					$codes[] = $code;
				}

				$item = $manager->createItem()->setCode( 'coupon-code' )->setType( 'coupon' )->setValue( $codes );
				$orderBaseItem->addProduct( $orderProductItem->setAttributeItem( $item ), $pos );
			}
		}

		$this->addCouponCodes( $map );
		return $orderBaseItem;
	}
protected function createCoupons( \Aimeos\MShop\Order\Item\Base\Iface $orderBaseItem )
	{
		$map = [];
		$manager = \Aimeos\MShop::create( $this->getContext(), 'order/base/product/attribute' );

		foreach( $orderBaseItem->getProducts() as $pos => $orderProductItem )
		{
			if( $orderProductItem->getType() === 'voucher'
				&& $orderProductItem->getAttribute( 'coupon-code', 'coupon' ) === null
			) {
				$codes = [];

				for( $i = 0; $i < $orderProductItem->getQuantity(); $i++ )
				{
					$str = $i . getmypid() . microtime( true ) . $orderProductItem->getId();
					$code = substr( strtoupper( sha1( $str ) ), -8 );
					$map[$code] = $orderProductItem->getId();
					$codes[] = $code;
				}

				$item = $manager->createItem()->setCode( 'coupon-code' )->setType( 'coupon' )->setValue( $codes );
				$orderBaseItem->addProduct( $orderProductItem->setAttributeItem( $item ), $pos );
			}
		}

		$this->addCouponCodes( $map );
		return $orderBaseItem;
	}
protected function createCoupons ( \ Aimeos \ MShop \ Order \ Item \ Base \ Iface $ orderBaseItem ) { $ map = [ ] ; $ manager = \ Aimeos \ MShop :: create ( $ this -> getContext ( ) , 'order/base/product/attribute' ) ; foreach ( $ orderBaseItem -> getProducts ( ) as $ pos => $ orderProductItem ) { if ( $ orderProductItem -> getType ( ) === 'voucher' && $ orderProductItem -> getAttribute ( 'coupon-code' , 'coupon' ) === null ) { $ codes = [ ] ; for ( $ i = 0 ; $ i < $ orderProductItem -> getQuantity ( ) ; $ i ++ ) { $ str = $ i . getmypid ( ) . microtime ( true ) . $ orderProductItem -> getId ( ) ; $ code = substr ( strtoupper ( sha1 ( $ str ) ) , - 8 ) ; $ map [ $ code ] = $ orderProductItem -> getId ( ) ; $ codes [ ] = $ code ; } $ item = $ manager -> createItem ( ) -> setCode ( 'coupon-code' ) -> setType ( 'coupon' ) -> setValue ( $ codes ) ; $ orderBaseItem -> addProduct ( $ orderProductItem -> setAttributeItem ( $ item ) , $ pos ) ; } } $ this -> addCouponCodes ( $ map ) ; return $ orderBaseItem ; }
Creates coupon codes for the bought vouchers

@param \Aimeos\MShop\Order\Item\Base\Iface $orderBaseItem Complete order including addresses, products, services
Creates coupon codes for the bought vouchers