diff --git a/README.md b/README.md index 1af00c2..211b31b 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,83 @@ If you have defined your own admin controllers, make them extend EasyAdminExtens Features -------- +### List filters form + +Add filters on list views by configuration. + +Consider following Animation entity using such [ValueListTrait](https://github.com/alterphp/components/blob/master/src/AlterPHP/Component/Behavior/ValueListTrait) : + +```php +class Animation +{ + use ValueListTrait; + + /** + * @var string + * + * @ORM\Id + * @ORM\Column(type="guid") + */ + private $id; + + /** + * @var bool + * + * @ORM\Column(type="boolean", nullable=false) + */ + private $enabled; + + /** + * @var string + * + * @ORM\Column(type="string", length=31) + */ + protected $status; + + /** + * @var string + * + * @ORM\Column(type="string", length=31, nullable=false) + */ + private $type; + + /** + * @var Organization + * + * @ORM\ManyToOne(targetEntity="App\Entity\Organization", inversedBy="animations") + * @ORM\JoinColumn(nullable=false) + */ + private $organization; + + const STATUS_DRAFT = 'draft'; + const STATUS_PUBLISHED = 'published'; + const STATUS_OPEN = 'open'; + const STATUS_ACTIVE = 'active'; + const STATUS_CLOSED = 'closed'; + const STATUS_ARCHIVED = 'archived'; +} +``` + +Define your filters under `list`.`form_filters` entity configuration. Automatic guesser set up a ChoiceType for filters mapped on boolean (NULL, true, false) and string class properties. ChoiceType for string properties requires either a `choices` label/value array in `type_options` of a `choices_static_callback` static callable that returns label/value choices list. + + +```yaml +easy_admin: + entities: + Animation: + class: App\Entity\Animation + list: + form_filters: + - enabled + - { property: type, type_options: { choices: { Challenge: challenge, Event: event } } } + - { property: status, type_options: { choices_static_callback: [getValuesList, [status, true]] } } + - organization +``` + +Let's see the result ! + +![Embedded list example](/doc/res/img/list-form-filters.png) + ### Filter list and search on request parameters * EasyAdmin allows filtering list with `dql_filter` configuration entry. But this is not dynamic and must be configured as an apart list in `easy_admin` configuration.* diff --git a/doc/res/img/list-form-filters.png b/doc/res/img/list-form-filters.png new file mode 100644 index 0000000..8e1eb7b Binary files /dev/null and b/doc/res/img/list-form-filters.png differ diff --git a/src/Configuration/ListFormFiltersConfigPass.php b/src/Configuration/ListFormFiltersConfigPass.php new file mode 100644 index 0000000..5c6a735 --- /dev/null +++ b/src/Configuration/ListFormFiltersConfigPass.php @@ -0,0 +1,196 @@ +doctrine = $doctrine; + } + + /** + * @param array $backendConfig + * + * @return array + */ + public function process(array $backendConfig): array + { + if (!isset($backendConfig['entities'])) { + return $backendConfig; + } + + foreach ($backendConfig['entities'] as $entityName => $entityConfig) { + if (!isset($entityConfig['list']['form_filters'])) { + continue; + } + + $formFilters = array(); + + foreach ($entityConfig['list']['form_filters'] as $i => $formFilter) { + // Detects invalid config node + if (!is_string($formFilter) && !is_array($formFilter)) { + throw new \RuntimeException( + sprintf( + 'The values of the "form_filters" option for the list view of the "%s" entity can only be strings or arrays.', + $entityConfig['class'] + ) + ); + } + + // Key mapping + if (is_string($formFilter)) { + $filterConfig = array('property' => $formFilter); + } else { + if (!array_key_exists('property', $formFilter)) { + throw new \RuntimeException( + sprintf( + 'One of the values of the "form_filters" option for the "list" view of the "%s" entity does not define the mandatory option "property".', + $entityConfig['class'] + ) + ); + } + + $filterConfig = $formFilter; + } + + $this->configureFilter($entityConfig['class'], $filterConfig); + + // If type is not configured at this steps => not guessable + if (!isset($filterConfig['type'])) { + continue; + } + + $formFilters[$filterConfig['property']] = $filterConfig; + } + + // set form filters config and form ! + $backendConfig['entities'][$entityName]['list']['form_filters'] = $formFilters; + } + + return $backendConfig; + } + + private function configureFilter(string $entityClass, array &$filterConfig) + { + // No need to guess type + if (isset($filterConfig['type'])) { + return; + } + + $em = $this->doctrine->getManagerForClass($entityClass); + $entityMetadata = $em->getMetadataFactory()->getMetadataFor($entityClass); + + // Not able to guess type + if ( + !$entityMetadata->hasField($filterConfig['property']) + && !$entityMetadata->hasAssociation($filterConfig['property']) + ) { + return; + } + + if ($entityMetadata->hasField($filterConfig['property'])) { + $this->configureFieldFilter( + $entityClass, $entityMetadata->getFieldMapping($filterConfig['property']), $filterConfig + ); + } elseif ($entityMetadata->hasAssociation($filterConfig['property'])) { + $this->configureAssociationFilter( + $entityClass, $entityMetadata->getAssociationMapping($filterConfig['property']), $filterConfig + ); + } + } + + private function configureFieldFilter(string $entityClass, array $fieldMapping, array &$filterConfig) + { + switch ($fieldMapping['type']) { + case 'boolean': + $filterConfig['type'] = ChoiceType::class; + $defaultFilterConfigTypeOptions = array( + 'choices' => array( + 'list_form_filters.default.boolean.true' => true, + 'list_form_filters.default.boolean.false' => false, + ), + 'choice_translation_domain' => 'EasyAdminBundle', + ); + break; + case 'string': + $filterConfig['type'] = ChoiceType::class; + $defaultFilterConfigTypeOptions = array( + 'multiple' => true, + 'choices' => $this->getChoiceList($entityClass, $filterConfig['property'], $filterConfig), + 'attr' => array('data-widget' => 'select2'), + ); + break; + default: + return; + } + + // Merge default type options when defined + if (isset($defaultFilterConfigTypeOptions)) { + $filterConfig['type_options'] = array_merge( + $defaultFilterConfigTypeOptions, + isset($filterConfig['type_options']) ? $filterConfig['type_options'] : array() + ); + } + } + + private function configureAssociationFilter(string $entityClass, array $associationMapping, array &$filterConfig) + { + // To-One (EasyAdminAutocompleteType) + if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { + $filterConfig['type'] = EasyAdminAutocompleteType::class; + $filterConfig['type_options'] = array_merge( + array( + 'class' => $associationMapping['targetEntity'], + 'multiple' => true, + 'attr' => array('data-widget' => 'select2'), + ), + isset($filterConfig['type_options']) ? $filterConfig['type_options'] : array() + ); + } + } + + private function getChoiceList(string $entityClass, string $property, array &$filterConfig) + { + if (isset($filterConfig['type_options']['choices'])) { + $choices = $filterConfig['type_options']['choices']; + unset($filterConfig['type_options']['choices']); + + return $choices; + } + + if (!isset($filterConfig['type_options']['choices_static_callback'])) { + throw new \RuntimeException( + sprintf( + 'Choice filter field "%s" for entity "%s" must provide either a static callback method returning choice list or choices option.', + $property, + $entityClass + ) + ); + } + + $callableParams = array(); + if (is_string($filterConfig['type_options']['choices_static_callback'])) { + $callable = array($entityClass, $filterConfig['type_options']['choices_static_callback']); + } else { + $callable = array($entityClass, $filterConfig['type_options']['choices_static_callback'][0]); + $callableParams = $filterConfig['type_options']['choices_static_callback'][1]; + } + unset($filterConfig['type_options']['choices_static_callback']); + + return forward_static_call_array($callable, $callableParams); + } +} diff --git a/src/EventListener/PostQueryBuilderSubscriber.php b/src/EventListener/PostQueryBuilderSubscriber.php index 18f4c3f..ea5da94 100644 --- a/src/EventListener/PostQueryBuilderSubscriber.php +++ b/src/EventListener/PostQueryBuilderSubscriber.php @@ -35,6 +35,7 @@ public function onPostListQueryBuilder(GenericEvent $event) if ($event->hasArgument('request')) { $this->applyRequestFilters($queryBuilder, $event->getArgument('request')->get('filters', array())); + $this->applyFormFilters($queryBuilder, $event->getArgument('request')->get('form_filters', array())); } } @@ -53,7 +54,7 @@ public function onPostSearchQueryBuilder(GenericEvent $event) } /** - * Applies filters on queryBuilder. + * Applies request filters on queryBuilder. * * @param QueryBuilder $queryBuilder * @param array $filters @@ -72,12 +73,48 @@ protected function applyRequestFilters(QueryBuilder $queryBuilder, array $filter continue; } // Sanitize parameter name - $parameter = 'filter_'.str_replace('.', '_', $field); + $parameter = 'request_filter_'.str_replace('.', '_', $field); $this->filterQueryBuilder($queryBuilder, $field, $parameter, $value); } } + /** + * Applies form filters on queryBuilder. + * + * @param QueryBuilder $queryBuilder + * @param array $filters + */ + protected function applyFormFilters(QueryBuilder $queryBuilder, array $filters = array()) + { + foreach ($filters as $field => $value) { + $value = $this->filterEasyadminAutocompleteValue($value); + // Empty string and numeric keys is considered as "not applied filter" + if (is_int($field) || '' === $value) { + continue; + } + // Add root entity alias if none provided + $field = false === strpos($field, '.') ? $queryBuilder->getRootAlias().'.'.$field : $field; + // Checks if filter is directly appliable on queryBuilder + if (!$this->isFilterAppliable($queryBuilder, $field)) { + continue; + } + // Sanitize parameter name + $parameter = 'form_filter_'.str_replace('.', '_', $field); + + $this->filterQueryBuilder($queryBuilder, $field, $parameter, $value); + } + } + + private function filterEasyadminAutocompleteValue($value) + { + if (!is_array($value) || !isset($value['autocomplete']) || 1 !== count($value)) { + return $value; + } + + return $value['autocomplete']; + } + /** * Filters queryBuilder. * diff --git a/src/Helper/ListFormFiltersHelper.php b/src/Helper/ListFormFiltersHelper.php new file mode 100644 index 0000000..f16ebff --- /dev/null +++ b/src/Helper/ListFormFiltersHelper.php @@ -0,0 +1,62 @@ +formFactory = $formFactory; + $this->requestStack = $requestStack; + } + + public function getListFiltersForm(array $formFilters): FormInterface + { + if (!isset($this->listFiltersForm)) { + $formBuilder = $this->formFactory->createNamedBuilder('form_filters'); + + foreach ($formFilters as $name => $config) { + $formBuilder->add( + $name, + isset($config['type']) ? $config['type'] : null, + array_merge( + array('required' => false), + $config['type_options'] + ) + ); + } + + $this->listFiltersForm = $formBuilder->setMethod('GET')->getForm(); + $this->listFiltersForm->handleRequest($this->requestStack->getCurrentRequest()); + } + + return $this->listFiltersForm; + } +} diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index ed3270c..131bdb1 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -34,6 +34,20 @@ + + + + + + + + + + + + + + diff --git a/src/Resources/public/js/easyadmin-extension.js b/src/Resources/public/js/easyadmin-extension.js index eb8a050..e355df3 100644 --- a/src/Resources/public/js/easyadmin-extension.js +++ b/src/Resources/public/js/easyadmin-extension.js @@ -75,4 +75,13 @@ $(function() { $('#modal-confirm').modal({ backdrop: true, keyboard: true }); }); + + // Deal with panel-heading toggling collapsible panel-body + // (@see https://stackoverflow.com/questions/33725181/bootstrap-using-panel-heading-to-collapse-panel-body) + $('.panel-heading[data-toggle^="collapse"]').click(function(){ + var target = $(this).attr('data-target'); + $(target).collapse('toggle'); + }).children().click(function(e) { + e.stopPropagation(); + }); }); diff --git a/src/Resources/public/stylesheet/easyadmin-extension.css b/src/Resources/public/stylesheet/easyadmin-extension.css new file mode 100644 index 0000000..a206186 --- /dev/null +++ b/src/Resources/public/stylesheet/easyadmin-extension.css @@ -0,0 +1,3 @@ +#list-form-filters { + margin: 10px 0; +} diff --git a/src/Resources/translations/EasyAdminBundle.en.xlf b/src/Resources/translations/EasyAdminBundle.en.xlf index 90f48ed..957c082 100644 --- a/src/Resources/translations/EasyAdminBundle.en.xlf +++ b/src/Resources/translations/EasyAdminBundle.en.xlf @@ -7,7 +7,27 @@ open.new_tab Open in a new tab - + + + list_form_filters.heading_title + Filters + + + list_form_filters.heading_expandcollapse + Expand / Collapse + + + list_form_filters.submit + Filter + + + list_form_filters.default.boolean.true + Yes + + + list_form_filters.default.boolean.false + No + confirm_modal.content diff --git a/src/Resources/translations/EasyAdminBundle.es.xlf b/src/Resources/translations/EasyAdminBundle.es.xlf index 6e778d8..60b1ce6 100644 --- a/src/Resources/translations/EasyAdminBundle.es.xlf +++ b/src/Resources/translations/EasyAdminBundle.es.xlf @@ -7,7 +7,27 @@ open.new_tab Abrir en una nueva pestaña - + + + list_form_filters.heading_title + Filtros + + + list_form_filters.heading_expandcollapse + Abrir / Cerrar + + + list_form_filters.submit + Filtro + + + list_form_filters.default.boolean.true + Si + + + list_form_filters.default.boolean.false + No + confirm_modal.content diff --git a/src/Resources/translations/EasyAdminBundle.fr.xlf b/src/Resources/translations/EasyAdminBundle.fr.xlf index d4691ce..71438e7 100644 --- a/src/Resources/translations/EasyAdminBundle.fr.xlf +++ b/src/Resources/translations/EasyAdminBundle.fr.xlf @@ -2,13 +2,33 @@ - + open.new_tab Ouvrir dans un nouvel onglet - - + + + list_form_filters.heading_title + Filtres + + + list_form_filters.heading_expandcollapse + Ouvrir / Fermer + + + list_form_filters.submit + Filtrer + + + list_form_filters.default.boolean.true + Oui + + + list_form_filters.default.boolean.false + Non + + confirm_modal.content Êtes-vous sûr(e) ? diff --git a/src/Resources/translations/EasyAdminBundle.hu.xlf b/src/Resources/translations/EasyAdminBundle.hu.xlf index 445478e..93fa99e 100644 --- a/src/Resources/translations/EasyAdminBundle.hu.xlf +++ b/src/Resources/translations/EasyAdminBundle.hu.xlf @@ -7,7 +7,27 @@ open.new_tab Megnyitás új lapon - + + + list_form_filters.heading_title + Szűrők + + + list_form_filters.heading_expandcollapse + Nyitás / Bezárás + + + list_form_filters.submit + Szűrő + + + list_form_filters.default.boolean.true + Igen + + + list_form_filters.default.boolean.false + Nem + confirm_modal.content diff --git a/src/Resources/translations/EasyAdminBundle.it.xlf b/src/Resources/translations/EasyAdminBundle.it.xlf index 800c2a0..4ba80ec 100644 --- a/src/Resources/translations/EasyAdminBundle.it.xlf +++ b/src/Resources/translations/EasyAdminBundle.it.xlf @@ -7,7 +7,27 @@ open.new_tab Apri in una nuova scheda - + + + list_form_filters.heading_title + Filtri + + + list_form_filters.heading_expandcollapse + Apri / Chiudi + + + list_form_filters.submit + Filtro + + + list_form_filters.default.boolean.true + Si + + + list_form_filters.default.boolean.false + Non + confirm_modal.content diff --git a/src/Resources/views/default/layout.html.twig b/src/Resources/views/default/layout.html.twig index fee9a10..e9307e5 100644 --- a/src/Resources/views/default/layout.html.twig +++ b/src/Resources/views/default/layout.html.twig @@ -1,5 +1,10 @@ {% extends '@BaseEasyAdmin/default/layout.html.twig' %} +{% block head_stylesheets %} + {{ parent() }} + +{% endblock %} + {% block head_javascript %} {{ parent() }} diff --git a/src/Resources/views/default/list.html.twig b/src/Resources/views/default/list.html.twig index 54044f7..e81e84b 100644 --- a/src/Resources/views/default/list.html.twig +++ b/src/Resources/views/default/list.html.twig @@ -5,6 +5,18 @@ filters: requestFilters }) %} +{% block request_parameters_as_hidden %} + {% for field, value in requestFilters %} + {% if value is iterable %} + {% for val in value %} + + {% endfor %} + {% else %} + + {% endif %} + {% endfor %} +{% endblock %} + {% block content_title_wrapper %}

{{ block('content_title') }} @@ -46,16 +58,62 @@ {{ parent() }} {% endblock %} -{# Adds request filters to the serach form #} +{# Adds request filters to the search form #} {% block search_form %} - {% for field, value in requestFilters %} - {% if value is iterable %} - {% for val in value %} - - {% endfor %} - {% else %} - - {% endif %} - {% endfor %} + {{ block('request_parameters_as_hidden') }} + {{ parent() }} +{% endblock %} + +{% block list_form_filters %} + {% if _entity_config.list.form_filters is defined and _entity_config.list.form_filters is not empty %} + {% set list_form_filters = list_form_filters(_entity_config.list.form_filters) %} +
+
+ {{ 'list_form_filters.heading_title'|trans(_trans_parameters, 'EasyAdminBundle') }} + + {{ 'list_form_filters.heading_expandcollapse'|trans(_trans_parameters, 'EasyAdminBundle') }} + +
+
+
+
+ {% form_theme list_form_filters '@EasyAdmin/form/bootstrap_3_layout.html.twig' %} + {{ block('request_parameters_as_hidden') }} + + + + + + + {% for field in list_form_filters %} +
{{ form_row(field) }}
+ {% endfor %} +
+
+
+ +
+
+
+
+
+ {% endif %} +{% endblock %} + +{# Display FILTERS form if defined #} +{% block main %} + {{ block('list_form_filters') }} + {{ parent() }} +{% endblock %} + +{% block body_javascript %} {{ parent() }} + {{ include('@EasyAdmin/default/includes/_select2_widget.html.twig') }} + {% endblock %} diff --git a/src/Twig/ListFormFiltersExtension.php b/src/Twig/ListFormFiltersExtension.php new file mode 100644 index 0000000..05b349d --- /dev/null +++ b/src/Twig/ListFormFiltersExtension.php @@ -0,0 +1,28 @@ +listFiltersHelper = $listFiltersHelper; + } + + public function getFunctions() + { + return array( + new TwigFunction('list_form_filters', array($this, 'getListFormFilters')), + ); + } + + public function getListFormFilters(array $filters) + { + return $this->listFiltersHelper->getListFiltersForm($filters)->createView(); + } +} diff --git a/tests/Controller/ListFormFiltersTest.php b/tests/Controller/ListFormFiltersTest.php new file mode 100644 index 0000000..9707726 --- /dev/null +++ b/tests/Controller/ListFormFiltersTest.php @@ -0,0 +1,41 @@ +initClient(array('environment' => 'list_form_filters')); + } + + public function testListFiltersAreDisplaid() + { + $crawler = $this->requestListView('Product'); + + $listFormFiltersCrawler = $crawler->filter('#list-form-filters'); + + $this->assertSame(1, $listFormFiltersCrawler->filter('select#form_filters_oddEven[multiple]')->count()); + $this->assertSame(1, $listFormFiltersCrawler->filter('select#form_filters_category_autocomplete[multiple]')->count()); + $this->assertSame(1, $listFormFiltersCrawler->filter('select#form_filters_replenishmentType[multiple]')->count()); + $this->assertSame(1, $listFormFiltersCrawler->filter('select#form_filters_enabled')->count()); + } + + public function testFormSingleFilterIsApplied() + { + $crawler = $this->requestListView('Product', array(), array('enabled' => false)); + + $this->assertSame(10, $crawler->filter('#main tr[data-id]')->count()); + } + + public function testFormSingleEasyadminAutocomplteFilterIsApplied() + { + $crawler = $this->requestListView('Product', array(), array('category' => array('autocomplete' => 1))); + + $this->assertSame(10, $crawler->filter('#main tr[data-id]')->count()); + } +} diff --git a/tests/Fixtures/AbstractTestCase.php b/tests/Fixtures/AbstractTestCase.php index 07075ff..d98e4aa 100644 --- a/tests/Fixtures/AbstractTestCase.php +++ b/tests/Fixtures/AbstractTestCase.php @@ -75,13 +75,14 @@ protected function getBackendHomepage() /** * @return Crawler */ - protected function requestListView($entityName = 'Category', array $requestFilters = array()) + protected function requestListView($entityName = 'Category', array $requestFilters = array(), array $formFilters = array()) { return $this->getBackendPage(array( 'action' => 'list', 'entity' => $entityName, 'view' => 'list', 'filters' => $requestFilters, + 'form_filters' => $formFilters, )); } diff --git a/tests/Fixtures/App/config/config_list_form_filters.yml b/tests/Fixtures/App/config/config_list_form_filters.yml new file mode 100644 index 0000000..f74e024 --- /dev/null +++ b/tests/Fixtures/App/config/config_list_form_filters.yml @@ -0,0 +1,15 @@ +imports: + - { resource: config.yml } + +easy_admin: + entities: + Category: + class: AppTestBundle\Entity\FunctionalTests\Category + Product: + class: AppTestBundle\Entity\FunctionalTests\Product + list: + form_filters: + - { property: oddEven, type_options: { choices: {Odd: odd, Even: even} } } + - { property: replenishmentType, type_options: { choices_static_callback: [getReplenishmentTypeValues, [true]] } } + - enabled + - category diff --git a/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadProducts.php b/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadProducts.php index b915876..2bec0cb 100644 --- a/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadProducts.php +++ b/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadProducts.php @@ -46,15 +46,17 @@ public function getOrder() public function load(ObjectManager $manager) { foreach (range(1, 100) as $i) { + $category = $i <= 10 ? $this->getReference('category-1') : $this->getRandomCategory(); $product = new Product(); - $product->setEnabled($i <= 90 ? true : false); - $product->setOddEven($i % 2 ? 'odd' : 'even'); + $product->setEnabled($i % 10 ? true : false); + $product->setOddEven($i % 4 ? 'odd' : 'even'); $product->setReference('ref'.str_pad($i, 6, '0', STR_PAD_LEFT)); $product->setName($this->getRandomName()); + $product->setReplenishmentType($this->getReplenishmentType()); $product->setPrice($this->getRandomPrice()); $product->setTags($this->getRandomTags()); $product->setEan($this->getRandomEan()); - $product->setCategory($this->getRandomCategory()); + $product->setCategory($category); $product->setDescription($this->getRandomDescription()); $product->setHtmlFeatures($this->getRandomHtmlFeatures()); $product->setPhone($i <= 10 ? null : '0123456789'); @@ -134,7 +136,8 @@ public function getRandomPrice() private function getRandomCategory() { - return $this->getReference('category-'.mt_rand(1, 100)); + // First category is reserved for first products (test purpose) + return $this->getReference('category-'.mt_rand(2, 100)); } public function getRandomDescription() @@ -152,4 +155,11 @@ public function getRandomHtmlFeatures() return '
  • '.implode('
  • ', array_slice($this->phrases, 0, $numFeatures)).'
'; } + + public function getReplenishmentType() + { + $replenishmentTypeValues = Product::getReplenishmentTypeValues(); + + return $replenishmentTypeValues[mt_rand(0, count($replenishmentTypeValues)-1)]; + } } diff --git a/tests/Fixtures/AppTestBundle/Entity/FunctionalTests/Product.php b/tests/Fixtures/AppTestBundle/Entity/FunctionalTests/Product.php index 25221f0..71e64a2 100644 --- a/tests/Fixtures/AppTestBundle/Entity/FunctionalTests/Product.php +++ b/tests/Fixtures/AppTestBundle/Entity/FunctionalTests/Product.php @@ -119,6 +119,14 @@ class Product */ protected $name; + /** + * The replenishment type of the product. + * + * @var string + * @ORM\Column(type="string") + */ + protected $replenishmentType; + /** * The description of the product. * @@ -150,6 +158,21 @@ class Product */ protected $phone; + public static function getReplenishmentTypeValues($withLabelsAsIndexes = false) + { + $replenishmentTypeValues = array( + 'replenishment_type.auto' => 'auto', + 'replenishment_type.trigger' => 'trigger', + 'replenishment_type.manual' => 'manual', + ); + + if (!$withLabelsAsIndexes) { + return array_values($replenishmentTypeValues); + } + + return $replenishmentTypeValues; + } + /** * Constructor of the Product class. * (Initialize some fields). @@ -303,6 +326,26 @@ public function getHtmlFeatures() return $this->htmlFeatures; } + /** + * Set replenishment type. + * + * @param string $replenishmentType + */ + public function setReplenishmentType($replenishmentType) + { + $this->replenishmentType = $replenishmentType; + } + + /** + * Get replenishment type. + * + * @return string + */ + public function getReplenishmentType() + { + return $this->replenishmentType; + } + /** * Set the product image. *