123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\SalesRule\Model\Rule\Metadata;
- use Magento\SalesRule\Model\Rule;
- use Magento\Store\Model\System\Store;
- use Magento\Customer\Api\GroupRepositoryInterface;
- use Magento\Framework\Api\SearchCriteriaBuilder;
- use Magento\Framework\Convert\DataObject;
- /**
- * Metadata provider for sales rule edit form.
- */
- class ValueProvider
- {
- /**
- * @var Store
- */
- protected $store;
- /**
- * @var GroupRepositoryInterface
- */
- protected $groupRepository;
- /**
- * @var SearchCriteriaBuilder
- */
- protected $searchCriteriaBuilder;
- /**
- * @var DataObject
- */
- protected $objectConverter;
- /**
- * @var \Magento\SalesRule\Model\RuleFactory
- */
- protected $salesRuleFactory;
- /**
- * Initialize dependencies.
- *
- * @param Store $store
- * @param GroupRepositoryInterface $groupRepository
- * @param SearchCriteriaBuilder $searchCriteriaBuilder
- * @param DataObject $objectConverter
- * @param \Magento\SalesRule\Model\RuleFactory $salesRuleFactory
- */
- public function __construct(
- Store $store,
- GroupRepositoryInterface $groupRepository,
- SearchCriteriaBuilder $searchCriteriaBuilder,
- DataObject $objectConverter,
- \Magento\SalesRule\Model\RuleFactory $salesRuleFactory
- ) {
- $this->store = $store;
- $this->groupRepository = $groupRepository;
- $this->searchCriteriaBuilder = $searchCriteriaBuilder;
- $this->objectConverter = $objectConverter;
- $this->salesRuleFactory = $salesRuleFactory;
- }
- /**
- * Get metadata for sales rule form. It will be merged with form UI component declaration.
- *
- * @param Rule $rule
- * @return array
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function getMetadataValues(\Magento\SalesRule\Model\Rule $rule)
- {
- $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
- $applyOptions = [
- ['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION],
- ['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION],
- ['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION],
- ['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]
- ];
- $couponTypesOptions = [];
- $couponTypes = $this->salesRuleFactory->create()->getCouponTypes();
- foreach ($couponTypes as $key => $couponType) {
- $couponTypesOptions[] = [
- 'label' => $couponType,
- 'value' => $key,
- ];
- }
- $labels = $rule->getStoreLabels();
- return [
- 'rule_information' => [
- 'children' => [
- 'website_ids' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'options' => $this->store->getWebsiteValuesForForm(),
- ],
- ],
- ],
- ],
- 'is_active' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'options' => [
- ['label' => __('Active'), 'value' => '1'],
- ['label' => __('Inactive'), 'value' => '0']
- ],
- ],
- ],
- ],
- ],
- 'customer_group_ids' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'options' => $this->objectConverter->toOptionArray($customerGroups, 'id', 'code'),
- ],
- ],
- ],
- ],
- 'coupon_type' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'options' => $couponTypesOptions,
- ],
- ],
- ],
- ],
- 'is_rss' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'options' => [
- ['label' => __('Yes'), 'value' => '1'],
- ['label' => __('No'), 'value' => '0']
- ],
- ],
- ],
- ],
- ],
- ]
- ],
- 'actions' => [
- 'children' => [
- 'simple_action' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'options' => $applyOptions
- ],
- ]
- ]
- ],
- 'discount_amount' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'value' => '0',
- ],
- ],
- ],
- ],
- 'discount_qty' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'value' => '0',
- ],
- ],
- ],
- ],
- 'apply_to_shipping' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'options' => [
- ['label' => __('Yes'), 'value' => '1'],
- ['label' => __('No'), 'value' => '0']
- ]
- ],
- ],
- ],
- ],
- 'stop_rules_processing' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'options' => [
- ['label' => __('Yes'), 'value' => '1'],
- ['label' => __('No'), 'value' => '0'],
- ],
- ],
- ]
- ]
- ],
- ]
- ],
- 'labels' => [
- 'children' => [
- 'store_labels[0]' => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'value' => isset($labels[0]) ? $labels[0] : '',
- ],
- ]
- ]
- ]
- ]
- ],
- ];
- }
- }
|