1<?php 2/** 3 * Copyright since 2007 PrestaShop SA and Contributors 4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA 5 * 6 * NOTICE OF LICENSE 7 * 8 * This source file is subject to the Open Software License (OSL 3.0) 9 * that is bundled with this package in the file LICENSE.md. 10 * It is also available through the world-wide-web at this URL: 11 * https://opensource.org/licenses/OSL-3.0 12 * If you did not receive a copy of the license and are unable to 13 * obtain it through the world-wide-web, please send an email 14 * to license@prestashop.com so we can send you a copy immediately. 15 * 16 * DISCLAIMER 17 * 18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer 19 * versions in the future. If you wish to customize PrestaShop for your 20 * needs please refer to https://devdocs.prestashop.com/ for more information. 21 * 22 * @author PrestaShop SA and Contributors <contact@prestashop.com> 23 * @copyright Since 2007 PrestaShop SA and Contributors 24 * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) 25 */ 26 27namespace PrestaShopBundle\Form\Admin\Product; 28 29use PrestaShop\PrestaShop\Adapter\Configuration; 30use PrestaShopBundle\Form\Admin\Type\CommonAbstractType; 31use PrestaShopBundle\Form\Admin\Type\DatePickerType; 32use Symfony\Component\Form\Extension\Core\Type\CheckboxType; 33use Symfony\Component\Form\Extension\Core\Type\MoneyType; 34use Symfony\Component\Form\Extension\Core\Type\NumberType; 35use Symfony\Component\Form\Extension\Core\Type\TextType; 36use Symfony\Component\Form\FormBuilderInterface; 37use Symfony\Component\OptionsResolver\OptionsResolver; 38use Symfony\Component\Translation\TranslatorInterface; 39 40/** 41 * This form class is responsible to generate the form for bulk combination feature 42 * Note this form is not validated from the server side. 43 */ 44class ProductCombinationBulk extends CommonAbstractType 45{ 46 private $isoCode; 47 private $translator; 48 private $configuration; 49 50 public function __construct(TranslatorInterface $translator, Configuration $configuration) 51 { 52 $this->translator = $translator; 53 $this->configuration = $configuration; 54 } 55 56 public function buildForm(FormBuilderInterface $builder, array $options) 57 { 58 $is_stock_management = $this->configuration->get('PS_STOCK_MANAGEMENT'); 59 $this->isoCode = $options['iso_code']; 60 61 if ($is_stock_management) { 62 $builder->add('quantity', NumberType::class, [ 63 'required' => true, 64 'label' => $this->translator->trans('Quantity', [], 'Admin.Catalog.Feature'), 65 ]); 66 } 67 68 $builder->add('cost_price', MoneyType::class, [ 69 'required' => false, 70 'label' => $this->translator->trans('Cost Price', [], 'Admin.Catalog.Feature'), 71 'attr' => ['data-display-price-precision' => self::PRESTASHOP_DECIMALS], 72 'currency' => $this->isoCode, 73 ]) 74 ->add('impact_on_weight', NumberType::class, [ 75 'required' => false, 76 'label' => $this->translator->trans('Impact on weight', [], 'Admin.Catalog.Feature'), 77 ]) 78 ->add('impact_on_price_te', MoneyType::class, [ 79 'required' => false, 80 'label' => $this->translator->trans('Impact on price (tax excl.)', [], 'Admin.Catalog.Feature'), 81 'currency' => $this->isoCode, 82 ]) 83 ->add('impact_on_price_ti', MoneyType::class, [ 84 'required' => false, 85 'mapped' => false, 86 'label' => $this->translator->trans('Impact on price (tax incl.)', [], 'Admin.Catalog.Feature'), 87 'currency' => $this->isoCode, 88 ]) 89 ->add('date_availability', DatePickerType::class, [ 90 'required' => false, 91 'label' => $this->translator->trans('Availability date', [], 'Admin.Catalog.Feature'), 92 'attr' => ['class' => 'date', 'placeholder' => 'YYYY-MM-DD'], 93 ]) 94 ->add('reference', TextType::class, [ 95 'required' => false, 96 'label' => $this->translator->trans('Reference', [], 'Admin.Catalog.Feature'), 97 'empty_data' => '', 98 ]) 99 ->add('minimal_quantity', NumberType::class, [ 100 'required' => false, 101 'label' => $this->translator->trans('Minimum quantity', [], 'Admin.Catalog.Feature'), 102 ]) 103 ->add('low_stock_threshold', NumberType::class, [ 104 'required' => false, 105 'label' => $this->translator->trans('Low stock level', [], 'Admin.Catalog.Feature'), 106 ]) 107 ->add('low_stock_alert', CheckboxType::class, [ 108 'required' => false, 109 'label' => $this->translator->trans('Send me an email when the quantity is below or equals this level', [], 'Admin.Catalog.Feature'), 110 ]); 111 } 112 113 public function configureOptions(OptionsResolver $resolver) 114 { 115 $resolver->setDefaults([ 116 'validation_groups' => false, 117 'iso_code' => '', 118 ]); 119 } 120 121 public function getBlockPrefix() 122 { 123 return 'product_combination_bulk'; 124 } 125} 126