getId(); $definition['id'] = $shipping_method_id . '--' . $service_id; } $this->id = $definition['id']; $this->shippingMethodId = $definition['shipping_method_id']; $this->service = $definition['service']; $this->originalAmount = $definition['original_amount'] ?? $definition['amount']; $this->amount = $definition['amount']; $this->description = $definition['description'] ?? ''; $this->deliveryDate = $definition['delivery_date'] ?? NULL; $this->data = $definition['data'] ?? []; } /** * Gets the ID. * * @return string * The ID. */ public function getId() : string { return $this->id; } /** * Gets the shipping method ID. * * @return string * The shipping method ID. */ public function getShippingMethodId() : string { return $this->shippingMethodId; } /** * Gets the shipping service. * * The shipping service label is meant to be displayed when presenting rates * for selection. * * @return \Drupal\commerce_shipping\ShippingService * The shipping service. */ public function getService() : ShippingService { return $this->service; } /** * Gets the original amount. * * This is the amount before promotions and fees are applied. * * @return \Drupal\commerce_price\Price * The original amount. */ public function getOriginalAmount() : Price { return $this->originalAmount; } /** * Sets the original amount. * * @param \Drupal\commerce_price\Price $original_amount * The original amount. * * @return $this */ public function setOriginalAmount(Price $original_amount) { $this->originalAmount = $original_amount; return $this; } /** * Gets the amount. * * @return \Drupal\commerce_price\Price * The amount. */ public function getAmount() : Price { return $this->amount; } /** * Sets the amount. * * @param \Drupal\commerce_price\Price $amount * The amount. * * @return $this */ public function setAmount(Price $amount) { $this->amount = $amount; return $this; } /** * Gets the description. * * Displayed to the end-user when available. * * @return string * The description */ public function getDescription() : string { return $this->description; } /** * Sets the description. * * @param string $description * The description. * * @return $this */ public function setDescription(string $description) { $this->description = $description; return $this; } /** * Gets the delivery date, if known. * * @return \Drupal\Core\Datetime\DrupalDateTime|null * The delivery date, or NULL. */ public function getDeliveryDate() { return $this->deliveryDate; } /** * Sets the delivery date. * * @param \Drupal\Core\Datetime\DrupalDateTime $delivery_date * The delivery date. * * @return $this */ public function setDeliveryDate(DrupalDateTime $delivery_date) { $this->deliveryDate = $delivery_date; return $this; } /** * Gets the data. * * @return array * The data. */ public function getData() { return $this->data; } /** * Sets the data. * * @param array $data * The data. * * @return $this */ public function setData(array $data) { $this->data = $data; return $this; } /** * Gets the array representation of the shipping rate. * * @return array * The array representation of the shipping rate. */ public function toArray() : array { return [ 'id' => $this->id, 'shipping_method_id' => $this->shippingMethodId, 'service' => $this->service, 'original_amount' => $this->originalAmount, 'amount' => $this->amount, 'description' => $this->description, 'delivery_date' => $this->deliveryDate, 'data' => $this->data, ]; } }