/**
  * {@inheritdoc}
  */
 public function modifyMeta(array $meta)
 {
     if ($groupCode = $this->getGroupCodeByField($meta, ProductAttributeInterface::CODE_SKU)) {
         $skuPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_SKU);
         $meta[$groupCode]['children'][self::CODE_SKU_TYPE] = ['arguments' => ['data' => ['config' => ['sortOrder' => $this->getNextAttributeSortOrder($meta, [ProductAttributeInterface::CODE_SKU], self::SORT_ORDER), 'formElement' => Form\Element\Checkbox::NAME, 'componentType' => Form\Field::NAME, 'dataType' => Form\Element\DataType\Number::NAME, 'label' => __('Dynamic SKU'), 'prefer' => 'toggle', 'additionalClasses' => 'admin__field-x-small', 'templates' => ['checkbox' => 'ui/form/components/single/switcher'], 'valueMap' => ['false' => '1', 'true' => '0'], 'dataScope' => self::CODE_SKU_TYPE, 'value' => '0', 'scopeLabel' => $this->arrayManager->get($skuPath . '/scopeLabel', $meta)]]]];
     }
     return $meta;
 }
 /**
  * {@inheritdoc}
  */
 public function modifyMeta(array $meta)
 {
     if ($groupCode = $this->getGroupCodeByField($meta, ProductAttributeInterface::CODE_WEIGHT) ?: $this->getGroupCodeByField($meta, self::CODE_CONTAINER_WEIGHT)) {
         $weightPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_WEIGHT) ?: $this->getElementArrayPath($meta, self::CODE_CONTAINER_WEIGHT);
         $meta[$groupCode]['children'][self::CODE_WEIGHT_TYPE] = ['arguments' => ['data' => ['config' => ['sortOrder' => $this->getNextAttributeSortOrder($meta, [self::CODE_CONTAINER_WEIGHT], self::SORT_ORDER), 'formElement' => Form\Element\Checkbox::NAME, 'componentType' => Form\Field::NAME, 'dataType' => Form\Element\DataType\Number::NAME, 'label' => __('Dynamic Weight'), 'prefer' => 'toggle', 'additionalClasses' => 'admin__field-x-small', 'templates' => ['checkbox' => 'ui/form/components/single/switcher'], 'valueMap' => ['false' => '1', 'true' => '0'], 'dataScope' => self::CODE_WEIGHT_TYPE, 'value' => '0', 'scopeLabel' => $this->arrayManager->get($weightPath . '/scopeLabel', $meta)]]]];
         $meta[$groupCode]['children'][self::CODE_CONTAINER_WEIGHT] = array_replace_recursive($meta[$groupCode]['children'][self::CODE_CONTAINER_WEIGHT], ['children' => [ProductAttributeInterface::CODE_HAS_WEIGHT => ['arguments' => ['data' => ['config' => ['disabled' => true, 'visible' => false]]]]]]);
         $meta[$groupCode]['children'][self::CODE_CONTAINER_WEIGHT] = array_replace_recursive($meta[$groupCode]['children'][self::CODE_CONTAINER_WEIGHT], ['children' => [ProductAttributeInterface::CODE_WEIGHT => ['arguments' => ['data' => ['config' => ['imports' => ['disabled' => 'ns = ${ $.ns }, index = ' . self::CODE_WEIGHT_TYPE . ':checked']]]]]]]);
     }
     return $meta;
 }
示例#3
0
 /**
  * Add warning over options grid
  *
  * @param array $meta
  * @return array
  */
 private function addPriceTypeWarning(array $meta)
 {
     $gridPath = $this->arrayManager->findPath(CustomOptionsModifier::GRID_OPTIONS_NAME, $meta, CustomOptionsModifier::GROUP_CUSTOM_OPTIONS_NAME . '/children', 'children');
     if ($gridPath) {
         $path = $this->arrayManager->slicePath($gridPath, 0, -1) . '/' . static::WARNING_PRICE_TYPE;
         $sortOrder = $this->arrayManager->get($gridPath . static::META_CONFIG_PATH . '/sortOrder', $meta) - 1;
         $isConfigurable = $this->locator->getProduct()->getTypeId() === ConfigurableProductType::TYPE_CODE;
         $meta = $this->arrayManager->set($path . static::META_CONFIG_PATH, $meta, ['componentType' => Container::NAME, 'component' => 'Magento_ConfigurableProduct/js/components/custom-options-warning', 'additionalClasses' => 'message message-warning', 'sortOrder' => $sortOrder, 'isConfigurable' => $isConfigurable, 'content' => __('Custom options with price type "percent" is not available for configurable product.'), 'imports' => ['updateVisibility' => 'ns = ${ $.ns }, index = ' . ConfigurablePanel::CONFIGURABLE_MATRIX . ':isEmpty']]);
     }
     return $meta;
 }
示例#4
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function modifyMeta(array $meta)
 {
     $path = $this->arrayManager->findPath(static::CODE_BUNDLE_DATA, $meta, null, 'children');
     $meta = $this->arrayManager->merge($path, $meta, ['arguments' => ['data' => ['config' => ['dataScope' => '', 'opened' => true, 'sortOrder' => $this->getNextGroupSortOrder($meta, static::GROUP_CONTENT, static::SORT_ORDER)]]], 'children' => ['modal' => ['arguments' => ['data' => ['config' => ['isTemplate' => false, 'componentType' => Modal::NAME, 'dataScope' => '', 'provider' => 'product_form.product_form_data_source', 'options' => ['title' => __('Add Products to Option'), 'buttons' => [['text' => __('Cancel'), 'actions' => ['closeModal']], ['text' => __('Add Selected Products'), 'class' => 'action-primary', 'actions' => [['targetName' => 'index = bundle_product_listing', 'actionName' => 'save'], 'closeModal']]]]]]], 'children' => ['bundle_product_listing' => ['arguments' => ['data' => ['config' => ['autoRender' => false, 'componentType' => 'insertListing', 'dataScope' => 'bundle_product_listing', 'externalProvider' => 'bundle_product_listing.bundle_product_listing_data_source', 'selectionsProvider' => 'bundle_product_listing.bundle_product_listing.product_columns.ids', 'ns' => 'bundle_product_listing', 'render_url' => $this->urlBuilder->getUrl('mui/index/render'), 'realTimeLink' => false, 'dataLinks' => ['imports' => false, 'exports' => true], 'behaviourType' => 'simple', 'externalFilterMode' => true]]]]]], self::CODE_AFFECT_BUNDLE_PRODUCT_SELECTIONS => ['arguments' => ['data' => ['config' => ['componentType' => Form\Field::NAME, 'dataType' => Form\Element\DataType\Text::NAME, 'formElement' => Form\Element\Input::NAME, 'dataScope' => 'data.affect_bundle_product_selections', 'visible' => false, 'value' => '1']]]], self::CODE_BUNDLE_HEADER => $this->getBundleHeader(), self::CODE_BUNDLE_OPTIONS => $this->getBundleOptions()]]);
     //TODO: Remove this workaround after MAGETWO-49902 is fixed
     $bundleItemsGroup = $this->arrayManager->get($path, $meta);
     $meta = $this->arrayManager->remove($path, $meta);
     $meta = $this->arrayManager->set($path, $meta, $bundleItemsGroup);
     $meta = $this->modifyShipmentType($meta);
     return $meta;
 }
 /**
  * Customization of allow gift message field
  *
  * @param array $meta
  * @return array
  */
 protected function customizeAllowGiftMessageField(array $meta)
 {
     $groupCode = $this->getGroupCodeByField($meta, 'container_' . static::FIELD_MESSAGE_AVAILABLE);
     if (!$groupCode) {
         return $meta;
     }
     $containerPath = $this->getElementArrayPath($meta, 'container_' . static::FIELD_MESSAGE_AVAILABLE);
     $fieldPath = $this->getElementArrayPath($meta, static::FIELD_MESSAGE_AVAILABLE);
     $groupConfig = $this->arrayManager->get($containerPath, $meta);
     $fieldConfig = $this->arrayManager->get($fieldPath, $meta);
     $meta = $this->arrayManager->merge($containerPath, $meta, ['arguments' => ['data' => ['config' => ['formElement' => 'container', 'componentType' => 'container', 'component' => 'Magento_Ui/js/form/components/group', 'label' => $groupConfig['arguments']['data']['config']['label'], 'breakLine' => false, 'sortOrder' => $fieldConfig['arguments']['data']['config']['sortOrder'], 'dataScope' => '']]]]);
     $meta = $this->arrayManager->merge($containerPath, $meta, ['children' => [static::FIELD_MESSAGE_AVAILABLE => ['arguments' => ['data' => ['config' => ['dataScope' => static::FIELD_MESSAGE_AVAILABLE, 'imports' => ['disabled' => '${$.parentName}.use_config_' . static::FIELD_MESSAGE_AVAILABLE . ':checked'], 'additionalClasses' => 'admin__field-x-small', 'formElement' => Checkbox::NAME, 'componentType' => Field::NAME, 'prefer' => 'toggle', 'valueMap' => ['false' => '0', 'true' => '1']]]]], 'use_config_' . static::FIELD_MESSAGE_AVAILABLE => ['arguments' => ['data' => ['config' => ['dataType' => 'number', 'formElement' => Checkbox::NAME, 'componentType' => Field::NAME, 'description' => __('Use Config Settings'), 'dataScope' => 'use_config_' . static::FIELD_MESSAGE_AVAILABLE, 'valueMap' => ['false' => '0', 'true' => '1']]]]]]]);
     return $meta;
 }
 /**
  * Customize date range field if from and to fields belong to one group
  *
  * @param array $meta
  * @return array
  */
 protected function customizeDateRangeField(array $meta)
 {
     if ($this->getGroupCodeByField($meta, self::CODE_CUSTOM_DESIGN_FROM) !== $this->getGroupCodeByField($meta, self::CODE_CUSTOM_DESIGN_TO)) {
         return $meta;
     }
     $fromFieldPath = $this->arrayManager->findPath(self::CODE_CUSTOM_DESIGN_FROM, $meta, null, 'children');
     $toFieldPath = $this->arrayManager->findPath(self::CODE_CUSTOM_DESIGN_TO, $meta, null, 'children');
     $fromContainerPath = $this->arrayManager->slicePath($fromFieldPath, 0, -2);
     $toContainerPath = $this->arrayManager->slicePath($toFieldPath, 0, -2);
     $meta = $this->arrayManager->merge($fromFieldPath . self::META_CONFIG_PATH, $meta, ['label' => __('Schedule Update From'), 'additionalClasses' => 'admin__field-date']);
     $meta = $this->arrayManager->merge($toFieldPath . self::META_CONFIG_PATH, $meta, ['label' => __('To'), 'scopeLabel' => null, 'additionalClasses' => 'admin__field-date']);
     $meta = $this->arrayManager->merge($fromContainerPath . self::META_CONFIG_PATH, $meta, ['label' => __('Schedule Update From'), 'additionalClasses' => 'admin__control-grouped-date', 'breakLine' => false, 'component' => 'Magento_Ui/js/form/components/group']);
     $meta = $this->arrayManager->set($fromContainerPath . '/children/' . self::CODE_CUSTOM_DESIGN_TO, $meta, $this->arrayManager->get($toFieldPath, $meta));
     return $this->arrayManager->remove($toContainerPath, $meta);
 }
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function modifyMeta(array $meta)
 {
     if ($groupCode = $this->getGroupCodeByField($meta, ProductAttributeInterface::CODE_PRICE) ?: $this->getGroupCodeByField($meta, self::CODE_GROUP_PRICE)) {
         $isNewProduct = $this->locator->getProduct()->getId() ? false : true;
         $pricePath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_PRICE) ?: $this->getElementArrayPath($meta, self::CODE_GROUP_PRICE);
         $meta[$groupCode]['children'][self::CODE_PRICE_TYPE] = ['arguments' => ['data' => ['config' => ['sortOrder' => self::SORT_ORDER, 'formElement' => Form\Element\Checkbox::NAME, 'componentType' => Form\Field::NAME, 'label' => __('Dynamic Price'), 'prefer' => 'toggle', 'additionalClasses' => 'admin__field-x-small', 'templates' => ['checkbox' => 'ui/form/components/single/switcher'], 'valueMap' => ['false' => '1', 'true' => '0'], 'dataScope' => self::CODE_PRICE_TYPE, 'value' => '0', 'disabled' => $isNewProduct ? false : true, 'scopeLabel' => $this->arrayManager->get($pricePath . '/scopeLabel', $meta)]]]];
         if (!empty($meta[$groupCode]['children']['container_' . self::CODE_PRICE_TYPE])) {
             $container =& $meta[$groupCode]['children']['container_' . self::CODE_PRICE_TYPE];
             $container['arguments']['data']['config']['sortOrder'] = self::SORT_ORDER;
             $container['arguments']['data']['config']['label'] = __('Dynamic Price');
         }
         if (!empty($meta[$groupCode]['children'][self::CODE_GROUP_PRICE])) {
             $meta[$groupCode]['children'][self::CODE_GROUP_PRICE] = array_replace_recursive($meta[$groupCode]['children'][self::CODE_GROUP_PRICE], ['children' => [ProductAttributeInterface::CODE_PRICE => ['arguments' => ['data' => ['config' => ['imports' => ['disabled' => 'ns = ${ $.ns }, index = ' . self::CODE_PRICE_TYPE . ':checked']]]]]]]);
         }
         if (!empty($meta[$groupCode]['children']['container_' . self::CODE_TAX_CLASS_ID])) {
             $meta[$groupCode]['children']['container_' . self::CODE_TAX_CLASS_ID] = array_replace_recursive($meta[$groupCode]['children']['container_' . self::CODE_TAX_CLASS_ID], ['children' => [self::CODE_TAX_CLASS_ID => ['arguments' => ['data' => ['config' => ['imports' => ['disabled' => 'ns = ${ $.ns }, index = ' . self::CODE_PRICE_TYPE . ':checked']]]]]]]);
         }
     }
     return $meta;
 }
示例#8
0
 /**
  * Special price data move to inline group
  *
  * @return $this
  */
 protected function specialPriceDataToInline()
 {
     $pathFrom = $this->arrayManager->findPath('special_from_date', $this->meta, null, 'children');
     $pathTo = $this->arrayManager->findPath('special_to_date', $this->meta, null, 'children');
     if ($pathFrom && $pathTo) {
         $this->meta = $this->arrayManager->merge($this->arrayManager->slicePath($pathFrom, 0, -2) . '/arguments/data/config', $this->meta, ['label' => __('Special Price From'), 'additionalClasses' => 'admin__control-grouped-date', 'breakLine' => false, 'component' => 'Magento_Ui/js/form/components/group', 'scopeLabel' => $this->arrayManager->get($pathFrom . '/arguments/data/config/scopeLabel', $this->meta)]);
         $this->meta = $this->arrayManager->merge($pathFrom . '/arguments/data/config', $this->meta, ['label' => __('Special Price From'), 'scopeLabel' => null, 'additionalClasses' => 'admin__field-date']);
         $this->meta = $this->arrayManager->merge($pathTo . '/arguments/data/config', $this->meta, ['label' => __('To'), 'scopeLabel' => null, 'additionalClasses' => 'admin__field-date']);
         // Move special_to_date to special_from_date container
         $this->meta = $this->arrayManager->set($this->arrayManager->slicePath($pathFrom, 0, -1) . '/special_to_date', $this->meta, $this->arrayManager->get($pathTo, $this->meta));
         $this->meta = $this->arrayManager->remove($this->arrayManager->slicePath($pathTo, 0, -2), $this->meta);
     }
     return $this;
 }
 /**
  * @return void
  */
 private function prepareMeta()
 {
     $fieldCode = 'quantity_and_stock_status';
     $pathField = $this->getElementArrayPath($this->meta, $fieldCode);
     if ($pathField) {
         $labelField = $this->arrayManager->get($this->arrayManager->slicePath($pathField, 0, -2) . '/arguments/data/config/label', $this->meta);
         $fieldsetPath = $this->arrayManager->slicePath($pathField, 0, -4);
         $this->meta = $this->arrayManager->merge($pathField . '/arguments/data/config', $this->meta, ['label' => __('Stock Status'), 'value' => '1', 'dataScope' => $fieldCode . '.is_in_stock', 'scopeLabel' => '[GLOBAL]']);
         $this->meta = $this->arrayManager->merge($this->arrayManager->slicePath($pathField, 0, -2) . '/arguments/data/config', $this->meta, ['label' => __('Stock Status'), 'scopeLabel' => '[GLOBAL]']);
         $container['arguments']['data']['config'] = ['formElement' => 'container', 'componentType' => 'container', 'component' => "Magento_Ui/js/form/components/group", 'label' => $labelField, 'breakLine' => false, 'dataScope' => $fieldCode, 'scopeLabel' => '[GLOBAL]', 'source' => 'product_details', 'sortOrder' => (int) $this->arrayManager->get($this->arrayManager->slicePath($pathField, 0, -2) . '/arguments/data/config/sortOrder', $this->meta) - 1];
         $qty['arguments']['data']['config'] = ['component' => 'Magento_CatalogInventory/js/components/qty-validator-changer', 'dataType' => 'number', 'formElement' => 'input', 'componentType' => 'field', 'visible' => '1', 'require' => '0', 'additionalClasses' => 'admin__field-small', 'dataScope' => 'qty', 'validation' => ['validate-number' => true, 'validate-digits' => true], 'imports' => ['handleChanges' => '${$.provider}:data.product.stock_data.is_qty_decimal'], 'sortOrder' => 10];
         $advancedInventoryButton['arguments']['data']['config'] = ['displayAsLink' => true, 'formElement' => 'container', 'componentType' => 'container', 'component' => 'Magento_Ui/js/form/components/button', 'template' => 'ui/form/components/button/container', 'actions' => [['targetName' => 'product_form.product_form.advanced_inventory_modal', 'actionName' => 'toggleModal']], 'title' => __('Advanced Inventory'), 'provider' => false, 'additionalForGroup' => true, 'source' => 'product_details', 'sortOrder' => 20];
         $container['children'] = ['qty' => $qty, 'advanced_inventory_button' => $advancedInventoryButton];
         $this->meta = $this->arrayManager->merge($fieldsetPath . '/children', $this->meta, ['quantity_and_stock_status_qty' => $container]);
     }
 }
示例#10
0
 /**
  * Customize "Set Product as New" date fields
  *
  * @param array $meta
  * @return array
  */
 protected function customizeNewDateRangeField(array $meta)
 {
     $fromField = 'news_from_date';
     $toField = 'news_to_date';
     $fromFieldPath = $this->arrayManager->findPath($fromField, $meta, null, 'children');
     $toFieldPath = $this->arrayManager->findPath($toField, $meta, null, 'children');
     if ($fromFieldPath && $toFieldPath) {
         $fromContainerPath = $this->arrayManager->slicePath($fromFieldPath, 0, -2);
         $toContainerPath = $this->arrayManager->slicePath($toFieldPath, 0, -2);
         $meta = $this->arrayManager->merge($fromFieldPath . self::META_CONFIG_PATH, $meta, ['label' => __('Set Product as New From'), 'additionalClasses' => 'admin__field-date']);
         $meta = $this->arrayManager->merge($toFieldPath . self::META_CONFIG_PATH, $meta, ['label' => __('To'), 'scopeLabel' => null, 'additionalClasses' => 'admin__field-date']);
         $meta = $this->arrayManager->merge($fromContainerPath . self::META_CONFIG_PATH, $meta, ['label' => __('Set Product as New From'), 'additionalClasses' => 'admin__control-grouped-date', 'breakLine' => false, 'component' => 'Magento_Ui/js/form/components/group']);
         $meta = $this->arrayManager->set($fromContainerPath . '/children/' . $toField, $meta, $this->arrayManager->get($toFieldPath, $meta));
         $meta = $this->arrayManager->remove($toContainerPath, $meta);
     }
     return $meta;
 }
 /**
  * Format float number to have two digits after delimiter
  *
  * @param string $path
  * @param array $data
  * @return array
  */
 protected function formatFloat($path, array $data)
 {
     $value = $this->arrayManager->get($path, $data);
     if (is_numeric($value)) {
         $data = $this->arrayManager->replace($path, $data, number_format($value, 2, '.', ''));
     }
     return $data;
 }
示例#12
0
 /**
  * Initial meta setup
  *
  * @param ProductAttributeInterface $attribute
  * @param string $groupCode
  * @param int $sortOrder
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @api
  */
 public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupCode, $sortOrder)
 {
     $configPath = ltrim(static::META_CONFIG_PATH, ArrayManager::DEFAULT_PATH_DELIMITER);
     $meta = $this->arrayManager->set($configPath, [], ['dataType' => $attribute->getFrontendInput(), 'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()), 'visible' => $attribute->getIsVisible(), 'required' => $attribute->getIsRequired(), 'notice' => $attribute->getNote(), 'default' => $attribute->getDefaultValue(), 'label' => $attribute->getDefaultFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'source' => $groupCode, 'scopeLabel' => $this->getScopeLabel($attribute), 'globalScope' => $this->isScopeGlobal($attribute), 'sortOrder' => $sortOrder * self::SORT_ORDER_MULTIPLIER]);
     // TODO: Refactor to $attribute->getOptions() when MAGETWO-48289 is done
     $attributeModel = $this->getAttributeModel($attribute);
     if ($attributeModel->usesSource()) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['options' => $attributeModel->getSource()->getAllOptions()]);
     }
     if ($this->canDisplayUseDefault($attribute)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['service' => ['template' => 'ui/form/element/helper/service']]);
     }
     if (!$this->arrayManager->exists($configPath . '/componentType', $meta)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['componentType' => Field::NAME]);
     }
     if (in_array($attribute->getAttributeCode(), $this->attributesToDisable)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['disabled' => true]);
     }
     // TODO: getAttributeModel() should not be used when MAGETWO-48284 is complete
     $childData = $this->arrayManager->get($configPath, $meta, []);
     if ($rules = $this->catalogEavValidationRules->build($this->getAttributeModel($attribute), $childData)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['validation' => $rules]);
     }
     $meta = $this->addUseDefaultValueCheckbox($attribute, $meta);
     switch ($attribute->getFrontendInput()) {
         case 'boolean':
             $meta = $this->customizeCheckbox($attribute, $meta);
             break;
         case 'textarea':
             $meta = $this->customizeWysiwyg($attribute, $meta);
             break;
         case 'price':
             $meta = $this->customizePriceAttribute($attribute, $meta);
             break;
         case 'gallery':
             // Gallery attribute is being handled by "Images And Videos" section
             $meta = [];
             break;
     }
     return $meta;
 }
示例#13
0
 /**
  * Format float number to have two digits after delimiter
  *
  * @param string $path
  * @param array $data
  * @return array
  */
 protected function formatPriceByPath($path, array $data)
 {
     $value = $this->arrayManager->get($path, $data);
     if (is_numeric($value)) {
         $data = $this->arrayManager->replace($path, $data, $this->formatPrice($value));
     }
     return $data;
 }
 /**
  * @param string $path
  * @param array $data
  * @param mixed $result
  * @dataProvider getDataProvider
  */
 public function testGet($path, $data, $result)
 {
     $this->assertSame($result, $this->arrayManager->get($path, $data));
 }