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

Fix : wrong value in VolumeUnits steps when creating a new rule #4889

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions assets/css/utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ li > a.text-danger // very specific selector for bootstrap dropdown
-ms-user-select: none; /* IE 10 and IE 11 */
user-select: none; /* Standard syntax */
}

/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button.no-number-input-arrow,
input::-webkit-inner-spin-button.no-number-input-arrow {
-webkit-appearance: none;
margin: 0;
}

/* Firefox */
input[type=number].no-number-input-arrow {
-moz-appearance: textfield;
}
52 changes: 26 additions & 26 deletions js/app/components/PriceRangeEditor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useRef } from 'react'
import React, { useState, useRef, useEffect } from 'react'
import { getCurrencySymbol } from '../i18n'
import { useTranslation } from 'react-i18next'

Expand Down Expand Up @@ -75,22 +75,30 @@ export default ({ defaultValue, onChange }) => {

const stepEl = useRef(null)
const thresholdEl = useRef(null)
const initialLoad = useRef(true)

useEffect(() => {
if (!initialLoad.current) {
onChange({
attribute,
price: price,
step,
threshold,
})
} else {
initialLoad.current = false
}
}, [price, threshold, attribute, step])

return (
<div>
<label className="mr-2">
<input type="number" size="4"
defaultValue={ price / 100 } min="0" step=".001"
className="form-control d-inline-block"
className="form-control d-inline-block no-number-input-arrow"
style={{ width: '80px' }}
onChange={ e => {
setPrice(e.target.value * 100)
onChange({
attribute,
price: e.target.value * 100,
step,
threshold,
})
}} />
<span className="ml-2">{ getCurrencySymbol() }</span>
</label>
Expand All @@ -102,12 +110,6 @@ export default ({ defaultValue, onChange }) => {
style={{ width: '80px' }}
onChange={ e => {
setStep(multiplyIfNeeded(e.target.value, unit))
onChange({
attribute,
price,
step: multiplyIfNeeded(e.target.value, unit),
threshold: multiplyIfNeeded(thresholdEl.current.value, e.target.value),
})
}} />
<select
className="form-control d-inline-block align-top ml-2"
Expand All @@ -116,12 +118,16 @@ export default ({ defaultValue, onChange }) => {
onChange={ e => {
setUnit(e.target.value)
setAttribute(unitToAttribute(e.target.value))
onChange({
attribute: unitToAttribute(e.target.value),
price,
step: multiplyIfNeeded(stepEl.current.value, e.target.value),
threshold: multiplyIfNeeded(thresholdEl.current.value, e.target.value),
})

const newUnit = e.target.value

if (newUnit === 'vu') {
setStep(step / 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug if the switch is between units that are both multiplied (kg, km); it needs an extra check that the current unit is 1000x (kg, km) and the newUnit is not (vu), and vice versa:

Screenshot 2025-02-10 at 14 35 17

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be add a helper to check if a unit is multiplied or not instead of hard-coding 'vu' to allow adding more units

setThreshold(threshold / 1000)
} else {
setStep(step * 1000)
setThreshold(threshold * 1000)
}
}}>
<option value="km">km</option>
<option value="kg">kg</option>
Expand All @@ -136,12 +142,6 @@ export default ({ defaultValue, onChange }) => {
style={{ width: '80px' }}
onChange={ e => {
setThreshold(multiplyIfNeeded(e.target.value, unit))
onChange({
attribute,
price,
step,
threshold: multiplyIfNeeded(e.target.value, unit),
})
}} />
<span className="ml-2">
<UnitLabel unit={ unit } />
Expand Down
4 changes: 3 additions & 1 deletion src/Doctrine/EventSubscriber/TaskSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private function handleStateChangesForTasks(EntitymanagerInterface $em, array $t
continue;
}

// if all tasks of a delivery are cancelled, cancel the linked order
$tasks = $delivery->getTasks();
$cancelOrder = true;
foreach ($tasks as $task) {
Expand All @@ -233,7 +234,8 @@ private function handleStateChangesForTasks(EntitymanagerInterface $em, array $t
}
}

if ($cancelOrder && $order->getState() !== OrderInterface::STATE_CANCELLED) {
// do not cancel order if order is "refused"
if ($cancelOrder && $order->getState() !== OrderInterface::STATE_CANCELLED && $order->getState() !== OrderInterface::STATE_REFUSED) {
$this->orderManager->cancel($order, 'All tasks were cancelled');
$em->flush();
}
Expand Down
Loading