Adds the coupon codes to the database.

@param string $couponId
@param array $data
517280
protected function _addCodes( $couponId, array $data )
	{
		$manager = MShop_Factory::createManager( $this->_getContext(), 'coupon/code' );

		foreach( $data as $entry )
		{
			$item = $manager->createItem();
			$item->setCouponId( $couponId );
			$item->setCode( $entry['code'] );
			$item->setCount( $entry['count'] );
			$item->setDateStart( $entry['datestart'] );
			$item->setDateEnd( $entry['dateend'] );

			$manager->saveItem( $item );
		}
	}
58177
public function createAndSaveCartCoupon(
        CartInterface $cart,
        CouponInterface $coupon
    ) {
        /**
         * We create a new instance of CartCoupon.
         * We also persist and flush relation.
         */
        $cartCoupon = $this
            ->cartCouponDirector
            ->create();

        $cartCoupon->setCart($cart);
        $cartCoupon->setCoupon($coupon);

        $this
            ->cartCouponDirector
            ->save($cartCoupon);

        return $cartCoupon;
    }
980422
private function addCommonPropertiesFromArray(array $data)
    {
        $k                 = array_keys($data);
        $k                 = $k[0];
        $this->_result[$k] = [];
        foreach ($data[$k] as $c) {
            $id = $c['_id'];
            unset($c['_id']);
            $this->_result[$k][$id] = $c;
        }
    }
1184008
public function show($productFamilyId, $couponId)
    {
        $service = $this->getService();

        $response      = $service->request('product_families/' . $productFamilyId . '/coupons/' . $couponId, 'GET');
        $responseArray = $this->getResponseArray($response);

        if (!$this->isError()) {
            $this->_data = $responseArray['coupon'];
        } else {
            $this->_data = array();
        }

        return $this;
    }
242751
private function addCouponToOrder($coupons, $new_order)
    {
        $errors = new \Illuminate\Support\MessageBag;
        
        if (count($coupons) > 0) {
            foreach ($coupons as $item) {
                $model = Coupon::find($item);
                if ($model != null) {
                    try {
                        $new_order->addCoupon($model);
                    } catch (Exception $exp) {
                        $errors->add(
                            'couponError',
                            "Coupon " . $model->code . " cannot be added because: " . $exp->getMessage()
                        );
                        
                    }
                }
            }
            
            // Set coupon discount
            $new_order->setDiscounts();
        }
        
        return $errors;
    }
330476
public function validateCoupon(
        CartInterface $cart,
        CouponInterface $coupon
    ) {
        if ($cart->getTotalItemNumber() === 0) {
            throw new CouponIncompatibleException();
        }

        $this
            ->couponManager
            ->checkCoupon($coupon);
    }
392216
protected function _beforeEntityInsert(AnCommandContext $context)
    {
        if (!empty($this->couponCode)) {
            $coupon = $this->getService('repos:subscriptions.coupon')
                           ->find(array(
                             'code' => $this->couponCode,
                           ));

            if ($coupon) {
                $coupon->used();
            }
        }
    }
322229
private function addDocumentsFromArray(array $data)
    {
        $_documentClass = $this->_documentClass;

        $this->_result[] = $_documentClass::createFromArray($data, $this->_options);
    }
375203
public static function createFromData(array $data)
    {
        if (!isset($data['type'])) {
            throw new DomainException(self::MSG_REQUIRED_TYPE);
        }

        switch ($data['type']) {
            case self::TYPE_FIXED:
                $discount = new Discounts\Fixed($data);

                break;
            case self::TYPE_PERCENT:
                $discount = new Discounts\Percent($data);

                break;
            default:
                throw new DomainException(
                    sprintf(self::MSG_UNSUPPORTED_TYPE, implode(',', self::$supportedTypes))
                );
        }

        return $discount;
    }
352136
def add(self, quote_id, coupon_code, store_view=None):
        
        return bool(
            self.call('cart_coupon.add', [quote_id, coupon_code, store_view])
        )
936664
public function generateCoupon($priceRuleId, $expireDate)
    {
        $rule   = $this->getPriceRule($priceRuleId);
        $coupon = $rule->acquireCoupon();
        $coupon = $this->setUpCoupon($expireDate, $coupon, $rule);
        $this->couponResourceInterface->save($coupon);

        return $coupon->getCode();
    }
170673
def add_coupon(self, coupon, idempotency_key=None):
		
		if isinstance(coupon, StripeModel):
			coupon = coupon.id

		stripe_customer = self.api_retrieve()
		stripe_customer["coupon"] = coupon
		stripe_customer.save(idempotency_key=idempotency_key)
		return self.__class__.sync_from_stripe_data(stripe_customer)
1185402
public function getBackOfficeConditionSummariesAjaxAction($couponId)
    {
        if (null !== $response = $this->checkAuth(AdminResources::COUPON, [], AccessManager::VIEW)) {
            return $response;
        }

        $this->checkXmlHttpRequest();

        /** @var Coupon $coupon */
        $coupon = CouponQuery::create()->findPk($couponId);
        if (null === $coupon) {
            return $this->pageNotFound();
        }

        /** @var CouponFactory $couponFactory */
        $couponFactory = $this->container->get('thelia.coupon.factory');
        $couponManager = $couponFactory->buildCouponFromModel($coupon);

        if (!$couponManager instanceof CouponInterface) {
            return $this->pageNotFound();
        }

        $args = [];
        $args['conditions'] = $this->cleanConditionForTemplate($couponManager->getConditions());

        return $this->render('coupon/conditions', $args);
    }
199522
private function setExpiryDate($couponModel, $expireDate, $rule)
    {
        $newExpiryDate = $expireDate;
        if ($rule->getToDate() && ! $expireDate) {
            $newExpiryDate = $rule->getToDate();
        }

        $couponModel->setExpirationDate($newExpiryDate);

        return $couponModel;
    }
347516
public function dispatchOrderCouponOnApplyEvent(
        OrderInterface $cart,
        CouponInterface $coupon
    ) {
        $event = new OrderCouponOnApplyEvent(
            $cart,
            $coupon
        );

        $this->eventDispatcher->dispatch(
            ElcodiCartCouponEvents::ORDER_COUPON_ONAPPLY,
            $event
        );
    }
884407
public static function createFromData(array $data)
    {
        if (!isset($data['formula'])) {
            throw new DomainException(self::REQUIRED_FORMULA);
        }

        switch ($data['formula']) {
            case self::FLAT_RATE:
                return new Pricing\FlatRate($data);
            case self::FIXED_FEE:
                return new Pricing\FixedFee($data);
            case self::STAIRSTEP:
                return new Pricing\Stairstep($data);
            case self::TIERED:
                return new Pricing\Tiered($data);
            case self::VOLUME:
                return new Pricing\Volume($data);
            default:
                throw new DomainException(sprintf(self::UNSUPPORTED_FORMULA, implode(',', self::getAvailableFormulas())));
        }
    }
1074148
public function add($key, $data)
    {
        $toInsert = $this->getDocumentData($data);

        $result = $this->collection->insertOne($toInsert);

        $data->_id = $result->getInsertedId();
    }