-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[shopsys] transport restrictions (#3397)
- Loading branch information
Showing
47 changed files
with
1,067 additions
and
261 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
assets/js/admin/components/TransportPriceWithWeightLimitCollection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Register from '../../common/utils/Register'; | ||
import { addNewItemToCollection, removeItemFromCollection } from '../validation/customization/customizeCollectionBundle'; | ||
|
||
export default class TransportPriceWithWeightLimitCollection { | ||
static init () { | ||
const $transportPriceItemAdd = $('.js-transport-prices-item-add'); | ||
const $transportPricesCollection = $('.js-transport-prices'); | ||
|
||
$transportPriceItemAdd.off('click'); | ||
$transportPricesCollection.off('click', '.js-transport-prices-item-remove'); | ||
|
||
$transportPricesCollection.on('click', '.js-transport-prices-item-remove', function (event) { | ||
const $item = $(this).closest('.js-transport-prices-item'); | ||
const index = $item.data('index'); | ||
removeItemFromCollection('.js-transport-prices', index); | ||
$item.remove(); | ||
|
||
event.preventDefault(); | ||
}); | ||
|
||
$transportPriceItemAdd.on('click', function () { | ||
const $collection = $(this).closest('.js-transport-prices-form-group').find('.js-transport-prices'); | ||
const index = $collection.data('index'); | ||
|
||
const prototype = $collection.data('prototype'); | ||
const item = prototype | ||
.replace(/__name__label__/g, index) | ||
.replace(/__name__/g, index); | ||
const $item = $($.parseHTML(item)); | ||
$item.data('index', index); | ||
|
||
$collection.data('index', index + 1); | ||
|
||
$collection.append($item); | ||
(new Register()).registerNewContent($item); | ||
|
||
addNewItemToCollection('.js-transport-prices', index); | ||
|
||
event.preventDefault(); | ||
return false; | ||
}); | ||
} | ||
} | ||
|
||
(new Register()).registerCallback(TransportPriceWithWeightLimitCollection.init, 'TransportPriceWithWeightLimitCollection.init'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
assets/js/admin/validation/form/validationTransportPrices.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Register from '../../../common/utils/Register'; | ||
|
||
function validationTransportPrices ($container) { | ||
window.$('form[name="transport_form"]').jsFormValidator({ | ||
callbacks: { | ||
validateTransportPricesOnDomain: function () { | ||
// JS validation is not necessary | ||
} | ||
} | ||
}); | ||
} | ||
|
||
(new Register()).registerCallback(validationTransportPrices); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Form\Admin\Transport\Price; | ||
|
||
use Override; | ||
use Shopsys\FrameworkBundle\Model\Transport\PriceWithLimitData; | ||
use Shopsys\FrameworkBundle\Twig\InputPriceLabelExtension; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\FormType; | ||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | ||
use Symfony\Component\Form\Extension\Core\Type\IntegerType; | ||
use Symfony\Component\Form\Extension\Core\Type\MoneyType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
||
class PriceWithLimitType extends AbstractType | ||
{ | ||
/** | ||
* @param \Shopsys\FrameworkBundle\Twig\InputPriceLabelExtension $inputPriceLabelExtension | ||
*/ | ||
public function __construct( | ||
protected readonly InputPriceLabelExtension $inputPriceLabelExtension, | ||
) { | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\Form\FormBuilderInterface $builder | ||
* @param array $options | ||
*/ | ||
#[Override] | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('price', MoneyType::class, [ | ||
'scale' => 6, | ||
'constraints' => [ | ||
new NotBlank(['message' => 'Please enter price']), | ||
], | ||
'label' => $this->inputPriceLabelExtension->getInputPriceLabel(), | ||
]) | ||
->add('maxWeight', IntegerType::class) | ||
->add('transportPriceId', HiddenType::class); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver | ||
*/ | ||
#[Override] | ||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver | ||
->setDefaults([ | ||
'data_class' => PriceWithLimitData::class, | ||
'attr' => ['novalidate' => 'novalidate'], | ||
]) | ||
->setRequired(['domain_id', 'current_transport_prices_indexed_by_id']) | ||
->setAllowedTypes('domain_id', 'int') | ||
->setAllowedTypes('current_transport_prices_indexed_by_id', 'array'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
#[Override] | ||
public function getParent(): string | ||
{ | ||
return FormType::class; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
#[Override] | ||
public function buildView(FormView $view, FormInterface $form, array $options): void | ||
{ | ||
$transportPriceId = (int)$form->get('transportPriceId')->getData(); | ||
$view->vars['domain_id'] = $options['domain_id']; | ||
$view->vars['transport_calculated_price'] = $options['current_transport_prices_indexed_by_id'][$transportPriceId] ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.