Skip to content

Commit

Permalink
Add registration type items for carts
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k3lm committed Jul 4, 2024
1 parent c2e1ba6 commit 69ea823
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- What to scan -->
<file>.</file>
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>.history/</exclude-pattern>
<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ parameters:
treatPhpDocTypesAsCertain: false
paths:
- src/
ignoreErrors:
- '#Unsafe usage of new static\(\)#'
4 changes: 4 additions & 0 deletions src/BusinessLogic/Domain/Order/Models/OrderRequest/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\ItemType;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\OtherPaymentItem;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\ProductItem;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\RegistrationItem;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\ServiceItem;

/**
Expand Down Expand Up @@ -126,6 +127,9 @@ public static function fromArray(array $data): Cart
case ItemType::TYPE_DISCOUNT:
$itemInstances[] = DiscountItem::fromArray($itemData);
break;
case ItemType::TYPE_REGISTRATION:
$itemInstances[] = RegistrationItem::fromArray($itemData);
break;
case ItemType::TYPE_SERVICE:
$itemInstances[] = ServiceItem::fromArray($itemData);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class ItemType
public const TYPE_INVOICE_FEE = 'invoice_fee';
public const TYPE_HANDLING = 'handling';
public const TYPE_DISCOUNT = 'discount';
public const TYPE_REGISTRATION = 'registration';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item;

/**
* Class RegistrationItem
*
* @package SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item
*/
class RegistrationItem extends Item
{
/**
* @var string|int A unique code that refers to this registration.
*/
private $reference;

/**
* @var string A name to describe this registration.
*/
private $name;

/**
* @param int|string $reference
* @param string $name
* @param int $totalWithTax
*/
public function __construct($reference, string $name, int $totalWithTax)
{
parent::__construct($totalWithTax, ItemType::TYPE_REGISTRATION);

$this->reference = $reference;
$this->name = $name;
}

/**
* Create RegistrationItem object from array.
*
* @param array $data
*
* @return RegistrationItem
*/
public static function fromArray(array $data): Item
{
$totalWithTax = self::getDataValue($data, 'total_with_tax', 0);
$reference = self::getDataValue($data, 'reference');
$name = self::getDataValue($data, 'name');

return new self($reference, $name, $totalWithTax);
}

/**
* @return int|string
*/
public function getReference()
{
return $this->reference;
}

/**
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* @inheritDoc
*/
public function toArray(): array
{
return $this->transformPropertiesToAnArray(get_object_vars($this));
}
}

0 comments on commit 69ea823

Please sign in to comment.