当前位置: 首页>>代码示例>>PHP>>正文


PHP MetadataPool::getMetadata方法代码示例

本文整理汇总了PHP中Magento\Framework\Model\Entity\MetadataPool::getMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP MetadataPool::getMetadata方法的具体用法?PHP MetadataPool::getMetadata怎么用?PHP MetadataPool::getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Model\Entity\MetadataPool的用法示例。


在下文中一共展示了MetadataPool::getMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * @param string $entityType
  * @param array $entityData
  * @return array
  * @throws \Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function execute($entityType, $entityData)
 {
     $data = [];
     $metadata = $this->metadataPool->getMetadata($entityType);
     /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
     $attributeTables = [];
     if ($metadata->getEavEntityType()) {
         $context = $this->getActionContext($entityType, $entityData);
         foreach ($this->getAttributes($entityType) as $attribute) {
             if (!$attribute->isStatic()) {
                 $attributeTables[$attribute->getBackend()->getTable()][] = $attribute->getAttributeId();
             }
         }
         $selects = [];
         foreach ($attributeTables as $attributeTable => $attributeCodes) {
             $select = $metadata->getEntityConnection()->select()->from(['t' => $attributeTable], ['value' => 't.value'])->join(['a' => $this->appResource->getTableName('eav_attribute')], 'a.attribute_id = t.attribute_id', ['attribute_code' => 'a.attribute_code'])->where($metadata->getLinkField() . ' = ?', $entityData[$metadata->getLinkField()])->where('t.attribute_id IN (?)', $attributeCodes)->order('a.attribute_id');
             foreach ($context as $field => $value) {
                 //TODO: if (in table exists context field)
                 $select->where($metadata->getEntityConnection()->quoteIdentifier($field) . ' IN (?)', $value)->order('t.' . $field . ' DESC');
             }
             $selects[] = $select;
         }
         $unionSelect = new \Magento\Framework\DB\Sql\UnionExpression($selects, \Magento\Framework\DB\Select::SQL_UNION_ALL);
         $attributeValues = $metadata->getEntityConnection()->fetchAll((string) $unionSelect);
         foreach ($attributeValues as $attributeValue) {
             $data[$attributeValue['attribute_code']] = $attributeValue['value'];
         }
     }
     return $data;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:37,代码来源:ReadHandler.php

示例2: save

 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
 {
     $storeId = (int) $this->storeManager->getStore()->getId();
     $existingData = $this->getExtensibleDataObjectConverter()->toNestedArray($category, [], 'Magento\\Catalog\\Api\\Data\\CategoryInterface');
     $existingData = array_diff_key($existingData, array_flip(['path', 'level', 'parent_id']));
     $existingData['store_id'] = $storeId;
     if ($category->getId()) {
         $metadata = $this->metadataPool->getMetadata(CategoryInterface::class);
         $category = $this->get($category->getId(), $storeId);
         $existingData[$metadata->getLinkField()] = $category->getData($metadata->getLinkField());
         if (isset($existingData['image']) && is_array($existingData['image'])) {
             $existingData['image_additional_data'] = $existingData['image'];
             unset($existingData['image']);
         }
     } else {
         $parentId = $category->getParentId() ?: $this->storeManager->getStore()->getRootCategoryId();
         $parentCategory = $this->get($parentId, $storeId);
         $existingData['path'] = $parentCategory->getPath();
         $existingData['parent_id'] = $parentId;
     }
     $category->addData($existingData);
     try {
         $this->validateCategory($category);
         $this->categoryResource->save($category);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not save category: %1', $e->getMessage()), $e);
     }
     unset($this->instances[$category->getId()]);
     return $this->get($category->getId(), $storeId);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:33,代码来源:CategoryRepository.php

示例3: saveProducts

 /**
  * Save configurable product relations
  *
  * @param \Magento\Catalog\Model\Product $mainProduct the parent id
  * @param array $productIds the children id array
  * @return $this
  */
 public function saveProducts($mainProduct, $productIds)
 {
     $isProductInstance = false;
     if ($mainProduct instanceof \Magento\Catalog\Model\Product) {
         $mainProductId = $mainProduct->getId();
         $isProductInstance = true;
     }
     $old = [];
     if (!$mainProduct->getIsDuplicate()) {
         $old = $mainProduct->getTypeInstance()->getUsedProductIds($mainProduct);
     }
     $insert = array_diff($productIds, $old);
     $delete = array_diff($old, $productIds);
     if ((!empty($insert) || !empty($delete)) && $isProductInstance) {
         $mainProduct->setIsRelationsChanged(true);
     }
     if (!empty($delete)) {
         $where = ['parent_id = ?' => $mainProductId, 'product_id IN(?)' => $delete];
         $this->getConnection()->delete($this->getMainTable(), $where);
     }
     if (!empty($insert)) {
         $data = [];
         foreach ($insert as $childId) {
             $data[] = ['product_id' => (int) $childId, 'parent_id' => (int) $mainProductId];
         }
         $this->getConnection()->insertMultiple($this->getMainTable(), $data);
     }
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     // configurable product relations should be added to relation table
     $this->_catalogProductRelation->processRelations($mainProduct->getData($linkField), $productIds);
     return $this;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:39,代码来源:Configurable.php

示例4: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  */
 public function execute($entityType, $entity)
 {
     $entityMetadata = $this->metadataPool->getMetadata($entityType);
     $linkField = $entityMetadata->getLinkField();
     $connection = $entityMetadata->getEntityConnection();
     $oldStores = $this->resourcePage->lookupStoreIds((int) $entity->getId());
     $newStores = (array) $entity->getStores();
     if (empty($newStores)) {
         $newStores = (array) $entity->getStoreId();
     }
     $table = $this->resourcePage->getTable('cms_page_store');
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $where = [$linkField . ' = ?' => (int) $entity->getData($linkField), 'store_id IN (?)' => $delete];
         $connection->delete($table, $where);
     }
     $insert = array_diff($newStores, $oldStores);
     if ($insert) {
         $data = [];
         foreach ($insert as $storeId) {
             $data[] = [$linkField => (int) $entity->getData($linkField), 'store_id' => (int) $storeId];
         }
         $connection->insertMultiple($table, $data);
     }
     return $entity;
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:31,代码来源:SaveHandler.php

示例5: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  * @throws CouldNotSaveException
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     /**
      * @var $entity \Magento\Catalog\Api\Data\ProductLinkInterface
      */
     $linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());
     $product = $this->productRepository->get($entity->getSku());
     $links = [];
     $extensions = $this->dataObjectProcessor->buildOutputDataArray($entity->getExtensionAttributes(), 'Magento\\Catalog\\Api\\Data\\ProductLinkExtensionInterface');
     $extensions = is_array($extensions) ? $extensions : [];
     $data = $entity->__toArray();
     foreach ($extensions as $attributeCode => $attribute) {
         $data[$attributeCode] = $attribute;
     }
     unset($data['extension_attributes']);
     $data['product_id'] = $linkedProduct->getId();
     $links[$linkedProduct->getId()] = $data;
     try {
         $linkTypesToId = $this->linkTypeProvider->getLinkTypes();
         $prodyctHydrator = $this->metadataPool->getHydrator(ProductInterface::class);
         $productData = $prodyctHydrator->extract($product);
         $this->linkResource->saveProductLinks($productData[$this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()], $links, $linkTypesToId[$entity->getLinkType()]);
     } catch (\Exception $exception) {
         throw new CouldNotSaveException(__('Invalid data provided for linked products'));
     }
     return $entity;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:34,代码来源:SaveHandler.php

示例6: install

 /**
  * {@inheritdoc}
  */
 public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
 {
     $installer = $setup;
     $installer->startSetup();
     $metadata = $this->metadataPool->getMetadata(CategoryInterface::class);
     $this->externalFKSetup->install($installer, $metadata->getEntityTable(), $metadata->getIdentifierField(), ResourceProduct::TABLE_NAME, 'category_id');
     $installer->endSetup();
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:11,代码来源:Recurring.php

示例7: execute

 /**
  * @param string $entityType
  * @param array $entityData
  * @return array
  * @throws \Exception
  */
 public function execute($entityType, $entityData)
 {
     $linkField = $this->metadataPool->getMetadata($entityType)->getLinkField();
     $entityId = $entityData[$linkField];
     $entityData['customer_group_ids'] = $this->ruleResource->getCustomerGroupIds($entityId);
     $entityData['website_ids'] = $this->ruleResource->getWebsiteIds($entityId);
     return $entityData;
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:14,代码来源:ReadHandler.php

示例8: execute

 /**
  * {@inheritdoc}
  */
 public function execute($entityType, $entity, $identifier)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $entity = $this->readMain->execute($entityType, $entity, $identifier);
     if (isset($entity[$metadata->getLinkField()])) {
         $entity = $this->readExtension->execute($entityType, $entity);
         $entity = $this->readRelation->execute($entityType, $entity);
     }
     return $entity;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:13,代码来源:Read.php

示例9: execute

 /**
  * @param string $entityType
  * @param array $data
  * @return array
  */
 public function execute($entityType, $data)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $linkField = $metadata->getLinkField();
     $entityTable = $metadata->getEntityTable();
     $connection = $metadata->getEntityConnection();
     $connection->insert($entityTable, $this->prepareData($metadata, $data));
     $data[$linkField] = $connection->lastInsertId($entityTable);
     return $data;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:15,代码来源:CreateEntityRow.php

示例10: getAttributes

 /**
  * Returns array of fields
  *
  * @param string $entityType
  * @return array
  * @throws \Exception
  */
 public function getAttributes($entityType)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->create());
     $attributes = [];
     foreach ($searchResult->getItems() as $attribute) {
         $attributes[] = $attribute->getAttributeCode();
     }
     return $attributes;
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:17,代码来源:AttributeProvider.php

示例11: execute

 /**
  * @param string $entityType
  * @param string $identifier
  * @param array $context
  * @return array
  * @throws \Exception
  */
 public function execute($entityType, $identifier, $context = [])
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $select = $metadata->getEntityConnection()->select()->from(['t' => $metadata->getEntityTable()])->where($metadata->getIdentifierField() . ' = ?', $identifier);
     foreach ($context as $field => $value) {
         $select->where($metadata->getEntityConnection()->quoteIdentifier($field) . ' = ?', $value);
     }
     $data = $metadata->getEntityConnection()->fetchRow($select);
     return $data ?: [];
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:17,代码来源:ReadEntityRow.php

示例12: save

 /**
  * @param string $entityType
  * @param object $entity
  * @return bool|object
  * @throws \Exception
  */
 public function save($entityType, $entity)
 {
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $metadata = $this->metadataPool->getMetadata($entityType);
     $entityData = $hydrator->extract($entity);
     if (!empty($entityData[$metadata->getIdentifierField()]) && $metadata->checkIsEntityExists($entityData[$metadata->getIdentifierField()])) {
         $operation = $this->orchestratorPool->getWriteOperation($entityType, 'update');
     } else {
         $operation = $this->orchestratorPool->getWriteOperation($entityType, 'create');
     }
     return $operation->execute($entityType, $entity);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:18,代码来源:EntityManager.php

示例13: getCollection

 /**
  * Retrieve cms page collection array
  *
  * @param int $storeId
  * @return array
  */
 public function getCollection($storeId)
 {
     $entityMetadata = $this->metadataPool->getMetadata(PageInterface::class);
     $linkField = $entityMetadata->getLinkField();
     $select = $this->getConnection()->select()->from(['main_table' => $this->getMainTable()], [$this->getIdFieldName(), 'url' => 'identifier', 'updated_at' => 'update_time'])->join(['store_table' => $this->getTable('cms_page_store')], "main_table.{$linkField} = store_table.{$linkField}", [])->where('main_table.is_active = 1')->where('main_table.identifier != ?', \Magento\Cms\Model\Page::NOROUTE_PAGE_ID)->where('store_table.store_id IN(?)', [0, $storeId]);
     $pages = [];
     $query = $this->getConnection()->query($select);
     while ($row = $query->fetch()) {
         $page = $this->_prepareObject($row);
         $pages[$page->getId()] = $page;
     }
     return $pages;
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:19,代码来源:Page.php

示例14: doesEntityHaveOverriddenUrlAttributeForStore

 /**
  * Check that entity has overridden url attribute for specific store
  *
  * @param int $storeId
  * @param int $entityId
  * @param string $entityType
  * @param mixed $attributeName
  * @throws \InvalidArgumentException
  * @return bool
  */
 protected function doesEntityHaveOverriddenUrlAttributeForStore($storeId, $entityId, $entityType, $attributeName)
 {
     $attribute = $this->eavConfig->getAttribute($entityType, $attributeName);
     if (!$attribute) {
         throw new \InvalidArgumentException(sprintf('Cannot retrieve attribute for entity type "%s"', $entityType));
     }
     $linkFieldName = $attribute->getEntity()->getLinkField();
     if (!$linkFieldName) {
         $linkFieldName = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     }
     $select = $this->connection->select()->from(['e' => $attribute->getEntity()->getEntityTable()], [])->join(['e_attr' => $attribute->getBackendTable()], "e.{$linkFieldName} = e_attr.{$linkFieldName}", 'store_id')->where('e_attr.attribute_id = ?', $attribute->getId())->where('e.entity_id = ?', $entityId);
     return in_array($storeId, $this->connection->fetchCol($select));
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:23,代码来源:StoreViewService.php

示例15: addProductToFilter

 /**
  * Method for product filter
  *
  * @param \Magento\Catalog\Model\Product|array|int|null $product
  * @return $this
  */
 public function addProductToFilter($product)
 {
     if (empty($product)) {
         $this->addFieldToFilter('product_id', '');
     } else {
         $this->join(['cpe' => $this->getTable('catalog_product_entity')], sprintf('cpe.%s = main_table.product_id', $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()));
         if (is_array($product)) {
             $this->addFieldToFilter('cpe.entity_id', ['in' => $product]);
         } else {
             $this->addFieldToFilter('cpe.entity_id', $product);
         }
     }
     return $this;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:20,代码来源:Collection.php


注:本文中的Magento\Framework\Model\Entity\MetadataPool::getMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。