/**
  * Add Checkbox
  *
  * @return void
  */
 protected function addCheckboxIsDownloadable()
 {
     $checkboxPath = Composite::CHILDREN_PATH . '/' . ProductAttributeInterface::CODE_IS_DOWNLOADABLE;
     $checkboxConfig['arguments']['data']['config'] = ['dataType' => Form\Element\DataType\Number::NAME, 'formElement' => Form\Element\Checkbox::NAME, 'componentType' => Form\Field::NAME, 'component' => 'Magento_Downloadable/js/components/is-downloadable-handler', 'description' => __('Is this downloadable Product?'), 'dataScope' => ProductAttributeInterface::CODE_IS_DOWNLOADABLE, 'sortOrder' => 10, 'imports' => ['disabled' => '${$.provider}:' . self::DATA_SCOPE_PRODUCT . '.' . ProductAttributeInterface::CODE_HAS_WEIGHT], 'valueMap' => ['false' => '0', 'true' => '1'], 'samplesFieldset' => 'ns = ${ $.ns }, index=' . Composite::CONTAINER_SAMPLES, 'linksFieldset' => 'ns = ${ $.ns }, index=' . Composite::CONTAINER_LINKS];
     $hideConfig['arguments']['data']['config'] = ['dataType' => Form\Element\DataType\Number::NAME, 'formElement' => Form\Element\Hidden::NAME, 'componentType' => Form\Field::NAME, 'value' => '1', 'dataScope' => ProductAttributeInterface::CODE_IS_DOWNLOADABLE, 'sortOrder' => 10];
     $this->meta = $this->arrayManager->set($checkboxPath, $this->meta, $this->locator->getProduct()->getTypeId() === Type::TYPE_DOWNLOADABLE ? $hideConfig : $checkboxConfig);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function modifyMeta(array $meta)
 {
     if ($this->locator->getProduct()->getTypeId() === static::PRODUCT_TYPE_GROUPED) {
         $meta = $this->arrayManager->remove(CustomOptionsModifier::GROUP_CUSTOM_OPTIONS_NAME, $meta);
     }
     return $meta;
 }
 /**
  * @return void
  */
 public function testModifyMeta()
 {
     $this->locatorMock->expects($this->exactly(2))->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->any())->method('getTypeId');
     $this->arrayManagerMock->expects($this->exactly(3))->method('set')->willReturn([]);
     $this->assertEquals([], $this->downloadablePanel->modifyMeta([]));
 }
 /**
  * {@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;
 }
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->locatorMock = $this->getMockBuilder(LocatorInterface::class)->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass();
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)->disableOriginalConstructor()->getMock();
     $this->arrayManagerMock->expects($this->any())->method('get')->willReturnArgument(3);
 }
Example #6
0
 /**
  * Modify "Price Type" fields
  *
  * @param array $meta
  * @return array
  */
 private function modifyPriceTypeFields(array $meta)
 {
     $isConfigurable = $this->locator->getProduct()->getTypeId() === ConfigurableProductType::TYPE_CODE;
     $paths = $this->arrayManager->findPaths(CustomOptionsModifier::FIELD_PRICE_TYPE_NAME, $meta, CustomOptionsModifier::GROUP_CUSTOM_OPTIONS_NAME . '/children', 'children');
     foreach ($paths as $fieldPath) {
         $meta = $this->arrayManager->merge($fieldPath . static::META_CONFIG_PATH, $meta, ['component' => 'Magento_ConfigurableProduct/js/components/custom-options-price-type', 'isConfigurable' => $isConfigurable, 'bannedOptions' => ['percent'], 'imports' => ['updateOptions' => 'ns = ${ $.ns }, index = ' . ConfigurablePanel::CONFIGURABLE_MATRIX . ':isEmpty']]);
     }
     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;
 }
 /**
  * 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->getElementArrayPath($meta, self::CODE_CUSTOM_DESIGN_FROM);
     $toFieldPath = $this->getElementArrayPath($meta, self::CODE_CUSTOM_DESIGN_TO);
     $fromContainerPath = $this->arrayManager->slicePath($fromFieldPath, 0, -2);
     $toContainerPath = $this->arrayManager->slicePath($toFieldPath, 0, -2);
     $scopeLabel = $this->arrayManager->get($fromFieldPath . self::META_CONFIG_PATH . '/scopeLabel', $meta);
     $meta = $this->arrayManager->merge($fromFieldPath . self::META_CONFIG_PATH, $meta, ['label' => __('Schedule Update From'), 'scopeLabel' => null, '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', 'scopeLabel' => $scopeLabel]);
     $meta = $this->arrayManager->set($fromContainerPath . '/children/' . self::CODE_CUSTOM_DESIGN_TO, $meta, $this->arrayManager->get($toFieldPath, $meta));
     return $this->arrayManager->remove($toContainerPath, $meta);
 }
    public function testSlicePathCustomDelimiter()
    {
        $path = 'my~custom~path';

        $this->assertSame('custom', $this->arrayManager->slicePath($path, 1, 1, '~'));
        $this->assertSame('', $this->arrayManager->slicePath($path, 1, 1));
    }
Example #11
0
 /**
  * @return array
  */
 protected function getMaxDownloadsColumn()
 {
     $maxDownloadsContainer['arguments']['data']['config'] = ['componentType' => Container::NAME, 'formElement' => Container::NAME, 'component' => 'Magento_Ui/js/form/components/group', 'label' => __('Max. Downloads'), 'dataScope' => ''];
     $numberOfDownloadsField['arguments']['data']['config'] = ['formElement' => Form\Element\Input::NAME, 'componentType' => Form\Field::NAME, 'dataType' => Form\Element\DataType\Number::NAME, 'dataScope' => 'number_of_downloads', 'value' => 0, 'validation' => ['validate-zero-or-greater' => true, 'validate-number' => true]];
     $isUnlimitedField['arguments']['data']['config'] = ['formElement' => Form\Element\Checkbox::NAME, 'componentType' => Form\Field::NAME, 'dataType' => Form\Element\DataType\Number::NAME, 'dataScope' => 'is_unlimited', 'description' => __('Unlimited'), 'valueMap' => ['false' => '0', 'true' => '1'], 'exports' => ['checked' => '${$.parentName}.number_of_downloads:disabled']];
     return $this->arrayManager->set('children', $maxDownloadsContainer, ['number_of_downloads' => $numberOfDownloadsField, 'is_unlimited' => $isUnlimitedField]);
 }
 /**
  * @return array
  */
 protected function getSampleColumn()
 {
     $sampleContainer['arguments']['data']['config'] = ['componentType' => Container::NAME, 'formElement' => Container::NAME, 'component' => 'Magento_Ui/js/form/components/group', 'label' => __('File'), 'dataScope' => ''];
     $sampleType['arguments']['data']['config'] = ['formElement' => Form\Element\Select::NAME, 'componentType' => Form\Field::NAME, 'component' => 'Magento_Downloadable/js/components/upload-type-handler', 'dataType' => Form\Element\DataType\Text::NAME, 'dataScope' => 'type', 'options' => $this->typeUpload->toOptionArray(), 'typeFile' => 'sample_file', 'typeUrl' => 'sample_url'];
     $sampleUrl['arguments']['data']['config'] = ['formElement' => Form\Element\Input::NAME, 'componentType' => Form\Field::NAME, 'dataType' => Form\Element\DataType\Text::NAME, 'dataScope' => 'sample_url', 'placeholder' => 'URL', 'validation' => ['required-entry' => true, 'validate-url' => true]];
     $sampleUploader['arguments']['data']['config'] = ['formElement' => 'fileUploader', 'componentType' => 'fileUploader', 'component' => 'Magento_Downloadable/js/components/file-uploader', 'elementTmpl' => 'Magento_Downloadable/components/file-uploader', 'fileInputName' => 'samples', 'uploaderConfig' => ['url' => $this->urlBuilder->addSessionParam()->getUrl('adminhtml/downloadable_file/upload', ['type' => 'samples', '_secure' => true])], 'dataScope' => 'file', 'validation' => ['required-entry' => true]];
     return $this->arrayManager->set('children', $sampleContainer, ['sample_type' => $sampleType, 'sample_url' => $sampleUrl, 'sample_file' => $sampleUploader]);
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function modifyMeta(array $meta)
 {
     $meta = $this->arrayManager->merge($this->arrayManager->findPath(static::CODE_WEIGHT_TYPE, $meta, null, 'children') . static::META_CONFIG_PATH, $meta, ['valueMap' => ['false' => '1', 'true' => '0'], 'validation' => ['required-entry' => false]]);
     $meta = $this->arrayManager->merge($this->arrayManager->findPath(ProductAttributeInterface::CODE_HAS_WEIGHT, $meta, null, 'children') . static::META_CONFIG_PATH, $meta, ['disabled' => true, 'visible' => false]);
     $meta = $this->arrayManager->merge($this->arrayManager->findPath(ProductAttributeInterface::CODE_WEIGHT, $meta, null, 'children') . static::META_CONFIG_PATH, $meta, ['imports' => ['disabled' => 'ns = ${ $.ns }, index = ' . static::CODE_WEIGHT_TYPE . ':checked']]);
     return $meta;
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function modifyMeta(array $meta)
 {
     $meta = $this->arrayManager->merge($this->arrayManager->findPath(static::CODE_PRICE_TYPE, $meta, null, 'children') . static::META_CONFIG_PATH, $meta, ['disabled' => (bool) $this->locator->getProduct()->getId(), 'valueMap' => ['false' => '1', 'true' => '0'], 'validation' => ['required-entry' => false]]);
     $meta = $this->arrayManager->merge($this->arrayManager->findPath(ProductAttributeInterface::CODE_PRICE, $meta, null, 'children') . static::META_CONFIG_PATH, $meta, ['imports' => ['disabled' => 'ns = ${ $.ns }, index = ' . static::CODE_PRICE_TYPE . ':checked']]);
     $meta = $this->arrayManager->merge($this->arrayManager->findPath(static::CODE_TAX_CLASS_ID, $meta, null, 'children') . static::META_CONFIG_PATH, $meta, ['imports' => ['disabled' => 'ns = ${ $.ns }, index = ' . static::CODE_PRICE_TYPE . ':checked']]);
     return $meta;
 }
Example #15
0
 /**
  * Customize msrp display actual price field
  *
  * @return $this
  */
 protected function customizeMsrpDisplayActualPrice()
 {
     $msrpDisplayPath = $this->arrayManager->findPath(static::FIELD_MSRP_DISPLAY_ACTUAL_PRICE, $this->meta, null, 'children');
     if ($msrpDisplayPath) {
         if (!$this->msrpConfig->isEnabled()) {
             $this->meta = $this->arrayManager->remove($this->arrayManager->slicePath($msrpDisplayPath, 0, -2), $this->meta);
         }
     }
     return $this;
 }
 /**
  * Customize msrp display actual price field
  *
  * @return $this
  */
 protected function customizeMsrpDisplayActualPrice()
 {
     $msrpDisplayPath = $this->getElementArrayPath($this->meta, self::FIELD_MSRP_DISPLAY_ACTUAL_PRICE);
     if ($msrpDisplayPath) {
         if (!$this->msrpConfig->isEnabled()) {
             $this->meta = $this->arrayManager->remove($this->arrayManager->slicePath($msrpDisplayPath, 0, -2), $this->meta);
         }
     }
     return $this;
 }
Example #17
0
 /**
  * Add use default checkbox to title in grid
  *
  * @param string $indexTitle
  * @return $this
  */
 protected function titleUsedDefaultInGrid($indexTitle)
 {
     if ($this->locator->getProduct()->getStoreId()) {
         $linkTitleGroupPath = $this->arrayManager->findPath('container_' . $indexTitle, $this->meta, null, 'children');
         $checkboxPath = $linkTitleGroupPath . '/children/use_default_title/arguments/data/config';
         $useDefaultConfig = ['componentType' => Form\Element\Checkbox::NAME, 'formElement' => Form\Field::NAME, 'description' => __('Use Default Value'), 'dataScope' => 'use_default_title', 'valueMap' => ['false' => '0', 'true' => '1'], 'exports' => ['checked' => '${$.parentName}.' . $indexTitle . ':disabled']];
         $this->meta = $this->arrayManager->set($checkboxPath, $this->meta, $useDefaultConfig);
     }
     return $this;
 }
 /**
  * {@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;
 }
 /**
  * @return void
  */
 public function testModifyMeta()
 {
     $this->locatorMock->expects($this->once())->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->once())->method('getTypeId');
     $this->storeManagerMock->expects($this->once())->method('isSingleStoreMode');
     $this->typeUploadMock->expects($this->once())->method('toOptionArray');
     $this->urlBuilderMock->expects($this->once())->method('addSessionParam')->willReturnSelf();
     $this->urlBuilderMock->expects($this->once())->method('getUrl');
     $this->arrayManagerMock->expects($this->exactly(6))->method('set')->willReturn([]);
     $this->assertEquals([], $this->samples->modifyMeta([]));
 }
Example #20
0
 /**
  * Customize Advanced Pricing Panel
  *
  * @return $this
  */
 protected function customizeAdvancedPricing()
 {
     $this->meta['advanced-pricing']['arguments']['data']['config']['opened'] = true;
     $this->meta['advanced-pricing']['arguments']['data']['config']['collapsible'] = false;
     $this->meta['advanced-pricing']['arguments']['data']['config']['label'] = '';
     $this->meta['advanced_pricing_modal']['arguments']['data']['config'] = ['isTemplate' => false, 'componentType' => Modal::NAME, 'dataScope' => '', 'provider' => 'product_form.product_form_data_source', 'onCancel' => 'actionDone', 'options' => ['title' => __('Advanced Pricing'), 'buttons' => [['text' => __('Done'), 'class' => 'action-primary', 'actions' => [['targetName' => '${ $.name }', 'actionName' => 'actionDone']]]]]];
     $this->meta = $this->arrayManager->merge($this->arrayManager->findPath(static::CONTAINER_PREFIX . ProductAttributeInterface::CODE_PRICE, $this->meta, null, 'children'), $this->meta, ['arguments' => ['data' => ['config' => ['component' => 'Magento_Ui/js/form/components/group']]]]);
     $this->meta['advanced_pricing_modal']['children']['advanced-pricing'] = $this->meta['advanced-pricing'];
     unset($this->meta['advanced-pricing']);
     return $this;
 }
Example #21
0
 /**
  * Customize Categories field
  *
  * @param array $meta
  * @return array
  */
 protected function customizeCategoriesField(array $meta)
 {
     $fieldCode = 'category_ids';
     $elementPath = $this->arrayManager->findPath($fieldCode, $meta, null, 'children');
     $containerPath = $this->arrayManager->findPath(static::CONTAINER_PREFIX . $fieldCode, $meta, null, 'children');
     if (!$elementPath) {
         return $meta;
     }
     $meta = $this->arrayManager->merge($containerPath, $meta, ['arguments' => ['data' => ['config' => ['label' => __('Categories'), 'dataScope' => '', 'breakLine' => false, 'formElement' => 'container', 'componentType' => 'container', 'component' => 'Magento_Ui/js/form/components/group', 'scopeLabel' => __('[GLOBAL]')]]], 'children' => [$fieldCode => ['arguments' => ['data' => ['config' => ['formElement' => 'select', 'componentType' => 'field', 'component' => 'Magento_Catalog/js/components/new-category', 'filterOptions' => true, 'chipsEnabled' => true, 'disableLabel' => true, 'levelsVisibility' => '1', 'elementTmpl' => 'ui/grid/filters/elements/ui-select', 'options' => $this->getCategoriesTree(), 'listens' => ['index=create_category:responseData' => 'setParsed', 'newOption' => 'toggleOptionSelected'], 'config' => ['dataScope' => $fieldCode, 'sortOrder' => 10]]]]], 'create_category_button' => ['arguments' => ['data' => ['config' => ['title' => __('New Category'), 'formElement' => 'container', 'additionalClasses' => 'admin__field-small', 'componentType' => 'container', 'component' => 'Magento_Ui/js/form/components/button', 'template' => 'ui/form/components/button/container', 'actions' => [['targetName' => 'product_form.product_form.create_category_modal', 'actionName' => 'toggleModal'], ['targetName' => 'product_form.product_form.create_category_modal.create_category', 'actionName' => 'render'], ['targetName' => 'product_form.product_form.create_category_modal.create_category', 'actionName' => 'resetForm']], 'additionalForGroup' => true, 'provider' => false, 'source' => 'product_details', 'displayArea' => 'insideGroup', 'sortOrder' => 20]]]]]]);
     return $meta;
 }
 /**
  * Add links for fields depends of product name
  *
  * @param array $meta
  * @return array
  */
 protected function customizeNameListeners(array $meta)
 {
     $listeners = [ProductAttributeInterface::CODE_SKU, ProductAttributeInterface::CODE_SEO_FIELD_META_TITLE, ProductAttributeInterface::CODE_SEO_FIELD_META_KEYWORD, ProductAttributeInterface::CODE_SEO_FIELD_META_DESCRIPTION];
     foreach ($listeners as $listener) {
         $listenerPath = $this->getElementArrayPath($meta, $listener);
         $importsConfig = ['arguments' => ['data' => ['config' => ['component' => 'Magento_Catalog/js/components/import-handler', 'imports' => ['handleChanges' => '${$.provider}:data.product.name']]]]];
         $meta = $this->arrayManager->merge($listenerPath, $meta, $importsConfig);
     }
     $skuPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_SKU);
     $meta = $this->arrayManager->merge($skuPath, $meta, ['arguments' => ['data' => ['config' => ['autoImportIfEmpty' => true, 'allowImport' => $this->locator->getProduct()->getId() ? false : true]]]]);
     $namePath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_NAME);
     return $this->arrayManager->merge($namePath, $meta, ['arguments' => ['data' => ['config' => ['valueUpdate' => 'keyup']]]]);
 }
Example #23
0
 /**
  * Customize options
  *
  * @param array $meta
  * @return array
  */
 private function customizeOptions($meta)
 {
     $sortOrder = 1;
     foreach ($this->storeRepository->getList() as $store) {
         $storeId = $store->getId();
         $meta['attribute_options_select_container']['children']['attribute_options_select']['children']['record']['children']['value_option_' . $storeId] = $this->arrayManager->set('arguments/data/config', [], ['dataType' => 'text', 'formElement' => 'input', 'component' => 'Magento_Catalog/js/form/element/input', 'template' => 'Magento_Catalog/form/element/input', 'prefixName' => 'option.value', 'prefixElementName' => 'option_', 'suffixName' => (string) $storeId, 'label' => $store->getName(), 'sortOrder' => $sortOrder, 'componentType' => Field::NAME]);
         $meta['attribute_options_multiselect_container']['children']['attribute_options_multiselect']['children']['record']['children']['value_option_' . $storeId] = $this->arrayManager->set('arguments/data/config', [], ['dataType' => 'text', 'formElement' => 'input', 'component' => 'Magento_Catalog/js/form/element/input', 'template' => 'Magento_Catalog/form/element/input', 'prefixName' => 'option.value', 'prefixElementName' => 'option_', 'suffixName' => (string) $storeId, 'label' => $store->getName(), 'sortOrder' => $sortOrder, 'componentType' => Field::NAME]);
         ++$sortOrder;
     }
     $meta['attribute_options_select_container']['children']['attribute_options_select']['children']['record']['children']['action_delete'] = $this->arrayManager->set('arguments/data/config', [], ['componentType' => 'actionDelete', 'dataType' => 'text', 'fit' => true, 'sortOrder' => $sortOrder, 'component' => 'Magento_Catalog/js/form/element/action-delete', 'elementTmpl' => 'Magento_Catalog/form/element/action-delete', 'template' => 'Magento_Catalog/form/element/action-delete', 'prefixName' => 'option.delete', 'prefixElementName' => 'option_']);
     $meta['attribute_options_multiselect_container']['children']['attribute_options_multiselect']['children']['record']['children']['action_delete'] = $this->arrayManager->set('arguments/data/config', [], ['componentType' => 'actionDelete', 'dataType' => 'text', 'fit' => true, 'sortOrder' => $sortOrder, 'component' => 'Magento_Catalog/js/form/element/action-delete', 'elementTmpl' => 'Magento_Catalog/form/element/action-delete', 'template' => 'Magento_Catalog/form/element/action-delete', 'prefixName' => 'option.delete', 'prefixElementName' => 'option_']);
     return $meta;
 }
 /**
  * @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]);
     }
 }
 /**
  * Adding URL rewrite checkbox to meta
  *
  * @param array $meta
  * @return array
  */
 protected function addUrlRewriteCheckbox(array $meta)
 {
     $urlPath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY, $meta, null, 'children');
     if ($urlPath) {
         $containerPath = $this->arrayManager->slicePath($urlPath, 0, -2);
         $urlKey = $this->locator->getProduct()->getData('url_key');
         $saveRewritesHistory = $this->scopeConfig->isSetFlag(self::XML_PATH_SEO_SAVE_HISTORY, ScopeInterface::SCOPE_STORE, $this->locator->getProduct()->getStoreId());
         $meta = $this->arrayManager->merge($containerPath, $meta, ['arguments' => ['data' => ['config' => ['component' => 'Magento_Ui/js/form/components/group']]]]);
         $checkbox['arguments']['data']['config'] = ['componentType' => Field::NAME, 'formElement' => Checkbox::NAME, 'dataType' => Text::NAME, 'component' => 'Magento_Catalog/js/components/url-key-handle-changes', 'valueMap' => ['false' => '', 'true' => $urlKey], 'imports' => ['urlKey' => '${ $.provider }:data.product.' . ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY, 'handleUseDefault' => '${ $.parentName }.url_key:isUseDefault', 'handleChanges' => '${ $.provider }:data.product.' . ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY], 'description' => __('Create Permanent Redirect for old URL'), 'dataScope' => 'url_key_create_redirect', 'value' => $saveRewritesHistory ? $urlKey : '', 'checked' => $saveRewritesHistory];
         $meta = $this->arrayManager->merge($urlPath . '/arguments/data/config', $meta, ['valueUpdate' => 'keyup']);
         $meta = $this->arrayManager->merge($containerPath . '/children', $meta, ['url_key_create_redirect' => $checkbox]);
         $meta = $this->arrayManager->merge($containerPath . '/arguments/data/config', $meta, ['breakLine' => true]);
     }
     return $meta;
 }
 /**
  * @return void
  */
 public function testModifyMeta()
 {
     $this->locatorMock->expects($this->once())->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->any())->method('getTypeId');
     $this->storeManagerMock->expects($this->exactly(2))->method('isSingleStoreMode');
     $this->typeUploadMock->expects($this->exactly(2))->method('toOptionArray');
     $this->shareableMock->expects($this->once())->method('toOptionArray');
     $this->urlBuilderMock->expects($this->exactly(2))->method('addSessionParam')->willReturnSelf();
     $this->urlBuilderMock->expects($this->exactly(2))->method('getUrl');
     $currencyMock = $this->getMock(\Magento\Directory\Model\Currency::class, [], [], '', false);
     $currencyMock->expects($this->once())->method('getCurrencySymbol');
     $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->setMethods(['getBaseCurrency'])->getMockForAbstractClass();
     $storeMock->expects($this->once())->method('getBaseCurrency')->willReturn($currencyMock);
     $this->locatorMock->expects($this->once())->method('getStore')->willReturn($storeMock);
     $this->arrayManagerMock->expects($this->exactly(9))->method('set')->willReturn([]);
     $this->assertEquals([], $this->links->modifyMeta([]));
 }
Example #27
0
 /**
  * Add links for fields depends of product name
  *
  * @param array $meta
  * @return array
  */
 protected function customizeNameListeners(array $meta)
 {
     $listeners = [ProductAttributeInterface::CODE_SKU, ProductAttributeInterface::CODE_SEO_FIELD_META_TITLE, ProductAttributeInterface::CODE_SEO_FIELD_META_KEYWORD, ProductAttributeInterface::CODE_SEO_FIELD_META_DESCRIPTION];
     $textListeners = [ProductAttributeInterface::CODE_SEO_FIELD_META_KEYWORD, ProductAttributeInterface::CODE_SEO_FIELD_META_DESCRIPTION];
     foreach ($listeners as $listener) {
         $listenerPath = $this->arrayManager->findPath($listener, $meta, null, 'children');
         $importsConfig = ['mask' => $this->locator->getStore()->getConfig('catalog/fields_masks/' . $listener), 'component' => 'Magento_Catalog/js/components/import-handler', 'imports' => ['handleNameChanges' => '${$.provider}:data.product.name', 'handleDescriptionChanges' => '${$.provider}:data.product.description', 'handleSkuChanges' => '${$.provider}:data.product.sku', 'handleColorChanges' => '${$.provider}:data.product.color', 'handleCountryChanges' => '${$.provider}:data.product.country_of_manufacture', 'handleGenderChanges' => '${$.provider}:data.product.gender', 'handleMaterialChanges' => '${$.provider}:data.product.material', 'handleShortDescriptionChanges' => '${$.provider}:data.product.short_description', 'handleSizeChanges' => '${$.provider}:data.product.size'], 'allowImport' => !$this->locator->getProduct()->getId()];
         if (!in_array($listener, $textListeners)) {
             $importsConfig['elementTmpl'] = 'ui/form/element/input';
         }
         $meta = $this->arrayManager->merge($listenerPath . static::META_CONFIG_PATH, $meta, $importsConfig);
     }
     $skuPath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_SKU, $meta, null, 'children');
     $meta = $this->arrayManager->merge($skuPath . static::META_CONFIG_PATH, $meta, ['autoImportIfEmpty' => true]);
     $namePath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_NAME, $meta, null, 'children');
     return $this->arrayManager->merge($namePath . static::META_CONFIG_PATH, $meta, ['valueUpdate' => 'keyup']);
 }
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->locatorMock = $this->getMockBuilder(LocatorInterface::class)->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getStoreId', 'getResource', 'getData', 'getAttributes', 'getStore', 'getAttributeDefaultValue', 'getExistsStoreValueFlag'])->getMockForAbstractClass();
     $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['load', 'getId', 'getConfig'])->getMockForAbstractClass();
     $this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)->disableOriginalConstructor()->getMock();
     $this->arrayManagerMock->expects($this->any())->method('replace')->willReturnArgument(1);
     $this->arrayManagerMock->expects($this->any())->method('get')->willReturnArgument(2);
     $this->arrayManagerMock->expects($this->any())->method('set')->willReturnArgument(1);
     $this->arrayManagerMock->expects($this->any())->method('merge')->willReturnArgument(1);
     $this->arrayManagerMock->expects($this->any())->method('remove')->willReturnArgument(1);
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->locatorMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
 }
 /**
  * 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;
 }
Example #30
0
 /**
  * Get option info
  *
  * @return array
  */
 protected function getOptionInfo()
 {
     $result = ['arguments' => ['data' => ['config' => ['formElement' => 'container', 'componentType' => Container::NAME, 'component' => 'Magento_Ui/js/form/components/group', 'showLabel' => false, 'additionalClasses' => 'admin__field-group-columns admin__control-group-equal', 'breakLine' => false, 'sortOrder' => 10]]], 'children' => ['type' => ['arguments' => ['data' => ['config' => ['dataType' => Form\Element\DataType\Text::NAME, 'formElement' => Form\Element\Select::NAME, 'componentType' => Form\Field::NAME, 'component' => 'Magento_Bundle/js/components/bundle-input-type', 'parentContainer' => 'product_bundle_container', 'selections' => 'bundle_selections', 'isDefaultIndex' => 'is_default', 'userDefinedIndex' => 'selection_can_change_qty', 'dataScope' => 'type', 'label' => __('Input Type'), 'sortOrder' => 20, 'options' => [['label' => __('Drop-down'), 'value' => 'select'], ['label' => __('Radio Buttons'), 'value' => 'radio'], ['label' => __('Checkbox'), 'value' => 'checkbox'], ['label' => __('Multiple Select'), 'value' => 'multi']], 'typeMap' => ['select' => 'radio', 'radio' => 'radio', 'checkbox' => 'checkbox', 'multi' => 'checkbox']]]]], 'required' => ['arguments' => ['data' => ['config' => ['dataType' => Form\Element\DataType\Number::NAME, 'formElement' => Form\Element\Checkbox::NAME, 'componentType' => Form\Field::NAME, 'description' => __('Required'), 'dataScope' => 'required', 'label' => ' ', 'value' => '1', 'valueMap' => ['true' => '1', 'false' => '0'], 'sortOrder' => 30]]]]]];
     return $this->arrayManager->merge('children', $result, $this->getTitleConfiguration());
 }