/** * Create coupon related to sales rule . * * @param int $ruleId * @return void * @throws \Exception */ protected function createCoupon($ruleId) { if (!$this->fixture->hasData('coupon_code')) { return; } $url = $_ENV['app_frontend_url'] . 'rest/V1/coupons'; $data = ['coupon' => array_filter(['rule_id' => $ruleId, 'code' => $this->fixture->getCouponCode(), 'type' => $this->mappingData['coupon_type'][$this->fixture->getCouponType()], 'usage_limit' => isset($this->data['uses_per_coupon']) ? $this->data['uses_per_coupon'] : null, 'usage_per_customer' => isset($this->data['usage_per_customer']) ? $this->data['usage_per_customer'] : null, 'is_primary' => true])]; $this->webapiTransport->write($url, $data); $response = json_decode($this->webapiTransport->read(), true); $this->webapiTransport->close(); if (empty($response['coupon_id'])) { $this->eventManager->dispatchEvent(['webapi_failed'], [$response]); throw new \Exception('Coupon creation by webapi handler was not successful!'); } }
/** * Preparation of "Rule Information" tab. * * @return void */ protected function prepareRuleInformation() { $this->data = array_diff_key($this->data, array_flip($this->couponFields)); $this->data['coupon_type'] = strtoupper(str_replace(' ', '_', $this->fixture->getCouponType())); }