コード例 #1
0
ファイル: Msrp.php プロジェクト: Doability/magento2dev
 /**
  * Customize msrp field
  *
  * @return $this
  */
 protected function customizeMsrp()
 {
     $msrpPath = $this->arrayManager->findPath(static::FIELD_MSRP, $this->meta, null, 'children');
     if ($msrpPath) {
         if ($this->msrpConfig->isEnabled()) {
             $this->meta = $this->arrayManager->merge($msrpPath . '/arguments/data/config', $this->meta, ['addbefore' => $this->locator->getStore()->getBaseCurrency()->getCurrencySymbol(), 'validation' => ['validate-zero-or-greater' => true]]);
         } else {
             $this->meta = $this->arrayManager->remove($this->arrayManager->slicePath($msrpPath, 0, -2), $this->meta);
         }
     }
     return $this;
 }
コード例 #2
0
ファイル: Related.php プロジェクト: Doability/magento2dev
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $productId = $product->getId();
     if (!$productId) {
         return $data;
     }
     $priceModifier = $this->getPriceModifier();
     /**
      * Set field name for modifier
      */
     $priceModifier->setData('name', 'price');
     foreach ($this->getDataScopes() as $dataScope) {
         $data[$productId]['links'][$dataScope] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== $dataScope) {
                 continue;
             }
             /** @var \Magento\Catalog\Model\Product $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId());
             $data[$productId]['links'][$dataScope][] = $this->fillData($linkedProduct, $linkItem);
         }
         if (!empty($data[$productId]['links'][$dataScope])) {
             $dataMap = $priceModifier->prepareDataSource(['data' => ['items' => $data[$productId]['links'][$dataScope]]]);
             $data[$productId]['links'][$dataScope] = $dataMap['data']['items'];
         }
     }
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId();
     return $data;
 }
コード例 #3
0
ファイル: Eav.php プロジェクト: rafaelstz/magento2
 /**
  * Customize attribute that has price type
  *
  * @param ProductAttributeInterface $attribute
  * @param array $meta
  * @return array
  */
 private function customizePriceAttribute(ProductAttributeInterface $attribute, array $meta)
 {
     if ($attribute->getFrontendInput() === 'price') {
         $meta['arguments']['data']['config']['addbefore'] = $this->locator->getStore()->getBaseCurrency()->getCurrencySymbol();
     }
     return $meta;
 }
コード例 #4
0
 /**
  * Customize Weight filed
  *
  * @param array $meta
  * @return array
  */
 protected function customizeWeightField(array $meta)
 {
     if ($weightPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_WEIGHT)) {
         if ($this->locator->getProduct()->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL) {
             $weightPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_WEIGHT);
             $meta = $this->arrayManager->merge($weightPath, $meta, ['arguments' => ['data' => ['config' => ['dataScope' => ProductAttributeInterface::CODE_WEIGHT, 'validation' => ['validate-number' => true], 'additionalClasses' => 'admin__field-small', 'addafter' => $this->locator->getStore()->getConfig('general/locale/weight_unit'), 'imports' => ['disabled' => '!${$.provider}:' . self::DATA_SCOPE_PRODUCT . '.product_has_weight:value']]]]]);
             $containerPath = $this->getElementArrayPath($meta, static::CONTAINER_PREFIX . ProductAttributeInterface::CODE_WEIGHT);
             $meta = $this->arrayManager->merge($containerPath, $meta, ['arguments' => ['data' => ['config' => ['component' => 'Magento_Ui/js/form/components/group']]]]);
             $hasWeightPath = $this->arrayManager->slicePath($weightPath, 0, -1) . '/' . ProductAttributeInterface::CODE_HAS_WEIGHT;
             $meta = $this->arrayManager->set($hasWeightPath, $meta, ['arguments' => ['data' => ['config' => ['dataType' => 'boolean', 'formElement' => Form\Element\Select::NAME, 'componentType' => Form\Field::NAME, 'dataScope' => 'product_has_weight', 'label' => '', 'options' => [['label' => __('This item has weight'), 'value' => 1], ['label' => __('This item has no weight'), 'value' => 0]], 'value' => (int) $this->locator->getProduct()->getTypeInstance()->hasWeight()]]]]);
         }
     }
     return $meta;
 }
コード例 #5
0
ファイル: General.php プロジェクト: rafaelstz/magento2
 /**
  * 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']);
 }
コード例 #6
0
 /**
  * Prepare variations
  *
  * @return void
  * @throws \Zend_Currency_Exception
  */
 protected function prepareVariations()
 {
     $variations = $this->getVariations();
     $productMatrix = [];
     $attributes = [];
     $productIds = [];
     if ($variations) {
         $usedProductAttributes = $this->getUsedAttributes();
         $productByUsedAttributes = $this->getAssociatedProducts();
         $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode());
         $configurableAttributes = $this->getAttributes();
         foreach ($variations as $variation) {
             $attributeValues = [];
             foreach ($usedProductAttributes as $attribute) {
                 $attributeValues[$attribute->getAttributeCode()] = $variation[$attribute->getId()]['value'];
             }
             $key = implode('-', $attributeValues);
             if (isset($productByUsedAttributes[$key])) {
                 $product = $productByUsedAttributes[$key];
                 $price = $product->getPrice();
                 $variationOptions = [];
                 foreach ($usedProductAttributes as $attribute) {
                     if (!isset($attributes[$attribute->getAttributeId()])) {
                         $attributes[$attribute->getAttributeId()] = ['code' => $attribute->getAttributeCode(), 'label' => $attribute->getStoreLabel(), 'id' => $attribute->getAttributeId(), 'position' => $configurableAttributes[$attribute->getAttributeId()]['position'], 'chosen' => []];
                         foreach ($attribute->getOptions() as $option) {
                             if (!empty($option->getValue())) {
                                 $attributes[$attribute->getAttributeId()]['options'][$option->getValue()] = ['attribute_code' => $attribute->getAttributeCode(), 'attribute_label' => $attribute->getStoreLabel(0), 'id' => $option->getValue(), 'label' => $option->getLabel(), 'value' => $option->getValue()];
                             }
                         }
                     }
                     $optionId = $variation[$attribute->getId()]['value'];
                     $variationOption = ['attribute_code' => $attribute->getAttributeCode(), 'attribute_label' => $attribute->getStoreLabel(0), 'id' => $optionId, 'label' => $variation[$attribute->getId()]['label'], 'value' => $optionId];
                     $variationOptions[] = $variationOption;
                     $attributes[$attribute->getAttributeId()]['chosen'][$optionId] = $variationOption;
                 }
                 $productMatrix[] = ['id' => $product->getId(), 'product_link' => '<a href="' . $this->urlBuilder->getUrl('catalog/product/edit', ['id' => $product->getId()]) . '" target="_blank">' . $product->getName() . '</a>', 'sku' => $product->getSku(), 'name' => $product->getName(), 'qty' => $this->getProductStockQty($product), 'price' => $currency->toCurrency(sprintf("%f", $price), ['display' => false]), 'price_string' => $currency->toCurrency(sprintf("%f", $price)), 'price_currency' => $this->locator->getStore()->getBaseCurrency()->getCurrencySymbol(), 'configurable_attribute' => $this->getJsonConfigurableAttributes($variationOptions), 'weight' => $product->getWeight(), 'status' => $product->getStatus(), 'variationKey' => $this->getVariationKey($variationOptions), 'canEdit' => 0, 'newProduct' => 0, 'attributes' => $this->getTextAttributes($variationOptions), 'thumbnail_image' => $this->imageHelper->init($product, 'product_thumbnail_image')->getUrl()];
                 $productIds[] = $product->getId();
             }
         }
     }
     $this->productMatrix = $productMatrix;
     $this->productIds = $productIds;
     $this->productAttributes = array_values($attributes);
 }
コード例 #7
0
ファイル: Grouped.php プロジェクト: Doability/magento2dev
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $modelId = $product->getId();
     if ($modelId) {
         $storeId = $this->locator->getStore()->getId();
         $data[$product->getId()]['links'][self::LINK_TYPE] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== self::LINK_TYPE) {
                 continue;
             }
             /** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId);
             $data[$modelId]['links'][self::LINK_TYPE][] = $this->fillData($linkedProduct, $linkItem);
         }
         $data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId;
     }
     return $data;
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $modelId = $product->getId();
     if ($modelId) {
         $storeId = $this->locator->getStore()->getId();
         /** @var \Magento\Framework\Currency $currency */
         $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode());
         $data[$product->getId()]['links'][self::LINK_TYPE] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== self::LINK_TYPE) {
                 continue;
             }
             /** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId);
             $data[$modelId]['links'][self::LINK_TYPE][] = ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()];
         }
         $data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId;
     }
     return $data;
 }
コード例 #9
0
ファイル: Related.php プロジェクト: rafaelstz/magento2
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $productId = $product->getId();
     if (!$productId) {
         return $data;
     }
     foreach ($this->getDataScopes() as $dataScope) {
         $data[$productId]['links'][$dataScope] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== $dataScope) {
                 continue;
             }
             /** @var \Magento\Catalog\Model\Product $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId());
             $data[$productId]['links'][$dataScope][] = $this->fillData($linkedProduct, $linkItem);
         }
     }
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId();
     return $data;
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function modifyData(array $data)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->locator->getProduct();
     $productId = $product->getId();
     if (!$productId) {
         return $data;
     }
     foreach ($this->getDataScopes() as $dataScope) {
         $data[$productId]['links'][$dataScope] = [];
         foreach ($this->productLinkRepository->getList($product) as $linkItem) {
             if ($linkItem->getLinkType() !== $dataScope) {
                 continue;
             }
             /** @var \Magento\Catalog\Model\Product $linkedProduct */
             $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId());
             $data[$productId]['links'][$dataScope][] = ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()];
         }
     }
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;
     $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId();
     return $data;
 }
コード例 #11
0
ファイル: Categories.php プロジェクト: Doability/magento2dev
 /**
  * Retrieve categories tree
  *
  * @param string|null $filter
  * @return array
  */
 protected function getCategoriesTree($filter = null)
 {
     if (isset($this->categoriesTrees[$filter])) {
         return $this->categoriesTrees[$filter];
     }
     $storeId = $this->locator->getStore()->getId();
     /* @var $matchingNamesCollection \Magento\Catalog\Model\ResourceModel\Category\Collection */
     $matchingNamesCollection = $this->categoryCollectionFactory->create();
     if ($filter !== null) {
         $matchingNamesCollection->addAttributeToFilter('name', ['like' => $this->dbHelper->addLikeEscape($filter, ['position' => 'any'])]);
     }
     $matchingNamesCollection->addAttributeToSelect('path')->addAttributeToFilter('entity_id', ['neq' => CategoryModel::TREE_ROOT_ID])->setStoreId($storeId);
     $shownCategoriesIds = [];
     /** @var \Magento\Catalog\Model\Category $category */
     foreach ($matchingNamesCollection as $category) {
         foreach (explode('/', $category->getPath()) as $parentId) {
             $shownCategoriesIds[$parentId] = 1;
         }
     }
     /* @var $collection \Magento\Catalog\Model\ResourceModel\Category\Collection */
     $collection = $this->categoryCollectionFactory->create();
     $collection->addAttributeToFilter('entity_id', ['in' => array_keys($shownCategoriesIds)])->addAttributeToSelect(['name', 'is_active', 'parent_id'])->setStoreId($storeId);
     $categoryById = [CategoryModel::TREE_ROOT_ID => ['value' => CategoryModel::TREE_ROOT_ID, 'optgroup' => null]];
     foreach ($collection as $category) {
         foreach ([$category->getId(), $category->getParentId()] as $categoryId) {
             if (!isset($categoryById[$categoryId])) {
                 $categoryById[$categoryId] = ['value' => $categoryId];
             }
         }
         $categoryById[$category->getId()]['is_active'] = $category->getIsActive();
         $categoryById[$category->getId()]['label'] = $category->getName();
         $categoryById[$category->getParentId()]['optgroup'][] =& $categoryById[$category->getId()];
     }
     $this->categoriesTrees[$filter] = $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];
     return $this->categoriesTrees[$filter];
 }
コード例 #12
0
ファイル: Links.php プロジェクト: Doability/magento2dev
 /**
  * @return array
  */
 protected function getPriceColumn()
 {
     $priceContainer['arguments']['data']['config'] = ['componentType' => Container::NAME, 'formElement' => Container::NAME, 'component' => 'Magento_Ui/js/form/components/group', 'label' => __('Price'), 'dataScope' => ''];
     $priceField['arguments']['data']['config'] = ['formElement' => Form\Element\Input::NAME, 'componentType' => Form\Field::NAME, 'dataType' => Form\Element\DataType\Number::NAME, 'component' => 'Magento_Downloadable/js/components/price-handler', 'dataScope' => 'price', 'addbefore' => $this->locator->getStore()->getBaseCurrency()->getCurrencySymbol(), 'validation' => ['validate-zero-or-greater' => true], 'imports' => ['linksPurchasedSeparately' => '${$.provider}:data.product' . '.links_purchased_separately', 'useDefaultPrice' => '${$.parentName}.use_default_price:checked']];
     return $this->arrayManager->set('children/link_price', $priceContainer, $priceField);
 }
コード例 #13
0
 /**
  * Retrieve store
  *
  * @return \Magento\Store\Model\Store
  */
 protected function getStore()
 {
     return $this->locator->getStore();
 }
コード例 #14
0
ファイル: Attributes.php プロジェクト: rafaelstz/magento2
 /**
  * @param array $meta
  * @return array
  */
 private function customizeCreateAttributeModal(array $meta)
 {
     $params = ['group' => static::GROUP_CODE, 'groupName' => self::GROUP_NAME, 'groupSortOrder' => self::GROUP_SORT_ORDER, 'store' => $this->locator->getStore()->getId(), 'product' => $this->locator->getProduct()->getId(), 'type' => $this->locator->getProduct()->getTypeId(), 'set' => $this->locator->getProduct()->getAttributeSetId(), 'message_key' => 'messages', 'popup' => 1];
     $meta['add_attribute_modal']['children']['create_new_attribute_modal'] = ['arguments' => ['data' => ['config' => ['isTemplate' => false, 'componentType' => Component\Modal::NAME, 'dataScope' => 'data.new_attribute', 'provider' => 'product_form.product_form_data_source', 'options' => ['title' => __('New Attribute')], 'imports' => ['state' => '!index=product_attribute_add_form:responseStatus']]]], 'children' => ['product_attribute_add_form' => ['arguments' => ['data' => ['config' => ['label' => __('New Attribute'), 'componentType' => Component\Container::NAME, 'component' => 'Magento_Catalog/js/components/new-attribute-insert-form', 'dataScope' => '', 'update_url' => $this->urlBuilder->getUrl('mui/index/render'), 'render_url' => $this->urlBuilder->getUrl('mui/index/render_handle', ['handle' => 'catalog_product_attribute_edit_form', 'buttons' => 1]), 'autoRender' => false, 'ns' => 'product_attribute_add_form', 'externalProvider' => 'product_attribute_add_form' . '.product_attribute_add_form_data_source', 'toolbarContainer' => '${ $.parentName }', 'formSubmitType' => 'ajax', 'saveUrl' => $this->urlBuilder->getUrl('catalog/product_attribute/save', $params), 'validateUrl' => $this->urlBuilder->getUrl('catalog/product_attribute/validate', $params), 'productId' => $this->locator->getProduct()->getId(), 'productType' => $this->locator->getProduct()->getTypeId(), 'imports' => ['attributeSetId' => '${ $.provider }:data.product.attribute_set_id'], 'exports' => ['saveUrl' => '${ $.externalProvider }:client.urls.save', 'validateUrl' => '${ $.externalProvider }:client.urls.beforeSave', 'attributeSetId' => '${ $.externalProvider }:params.set']]]]]]];
     return $meta;
 }