-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIPRES-261: Create fresh specific price
- Loading branch information
Showing
9 changed files
with
312 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Action; | ||
|
||
use Mollie\Subscription\DTO\CreateSpecificPriceData; | ||
use Mollie\Subscription\Repository\SpecificPriceRepositoryInterface; | ||
|
||
class CreateSpecificPriceAction | ||
{ | ||
/** @var SpecificPriceRepositoryInterface */ | ||
private $specificPriceRepository; | ||
|
||
public function __construct( | ||
SpecificPriceRepositoryInterface $specificPriceRepository | ||
) { | ||
$this->specificPriceRepository = $specificPriceRepository; | ||
} | ||
|
||
/** | ||
* @throws \Throwable | ||
*/ | ||
public function run(CreateSpecificPriceData $data): \SpecificPrice | ||
{ | ||
/** @var \SpecificPrice[] $specificPrices */ | ||
$specificPrices = $this->specificPriceRepository->findAllBy([ | ||
'id_product' => $data->getProductId(), | ||
'id_product_attribute' => $data->getProductAttributeId(), | ||
'price' => $data->getPrice(), | ||
'id_customer' => $data->getCustomerId(), | ||
'id_shop' => $data->getShopId(), | ||
'id_currency' => $data->getCurrencyId(), | ||
'id_shop_group' => $data->getShopGroupId(), | ||
'id_country' => 0, | ||
'id_group' => 0, | ||
'from_quantity' => 0, | ||
'reduction' => 0, | ||
'reduction_type' => 'amount', | ||
'from' => '0000-00-00 00:00:00', | ||
'to' => '0000-00-00 00:00:00', | ||
]); | ||
|
||
foreach ($specificPrices as $specificPrice) { | ||
$specificPrice->delete(); | ||
} | ||
|
||
$specificPrice = new \SpecificPrice(); | ||
|
||
$specificPrice->id_product = $data->getProductId(); | ||
$specificPrice->id_product_attribute = $data->getProductAttributeId(); | ||
$specificPrice->price = $data->getPrice(); | ||
$specificPrice->id_customer = $data->getCustomerId(); | ||
$specificPrice->id_shop = $data->getShopId(); | ||
$specificPrice->id_currency = $data->getCurrencyId(); | ||
$specificPrice->id_shop_group = $data->getShopGroupId(); | ||
$specificPrice->id_country = 0; | ||
$specificPrice->id_group = 0; | ||
$specificPrice->from_quantity = 0; | ||
$specificPrice->reduction = 0; | ||
$specificPrice->reduction_type = 'amount'; | ||
$specificPrice->from = '0000-00-00 00:00:00'; | ||
$specificPrice->to = '0000-00-00 00:00:00'; | ||
|
||
$specificPrice->add(); | ||
|
||
return $specificPrice; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\DTO; | ||
|
||
class CreateSpecificPriceData | ||
{ | ||
/** @var int */ | ||
private $productId; | ||
/** @var int */ | ||
private $productAttributeId; | ||
/** @var float */ | ||
private $price; | ||
/** @var int */ | ||
private $customerId; | ||
/** @var int */ | ||
private $shopId; | ||
/** @var int */ | ||
private $shopGroupId; | ||
/** @var int */ | ||
private $currencyId; | ||
|
||
public function __construct( | ||
int $productId, | ||
int $productAttributeId, | ||
float $price, | ||
int $customerId, | ||
int $shopId, | ||
int $shopGroupId, | ||
int $currencyId | ||
) { | ||
$this->productId = $productId; | ||
$this->productAttributeId = $productAttributeId; | ||
$this->price = $price; | ||
$this->customerId = $customerId; | ||
$this->shopId = $shopId; | ||
$this->shopGroupId = $shopGroupId; | ||
$this->currencyId = $currencyId; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getProductId(): int | ||
{ | ||
return $this->productId; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getProductAttributeId(): int | ||
{ | ||
return $this->productAttributeId; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getPrice(): float | ||
{ | ||
return $this->price; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getCustomerId(): int | ||
{ | ||
return $this->customerId; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getShopId(): int | ||
{ | ||
return $this->shopId; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getShopGroupId(): int | ||
{ | ||
return $this->shopGroupId; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getCurrencyId(): int | ||
{ | ||
return $this->currencyId; | ||
} | ||
|
||
public static function create( | ||
int $productId, | ||
int $productAttributeId, | ||
float $price, | ||
int $customerId, | ||
int $shopId, | ||
int $shopGroupId, | ||
int $currencyId | ||
): self { | ||
return new self( | ||
$productId, | ||
$productAttributeId, | ||
$price, | ||
$customerId, | ||
$shopId, | ||
$shopGroupId, | ||
$currencyId | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Repository; | ||
|
||
class SpecificPriceRepository extends AbstractRepository implements SpecificPriceRepositoryInterface | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(\SpecificPrice::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Repository; | ||
|
||
use Mollie\Repository\ReadOnlyRepositoryInterface; | ||
|
||
interface SpecificPriceRepositoryInterface extends ReadOnlyRepositoryInterface | ||
{ | ||
} |
Oops, something went wrong.