1010use Commercetools \Core \Fixtures \TeamCityFormatter ;
1111use Commercetools \Core \Model \Cart \Cart ;
1212use Commercetools \Core \Model \Cart \CartDraft ;
13+ use Commercetools \Core \Model \CartDiscount \AbsoluteCartDiscountValue ;
1314use Commercetools \Core \Model \CartDiscount \CartDiscount ;
1415use Commercetools \Core \Model \CartDiscount \CartDiscountDraft ;
1516use Commercetools \Core \Model \CartDiscount \CartDiscountReferenceCollection ;
1617use Commercetools \Core \Model \CartDiscount \CartDiscountTarget ;
1718use Commercetools \Core \Model \CartDiscount \CartDiscountValue ;
19+ use Commercetools \Core \Model \CartDiscount \GiftLineItemCartDiscountValue ;
1820use Commercetools \Core \Model \Category \Category ;
1921use Commercetools \Core \Model \Category \CategoryDraft ;
2022use Commercetools \Core \Model \Channel \Channel ;
@@ -734,7 +736,7 @@ protected function getCartDiscount()
734736 if (is_null ($ this ->cartDiscount )) {
735737 $ draft = CartDiscountDraft::ofNameValuePredicateTargetOrderActiveAndDiscountCode (
736738 LocalizedString::ofLangAndText ('en ' , 'test- ' . $ this ->getTestRun () . '-discount ' ),
737- CartDiscountValue ::of ()-> setType ( ' absolute ' )->setMoney (
739+ AbsoluteCartDiscountValue ::of ()->setMoney (
738740 MoneyCollection::of ()->add (Money::ofCurrencyAndAmount ('EUR ' , 100 ))
739741 ),
740742 '1=1 ' ,
@@ -751,6 +753,32 @@ protected function getCartDiscount()
751753 return $ this ->cartDiscount ;
752754 }
753755
756+ protected function getGiftLineItemCartDiscount ()
757+ {
758+ if (is_null ($ this ->cartDiscount )) {
759+ $ product = $ this ->getProduct ();
760+ $ draft = CartDiscountDraft::ofNameValuePredicateOrderActiveAndDiscountCode (
761+ LocalizedString::ofLangAndText (
762+ 'en ' ,
763+ 'test- ' . $ this ->getTestRun () . '-gift-line-item-discount '
764+ ),
765+ GiftLineItemCartDiscountValue::of ()
766+ ->setProduct ($ product ->getReference ())
767+ ->setVariantId ($ product ->getMasterData ()->getCurrent ()->getMasterVariant ()->getId ()),
768+ '1=1 ' ,
769+ '0.9 ' . trim ((string )mt_rand (1 , 1000 ), '0 ' ),
770+ true ,
771+ false
772+ );
773+ $ request = CartDiscountCreateRequest::ofDraft ($ draft );
774+ $ response = $ request ->executeWithClient ($ this ->getClient ());
775+
776+ $ this ->cartDiscount = $ request ->mapResponse ($ response );
777+ }
778+
779+ return $ this ->cartDiscount ;
780+ }
781+
754782 private function deleteCartDiscount ()
755783 {
756784 if (!is_null ($ this ->cartDiscount )) {
0 commit comments