Skip to content

Commit b170d1c

Browse files
Christian Braunmamazu
authored andcommitted
removed optional ignoreActive option
1 parent 3b0b3c5 commit b170d1c

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

src/Repository/CustomerOptionValuePriceRepository.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOptionValueInterface;
88
use Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOptionValuePriceInterface;
9-
use DateTime;
109
use Doctrine\ORM\NonUniqueResultException;
1110
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
1211
use Sylius\Component\Channel\Model\ChannelInterface;
@@ -16,31 +15,25 @@
1615
class CustomerOptionValuePriceRepository extends EntityRepository implements CustomerOptionValuePriceRepositoryInterface
1716
{
1817
/**
19-
* @throws NonUniqueResultException
20-
*
2118
* @param ChannelInterface $channel
2219
* @param ProductInterface $product
2320
* @param CustomerOptionValueInterface $customerOptionValue
24-
* @param bool $ignoreActive
21+
*
22+
* @throws NonUniqueResultException
2523
*/
2624
public function getPriceForChannel(
2725
ChannelInterface $channel,
2826
ProductInterface $product,
29-
CustomerOptionValueInterface $customerOptionValue,
30-
bool $ignoreActive = false
27+
CustomerOptionValueInterface $customerOptionValue
3128
): ?CustomerOptionValuePriceInterface {
3229
$qb = $this->createQueryBuilder('price');
3330
$qb->where('price.channel = :channel');
3431
$qb->andWhere('price.customerOptionValue = :customerOptionValue');
3532

36-
if (!$ignoreActive) {
37-
$qb->leftJoin('price.dateValid', 'dr');
38-
$qb->andWhere('price.dateValid IS NULL OR (:now >= dr.start AND :now <= dr.end)');
39-
$qb->setParameter('now', new DateTime());
40-
}
41-
4233
$qb->andWhere('(price.product IS NOT NULL AND price.product = :product) OR price.product IS NULL');
4334

35+
// If a product price overwrite exists the result could contain multiple entries. Therefore we order the
36+
// overwritten price to the top to get it as the only result.
4437
$qb->orderBy('price.product', 'DESC');
4538
$qb->setMaxResults(1);
4639

@@ -50,8 +43,6 @@ public function getPriceForChannel(
5043

5144
$query = $qb->getQuery();
5245

53-
$sql = $query->getSQL();
54-
5546
/** @var CustomerOptionValuePriceInterface|null $result */
5647
$result = $query->getOneOrNullResult();
5748
Assert::nullOrIsInstanceOf($result, CustomerOptionValuePriceInterface::class);

src/Repository/CustomerOptionValuePriceRepositoryInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interface CustomerOptionValuePriceRepositoryInterface extends RepositoryInterfac
1515
public function getPriceForChannel(
1616
ChannelInterface $channel,
1717
ProductInterface $product,
18-
CustomerOptionValueInterface $customerOptionValue,
19-
bool $ignoreActive = false
18+
CustomerOptionValueInterface $customerOptionValue
2019
): ?CustomerOptionValuePriceInterface;
2120
}

tests/PHPUnit/Factory/OrderItemOptionFactoryTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Brille24\SyliusCustomerOptionsPlugin\Factory\OrderItemOptionFactory;
1515
use Brille24\SyliusCustomerOptionsPlugin\Factory\OrderItemOptionFactoryInterface;
1616
use Brille24\SyliusCustomerOptionsPlugin\Repository\CustomerOptionRepositoryInterface;
17+
use Brille24\SyliusCustomerOptionsPlugin\Repository\CustomerOptionValuePriceRepositoryInterface;
1718
use Brille24\SyliusCustomerOptionsPlugin\Services\CustomerOptionValueResolverInterface;
1819
use Doctrine\Common\Collections\ArrayCollection;
1920
use PHPUnit\Framework\TestCase;
@@ -64,7 +65,11 @@ function (CustomerOptionInterface $customerOption, $valueToMatch) {
6465

6566
$baseFactory->method('createNew')->willReturn(self::createMock(OrderItemOptionInterface::class));
6667

67-
$this->orderItemOptionFactory = new OrderItemOptionFactory($baseFactory, $customerOptionRepo, $valueResolver);
68+
$customerOptionValuePrice = self::createMock(CustomerOptionValuePriceInterface::class);
69+
$customerOptionValuePriceRepository = self::createMock(CustomerOptionValuePriceRepositoryInterface::class);
70+
$customerOptionValuePriceRepository->method('getPriceForChannel')->willReturn($customerOptionValuePrice);
71+
72+
$this->orderItemOptionFactory = new OrderItemOptionFactory($baseFactory, $customerOptionRepo, $valueResolver, $customerOptionValuePriceRepository);
6873
}
6974

7075
private function addCustomerOption(CustomerOptionInterface $customerOption)

tests/PHPUnit/Service/CustomerOptionValueRefresherTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
use Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOptionValuePriceInterface;
1111
use Brille24\SyliusCustomerOptionsPlugin\Entity\OrderItemInterface as Brille24OrderItem;
1212
use Brille24\SyliusCustomerOptionsPlugin\Entity\OrderItemOptionInterface;
13+
use Brille24\SyliusCustomerOptionsPlugin\Repository\CustomerOptionValuePriceRepositoryInterface;
1314
use Brille24\SyliusCustomerOptionsPlugin\Services\CustomerOptionValueRefresher;
1415
use Doctrine\Common\Collections\ArrayCollection;
16+
use PHPUnit\Framework\MockObject\MockObject;
1517
use PHPUnit\Framework\TestCase;
1618
use Sylius\Component\Core\Model\ChannelInterface;
1719
use Sylius\Component\Core\Model\OrderInterface;
@@ -32,15 +34,24 @@ class CustomerOptionValueRefresherTest extends TestCase
3234
/** @var int */
3335
private $priceUpdate;
3436

35-
/** @var ChannelInterface */
37+
/** @var ChannelInterface|MockObject */
3638
private $channel;
3739

3840
//<editor-fold desc="Helper function for setup">
41+
/**
42+
* @var CustomerOptionValuePriceRepositoryInterface|MockObject
43+
*/
44+
private $customerOptionValuePriceRepository;
45+
3946
public function setUp(): void
4047
{
4148
$this->channel = self::createMock(ChannelInterface::class);
4249

43-
$this->customerOptionValueRefresher = new CustomerOptionValueRefresher();
50+
$this->customerOptionValuePriceRepository = $this->createMock(
51+
CustomerOptionValuePriceRepositoryInterface::class
52+
);
53+
54+
$this->customerOptionValueRefresher = new CustomerOptionValueRefresher($this->customerOptionValuePriceRepository);
4455
}
4556

4657
private function createOrder(array $orderItems): OrderInterface
@@ -90,7 +101,7 @@ private function createCustomerOptionValue(array $config): CustomerOptionValueIn
90101
$customerOptionValue->method('getCode')->willReturn($config['code']);
91102
$customerOptionValue->method('getName')->willReturn($config['name'] ?? null);
92103

93-
$customerOptionValue->method('getPriceForChannel')->willReturnCallback(
104+
$this->customerOptionValuePriceRepository->method('getPriceForChannel')->willReturnCallback(
94105
function (ChannelInterface $channel) use ($price) {
95106
$customerOptionPrice = self::createMock(CustomerOptionValuePriceInterface::class);
96107
$customerOptionPrice->method('getAmount')->willReturn($price);

0 commit comments

Comments
 (0)