Skip to content

Commit ae217d9

Browse files
authored
Merge pull request #9 from justbetter/feature/accept-decimal-qty-sort-customerprices-by-quantity
accept decimal qty and sort customerprices by quantity
2 parents 6984f87 + 4e38fd7 commit ae217d9

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/Actions/CustomerPrice.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,24 @@ public function __construct(
1515
) {
1616
}
1717

18-
public function getCustomerPrice(int $productId, int $customerId, int $quantity = 1): ?float
18+
public function getCustomerPrice(int $productId, int $customerId, float $quantity = 1): ?float
1919
{
2020
$this->customerPricingCollection
2121
->clear()
2222
->getSelect()
23-
->reset(Zend_Db_Select::WHERE);
23+
->reset(Zend_Db_Select::WHERE)
24+
->reset(Zend_Db_Select::ORDER);
2425

2526
$customerPrices = $this->customerPricingCollection
2627
->addFieldToFilter('product_id', ['eq' => $productId])
2728
->addFieldToFilter('customer_id', ['eq' => $customerId])
28-
->load()
29+
->addFieldToFilter('quantity', ['lteq' => $quantity])
30+
->setOrder('quantity')
2931
->getItems();
3032

31-
usort(
32-
$customerPrices,
33-
fn (CustomerPricing $a, CustomerPricing $b): int => $a->getData('quantity') <=> $b->getData('quantity')
34-
);
35-
3633
foreach ($customerPrices as $price) {
37-
if ($quantity >= $price->getData('quantity')) {
38-
return $price->getData('price');
34+
if ($quantity >= (float) $price->getData('quantity')) {
35+
return (float) $price->getData('price');
3936
}
4037
}
4138

0 commit comments

Comments
 (0)