Skip to content
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 @@ -11,7 +11,7 @@ Feature: Adding a new product with a simple quantity price rule
Scenario: Add a quantity price rule with no conditions
Given adding a quantity price rule to product "Shoe" named "default-product-quantity-price-rule" and with calculation-behaviour "volume"
And the quantity price rule is active
And the quantity price rule has a range from 0 to 10 with behaviour percentage-decrease of 10%
And the quantity price rule has a range starting from 0 with behaviour percentage-decrease of 10%
Then the quantity price rule should be valid for product "Shoe"
And the product "Shoe" should be priced at "10000"
Given I add the product "Shoe" to my cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,49 +140,46 @@ public function theProductQuantityPriceRuleIsInActive(ProductQuantityPriceRuleIn
}

/**
* @Given /^the (quantity price rule "[^"]+") has a range from ([^"]+) to ([^"]+) with behaviour percentage-decrease of ([^"]+)%$/
* @Given /^the (quantity price rule) has a range from ([^"]+) to ([^"]+) with behaviour percentage-decrease of ([^"]+)%$/
* @Given /^the (quantity price rule "[^"]+") has a range starting from ([^"]+) with behaviour percentage-decrease of ([^"]+)%$/
* @Given /^the (quantity price rule) has a range starting from ([^"]+) with behaviour percentage-decrease of ([^"]+)%$/
*/
public function theProductQuantityPriceRuleHasRangePercentageDecrease(ProductQuantityPriceRuleInterface $rule, int $from, int $to, $percentage)
public function theProductQuantityPriceRuleHasRangePercentageDecrease(ProductQuantityPriceRuleInterface $rule, int $from, $percentage)
{
/**
* @var QuantityRangeInterface $range
*/
$range = $this->rangeFactory->createNew();
$range->setPricingBehaviour('percentage_decrease');
$range->setPercentage($percentage);
$range->setRangeFrom($from);
$range->setRangeTo($to);
$range->setRangeStartingFrom($from);

$this->addRange($rule, $range);
}

/**
* @Given /^the (quantity price rule "[^"]+") has a range from ([^"]+) to ([^"]+) with behaviour percentage-increase of ([^"]+)%$/
* @Given /^the (quantity price rule) has a range from ([^"]+) to ([^"]+) with behaviour percentage-increase of ([^"]+)%$/
* @Given /^the (quantity price rule "[^"]+") has a range starting from to ([^"]+) with behaviour percentage-increase of ([^"]+)%$/
* @Given /^the (quantity price rule) has a range starting from ([^"]+) with behaviour percentage-increase of ([^"]+)%$/
*/
public function theProductQuantityPriceRuleHasRangePercentageIncrease(ProductQuantityPriceRuleInterface $rule, int $from, int $to, $percentage)
public function theProductQuantityPriceRuleHasRangePercentageIncrease(ProductQuantityPriceRuleInterface $rule, int $from, $percentage)
{
/**
* @var QuantityRangeInterface $range
*/
$range = $this->rangeFactory->createNew();
$range->setPricingBehaviour('percentage_increase');
$range->setPercentage($percentage);
$range->setRangeFrom($from);
$range->setRangeTo($to);
$range->setRangeStartingFrom($from);

$this->addRange($rule, $range);
}

/**
* @Given /^the (quantity price rule "[^"]+") has a range from ([^"]+) to ([^"]+) with behaviour amount-decrease of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule) has a range from ([^"]+) to ([^"]+) with behaviour amount-decrease of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule "[^"]+") has a range starting from ([^"]+) with behaviour amount-decrease of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule) has a range starting from ([^"]+) with behaviour amount-decrease of ([^"]+) in (currency "[^"]+")$/
*/
public function theProductQuantityPriceRuleHasRangeAmountDecrease(
ProductQuantityPriceRuleInterface $rule,
int $from,
int $to,
$amount,
CurrencyInterface $currency
) {
Expand All @@ -192,21 +189,19 @@ public function theProductQuantityPriceRuleHasRangeAmountDecrease(
$range = $this->rangeFactory->createNew();
$range->setPricingBehaviour('amount_decrease');
$range->setAmount($amount);
$range->setRangeFrom($from);
$range->setRangeTo($to);
$range->setRangeStartingFrom($from);
$range->setCurrency($currency);

$this->addRange($rule, $range);
}

/**
* @Given /^the (quantity price rule "[^"]+") has a range from ([^"]+) to ([^"]+) with behaviour amount-increase of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule) has a range from ([^"]+) to ([^"]+) with behaviour amount-increase of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule "[^"]+") has a range starting from ([^"]+) with behaviour amount-increase of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule) has a range starting from ([^"]+) with behaviour amount-increase of ([^"]+) in (currency "[^"]+")$/
*/
public function theProductQuantityPriceRuleHasRangeAmountIncrease(
ProductQuantityPriceRuleInterface $rule,
int $from,
int $to,
$amount,
CurrencyInterface $currency
) {
Expand All @@ -216,27 +211,25 @@ public function theProductQuantityPriceRuleHasRangeAmountIncrease(
$range = $this->rangeFactory->createNew();
$range->setPricingBehaviour('amount_increase');
$range->setAmount($amount);
$range->setRangeFrom($from);
$range->setRangeTo($to);
$range->setRangeStartingFrom($from);
$range->setCurrency($currency);

$this->addRange($rule, $range);
}

/**
* @Given /^the (quantity price rule "[^"]+") has a range from ([^"]+) to ([^"]+) with behaviour fixed of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule) has a range from ([^"]+) to ([^"]+) with behaviour fixed of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule "[^"]+") has a range starting from ([^"]+) with behaviour fixed of ([^"]+) in (currency "[^"]+")$/
* @Given /^the (quantity price rule) has a range starting from ([^"]+) with behaviour fixed of ([^"]+) in (currency "[^"]+")$/
*/
public function theProductQuantityPriceRuleHasRangeFixed(ProductQuantityPriceRuleInterface $rule, int $from, int $to, $amount, CurrencyInterface $currency)
public function theProductQuantityPriceRuleHasRangeFixed(ProductQuantityPriceRuleInterface $rule, int $from, $amount, CurrencyInterface $currency)
{
/**
* @var QuantityRangeInterface $range
*/
$range = $this->rangeFactory->createNew();
$range->setPricingBehaviour('fixed');
$range->setAmount($amount);
$range->setRangeFrom($from);
$range->setRangeTo($to);
$range->setRangeStartingFrom($from);
$range->setCurrency($currency);

$this->addRange($rule, $range);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}

$dataCheck[$unit][] = [
'row' => $realRowIndex,
'from' => $quantityRange->getRangeFrom(),
'to' => $quantityRange->getRangeTo(),
'row' => $realRowIndex,
'startingFrom' => $quantityRange->getRangeStartingFrom()
];
}

Expand All @@ -71,29 +70,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
foreach ($quantityRangesToCheck as $quantityRange) {

$realRowIndex = $quantityRange['row'];
$from = $quantityRange['from'];
$to = $quantityRange['to'];
$startingFrom = $quantityRange['startingFrom'];

if (!is_numeric($from)) {
$form->addError(new FormError('Field "from" in row ' . $realRowIndex . ' needs to be numeric'));
if (!is_numeric($startingFrom)) {
$form->addError(new FormError('Field "starting from" in row ' . $realRowIndex . ' needs to be numeric'));
break;
} elseif ((int) $from < 0) {
$form->addError(new FormError('Field "from" in row ' . $realRowIndex . ' needs to be greater or equal than 0'));
} elseif ((int) $startingFrom < 0) {
$form->addError(new FormError('Field "starting from" in row ' . $realRowIndex . ' needs to be greater or equal than 0'));
break;
} elseif ((int) $from < $lastEnd) {
$form->addError(new FormError('Field "from" in row ' . $realRowIndex . ' needs to be greater than ' . $lastEnd));
} elseif ((int) $startingFrom <= $lastEnd) {
$form->addError(new FormError('Field "starting from" in row ' . $realRowIndex . ' needs to be greater than ' . $lastEnd));
break;
}

if (!is_numeric($to)) {
$form->addError(new FormError('Field "to" in row ' . $realRowIndex . ' needs to be numeric'));
break;
} elseif ((int) $to < $from) {
$form->addError(new FormError('Field "to" in row ' . $realRowIndex . ' needs to be greater than ' . $from));
break;
}

$lastEnd = (int) $to;
$lastEnd = (int) $startingFrom;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ coreshop.product_quantity_price_rules.ranges = Class.create(coreshop.product_qua
grid.getStore().each(function (record) {
ranges.push({
'id': record.get('rangeId'),
'rangeFrom': record.get('rangeFrom'),
'rangeTo': record.get('rangeTo'),
'rangeStartingFrom': record.get('rangeStartingFrom'),
'pricingBehaviour': record.get('pricingBehaviour'),
'unitDefinition': record.get('unitDefinition'),
'amount': record.get('amount'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

class QuantityRangePriceCurrencyAware extends Constraint
{
public $message = '{{ range }} needs a valid currency to work.';
public $message = '{{ rangeStartingFrom }} needs a valid currency to work.';
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function validate($value, Constraint $constraint)

if (!$value->getCurrency() instanceof CurrencyInterface) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ range }}', sprintf('Range from %d to %d', $value->getRangeFrom(), $value->getRangeTo()))
->setParameter('{{ rangeStartingFrom }}', sprintf('Range starting from %d', $value->getRangeStartingFrom()))
->addViolation();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{% for range in sorted_unit_range.ranges %}
<tr class="">
<td class="">
{{ 'coreshop.ui.product_quantity_price_rules.starting_from'|trans }} <span class="">{{ range.getRangeFrom() }}</span>
{{ 'coreshop.ui.product_quantity_price_rules.starting_from'|trans }} <span class="">{{ range.getRangeStartingFrom() }}</span>
{% if range.isHighlighted() %}
<span class="badge badge-info">{{ 'coreshop.ui.product_quantity_price_rules.best_offer'|trans }}</span>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public function buildForm(FormBuilderInterface $builder, array $options = [])
parent::buildForm($builder, $options);

$builder
->add('rangeFrom', IntegerType::class, [])
->add('rangeTo', IntegerType::class, [])
->add('rangeStartingFrom', IntegerType::class, [])
->add('pricingBehaviour', ChoiceType::class, [
'choices' => $this->actionTypes,
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ CoreShop\Component\ProductQuantityPriceRules\Model\QuantityRange:
id: true
generator:
strategy: AUTO
rangeFrom:
column: range_from
type: integer
rangeTo:
column: range_to
rangeStartingFrom:
column: range_starting_from
type: integer
pricingBehaviour:
column: pricing_behaviour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ coreshop.product_quantity_price_rules.ranges = Class.create({
grid.getStore().each(function (record) {
ranges.push({
'id': record.get('rangeId'),
'rangeFrom': record.get('rangeFrom'),
'rangeTo': record.get('rangeTo'),
'rangeStartingFrom': record.get('rangeStartingFrom'),
'pricingBehaviour': record.get('pricingBehaviour'),
'highlighted': record.get('highlighted'),
});
Expand Down Expand Up @@ -150,12 +149,12 @@ coreshop.product_quantity_price_rules.ranges = Class.create({
hidden: true
},
{
text: t('coreshop_product_quantity_price_rules_range_from'),
text: t('coreshop_product_quantity_price_rules_range_starting_from'),
flex: 1,
sortable: false,
readOnly: true,
dataIndex: 'rangeFrom',
name: 'quantity_range_from',
dataIndex: 'rangeStartingFrom',
name: 'quantity_range_starting_from',
getEditor: function () {
return new Ext.form.NumberField({
minValue: 0
Expand All @@ -168,25 +167,6 @@ coreshop.product_quantity_price_rules.ranges = Class.create({
return value + ' ' + t('coreshop_product_quantity_price_rules_quantity_amount');
}
},
{
text: t('coreshop_product_quantity_price_rules_range_to'),
flex: 1,
sortable: false,
dataIndex: 'rangeTo',
name: 'quantity_range_to',
getEditor: function () {
return new Ext.form.NumberField({
minValue: 1
});
},
renderer: function (value, cell, record, rowIndex) {
var lastElement = record.store.getRange().length === (rowIndex + 1);
if (value === undefined || value === null) {
return '0' + ' ' + t('coreshop_product_quantity_price_rules_quantity_amount');
}
return value + ' ' + t('coreshop_product_quantity_price_rules_quantity_amount') + (lastElement === true ? '+' : '');
}
},
{
text: t('coreshop_product_quantity_price_rules_behaviour'),
flex: 1,
Expand Down Expand Up @@ -426,8 +406,7 @@ coreshop.product_quantity_price_rules.ranges = Class.create({
lastEntry = grid.getStore().last();

return new modelClass({
rangeFrom: lastEntry !== null ? lastEntry.get('rangeTo') + 1 : 0,
rangeTo: lastEntry !== null ? lastEntry.get('rangeTo') + 10 : 10,
rangeStartingFrom: lastEntry !== null ? lastEntry.get('rangeStartingFrom') + 10 : 0,
pricingBehaviour: 'fixed',
highlight: false,
rangeId: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
coreshop_product_quantity_price_rules: 'Produkt Stückmengen-Preisregeln'
coreshop_product_quantity_price_rules_calculation_behaviour: 'Berechnungsverhalten'
coreshop_product_quantity_price_rules_ranges: 'Stückmengen-Preisregeln'
coreshop_product_quantity_price_rules_range_from: 'Von'
coreshop_product_quantity_price_rules_range_to: 'Bis'
coreshop_product_quantity_price_rules_range_starting_from: 'Ab'
coreshop_product_quantity_price_rules_highlight: 'Hervorheben'
coreshop_product_quantity_price_rules_quantity_amount: 'Einheiten'
coreshop_product_quantity_price_rules_copy_ranges: 'Bereiche kopieren'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
coreshop_product_quantity_price_rules: 'Product Quantity Price Rules'
coreshop_product_quantity_price_rules_calculation_behaviour: 'Calculation Behaviour'
coreshop_product_quantity_price_rules_ranges: 'Quantity Price Ranges'
coreshop_product_quantity_price_rules_range_from: 'From'
coreshop_product_quantity_price_rules_range_to: 'To'
coreshop_product_quantity_price_rules_range_starting_from: 'Starting from'
coreshop_product_quantity_price_rules_highlight: 'Highlight'
coreshop_product_quantity_price_rules_quantity_amount: 'Units'
coreshop_product_quantity_price_rules_copy_ranges: 'Copy Ranges'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,11 @@ protected function locate(Collection $ranges, int $quantity, ProductUnitDefiniti
/** @var CoreQuantityRangeInterface $range */
foreach ($unitFilteredRanges as $index => $range) {

// if last range and quantity is greater: count!
if ($index+1 === count($unitFilteredRanges) && $quantity > $range->getRangeTo()) {
$cheapestRangePrice = $range;
if ($range->getRangeStartingFrom() > $quantity) {
break;
}

if ($range->getRangeFrom() <= $quantity && $quantity <= $range->getRangeTo()) {
$cheapestRangePrice = $range;
break;
}
$cheapestRangePrice = $range;
}

return $cheapestRangePrice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,12 @@ protected function locate(Collection $ranges, int $quantity)
$cheapestRangePrice = null;
/** @var QuantityRangeInterface $range */
foreach ($ranges as $index => $range) {
// if last range and quantity is greater: count!
if ($index + 1 === count($ranges) && $quantity > $range->getRangeTo()) {
$cheapestRangePrice = $range;
break;
}

if ($range->getRangeFrom() <= $quantity && $quantity <= $range->getRangeTo()) {
$cheapestRangePrice = $range;
if ($range->getRangeStartingFrom() > $quantity) {
break;
}

$cheapestRangePrice = $range;
}

return $cheapestRangePrice;
Expand Down
Loading