Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ProductQuantityPriceRules] add interface for QuantityPriceFetcher and QuantityRuleFetcher #1628

Merged
merged 1 commit into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use CoreShop\Component\Registry\ServiceRegistryInterface;
use CoreShop\Component\ProductQuantityPriceRules\Model\QuantityRangePriceAwareInterface;

class QuantityPriceFetcher
class QuantityPriceFetcher implements QuantityPriceFetcherInterface
{
/**
* @var ServiceRegistryInterface
Expand All @@ -34,17 +34,6 @@ public function __construct(ServiceRegistryInterface $calculatorRegistry)
$this->calculatorRegistry = $calculatorRegistry;
}

/**
* @param ProductQuantityPriceRuleInterface $rule
* @param QuantityRangePriceAwareInterface $subject
* @param float $quantity
* @param int $originalPrice
* @param array $context
*
* @throws NoPriceFoundException
*
* @return int
*/
public function fetchQuantityPrice(
ProductQuantityPriceRuleInterface $rule,
QuantityRangePriceAwareInterface $subject,
Expand All @@ -60,16 +49,6 @@ public function fetchQuantityPrice(
return $service->calculateForQuantity($rule, $subject, $quantity, $originalPrice, $context);
}

/**
* @param QuantityRangeInterface $range
* @param QuantityRangePriceAwareInterface $subject
* @param int $originalPrice
* @param array $context
*
* @throws NoPriceFoundException
*
* @return int
*/
public function fetchRangePrice(
QuantityRangeInterface $range,
QuantityRangePriceAwareInterface $subject,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Component\ProductQuantityPriceRules\Fetcher;

use CoreShop\Component\ProductQuantityPriceRules\Calculator\CalculatorInterface;
use CoreShop\Component\ProductQuantityPriceRules\Exception\NoPriceFoundException;
use CoreShop\Component\ProductQuantityPriceRules\Model\ProductQuantityPriceRuleInterface;
use CoreShop\Component\ProductQuantityPriceRules\Model\QuantityRangeInterface;
use CoreShop\Component\Registry\ServiceRegistryInterface;
use CoreShop\Component\ProductQuantityPriceRules\Model\QuantityRangePriceAwareInterface;

interface QuantityPriceFetcherInterface
{
/**
* @param ProductQuantityPriceRuleInterface $rule
* @param QuantityRangePriceAwareInterface $subject
* @param float $quantity
* @param int $originalPrice
* @param array $context
*
* @throws NoPriceFoundException
*
* @return int
*/
public function fetchQuantityPrice(
ProductQuantityPriceRuleInterface $rule,
QuantityRangePriceAwareInterface $subject,
float $quantity,
int $originalPrice,
array $context
);

/**
* @param QuantityRangeInterface $range
* @param QuantityRangePriceAwareInterface $subject
* @param int $originalPrice
* @param array $context
*
* @throws NoPriceFoundException
*
* @return int
*/
public function fetchRangePrice(
QuantityRangeInterface $range,
QuantityRangePriceAwareInterface $subject,
int $originalPrice,
array $context
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use CoreShop\Component\ProductQuantityPriceRules\Model\QuantityRangePriceAwareInterface;
use CoreShop\Component\ProductQuantityPriceRules\Rule\Fetcher\ValidRulesFetcherInterface;

class QuantityRuleFetcher
class QuantityRuleFetcher implements QuantityRuleFetcherInterface
{
/**
* @var ValidRulesFetcherInterface
Expand All @@ -32,14 +32,6 @@ public function __construct(ValidRulesFetcherInterface $validRulesFetcher)
$this->validRulesFetcher = $validRulesFetcher;
}

/**
* @param QuantityRangePriceAwareInterface $subject
* @param array $context
*
* @throws NoRuleFoundException
*
* @return ProductQuantityPriceRuleInterface
*/
public function fetch(QuantityRangePriceAwareInterface $subject, array $context)
{
$quantityPriceRules = $this->getQuantityPriceRulesForSubject($subject, $context);
Expand All @@ -54,13 +46,7 @@ public function fetch(QuantityRangePriceAwareInterface $subject, array $context)

return $quantityPriceRules[0];
}

/**
* @param QuantityRangePriceAwareInterface $subject
* @param array $context
*
* @return array|ProductQuantityPriceRuleInterface[]
*/

public function getQuantityPriceRulesForSubject(QuantityRangePriceAwareInterface $subject, array $context)
{
/** @var ProductQuantityPriceRuleInterface[] $rules */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Component\ProductQuantityPriceRules\Fetcher;

use CoreShop\Component\ProductQuantityPriceRules\Exception\NoRuleFoundException;
use CoreShop\Component\ProductQuantityPriceRules\Model\ProductQuantityPriceRuleInterface;
use CoreShop\Component\ProductQuantityPriceRules\Model\QuantityRangePriceAwareInterface;
use CoreShop\Component\ProductQuantityPriceRules\Rule\Fetcher\ValidRulesFetcherInterface;

interface QuantityRuleFetcherInterface
{
/**
* @param QuantityRangePriceAwareInterface $subject
* @param array $context
*
* @throws NoRuleFoundException
*
* @return ProductQuantityPriceRuleInterface
*/
public function fetch(QuantityRangePriceAwareInterface $subject, array $context);

/**
* @param QuantityRangePriceAwareInterface $subject
* @param array $context
*
* @return array|ProductQuantityPriceRuleInterface[]
*/
public function getQuantityPriceRulesForSubject(QuantityRangePriceAwareInterface $subject, array $context);
}