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


PHP Entity\MetadataPool类代码示例

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


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

示例1: testHydrator

 public function testHydrator()
 {
     $metadataPool = new MetadataPool($this->entityMetadataFactoryMock, $this->entityHydratorFactoryMock, []);
     $entityHydrator = $this->getMockBuilder(EntityHydrator::class)->disableOriginalConstructor()->getMock();
     $this->entityHydratorFactoryMock->expects($this->once())->method('create')->willReturn($entityHydrator);
     $this->assertEquals($entityHydrator, $metadataPool->getHydrator('testType'));
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:7,代码来源:MetadataPoolTest.php

示例2: __construct

 /**
  * @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository
  * @param \Magento\Catalog\Model\ResourceModel\Attribute $attributeResource
  * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
  * @param \Magento\Framework\App\State $appState
  * @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
  */
 public function __construct(\Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository, \Magento\Catalog\Model\ResourceModel\Attribute $attributeResource, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Framework\App\State $appState, \Magento\Framework\Model\Entity\MetadataPool $metadataPool)
 {
     $this->productAttributeRepository = $productAttributeRepository;
     $this->searchCriteriaBuilder = $searchCriteriaBuilder;
     $this->attributeResource = $attributeResource;
     $this->appState = $appState;
     $this->metadata = $metadataPool->getMetadata(ProductInterface::class);
     parent::__construct();
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:16,代码来源:ProductAttributesCleanUp.php

示例3: __construct

 /**
  * @param ResourceConnection $resource
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
  */
 public function __construct(ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, MetadataPool $metadataPool, $skipStaticColumns = [])
 {
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->storeManager = $storeManager;
     $this->resourceHelper = $resourceHelper;
     $this->skipStaticColumns = $skipStaticColumns;
     $this->columns = array_merge($this->getStaticColumns(), $this->getEavColumns());
     $this->categoryMetadata = $metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:15,代码来源:AbstractAction.php

示例4: setUp

 protected function setUp()
 {
     $helper = new ObjectManager($this);
     $this->resource = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->setMethods(['select', 'fetchOne'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['reset', 'from', 'join', 'where', 'group', 'limit'])->disableOriginalConstructor()->getMock();
     $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
     $this->metadataPoolMock->expects(self::once())->method('getMetadata')->with(ProductInterface::class)->willReturn($this->getMetaDataMock());
     $this->model = $helper->getObject('Magento\\ConfigurableProduct\\Model\\Attribute\\LockValidator', ['resource' => $this->resource, 'metadataPool' => $this->metadataPoolMock]);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:10,代码来源:LockValidatorTest.php

示例5: __construct

 /**
  * @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
  * @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
  * @param \Magento\Catalog\Model\ResourceModel\Product\Gallery $resourceModel
  * @param \Magento\Framework\Json\Helper\Data $jsonHelper
  * @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb
  */
 public function __construct(\Magento\Framework\Model\Entity\MetadataPool $metadataPool, \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository, \Magento\Catalog\Model\ResourceModel\Product\Gallery $resourceModel, \Magento\Framework\Json\Helper\Data $jsonHelper, \Magento\Catalog\Model\Product\Media\Config $mediaConfig, \Magento\Framework\Filesystem $filesystem, \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb)
 {
     $this->metadata = $metadataPool->getMetadata('Magento\\Catalog\\Api\\Data\\ProductInterface');
     $this->attributeRepository = $attributeRepository;
     $this->resourceModel = $resourceModel;
     $this->jsonHelper = $jsonHelper;
     $this->mediaConfig = $mediaConfig;
     $this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
     $this->fileStorageDb = $fileStorageDb;
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:19,代码来源:CreateHandler.php

示例6: setUp

 protected function setUp()
 {
     $this->connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], '', false, false, true, []);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $metadata->expects($this->any())->method('getLinkField')->willReturn('entity_id');
     $metadata->expects($this->any())->method('getEntityTable')->willReturn('entity_table');
     $metadata->expects($this->any())->method('getEntityConnection')->willReturn($this->connection);
     $this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->metadataPool->expects($this->any())->method('getMetadata')->with('Test\\Entity\\Type')->willReturn($metadata);
     $this->subject = new \Magento\Framework\Model\ResourceModel\Db\DeleteEntityRow($this->metadataPool);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:11,代码来源:DeleteEntityRowTest.php

示例7: 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

示例8: 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

示例9: testExecute

 public function testExecute()
 {
     $entityId = 1;
     $linkId = 2;
     $oldStore = 1;
     $newStore = 2;
     $linkField = 'link_id';
     $adapter = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMockForAbstractClass();
     $whereForDelete = [$linkField . ' = ?' => $linkId, 'store_id IN (?)' => [$oldStore]];
     $adapter->expects($this->once())->method('delete')->with('cms_page_store', $whereForDelete)->willReturnSelf();
     $whereForInsert = [$linkField => $linkId, 'store_id' => $newStore];
     $adapter->expects($this->once())->method('insertMultiple')->with('cms_page_store', [$whereForInsert])->willReturnSelf();
     $entityMetadata = $this->getMockBuilder('Magento\\Framework\\Model\\Entity\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $entityMetadata->expects($this->once())->method('getEntityConnection')->willReturn($adapter);
     $entityMetadata->expects($this->once())->method('getLinkField')->willReturn($linkField);
     $this->metadataPool->expects($this->once())->method('getMetadata')->with('Magento\\Cms\\Model\\Page')->willReturn($entityMetadata);
     $this->resourcePage->expects($this->once())->method('lookupStoreIds')->willReturn([$oldStore]);
     $this->resourcePage->expects($this->once())->method('getTable')->with('cms_page_store')->willReturn('cms_page_store');
     $page = $this->getMockBuilder('Magento\\Cms\\Model\\Page')->disableOriginalConstructor()->setMethods(['getStores', 'getStoreId', 'getId', 'getData'])->getMock();
     $page->expects($this->once())->method('getStores')->willReturn(null);
     $page->expects($this->once())->method('getStoreId')->willReturn($newStore);
     $page->expects($this->once())->method('getId')->willReturn($entityId);
     $page->expects($this->exactly(2))->method('getData')->with($linkField)->willReturn($linkId);
     $result = $this->model->execute('Magento\\Cms\\Model\\Page', $page);
     $this->assertInstanceOf('Magento\\Cms\\Model\\Page', $result);
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:26,代码来源:SaveHandlerTest.php

示例10: 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

示例11: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @param array $data
  * @return object
  */
 public function execute($entityType, $entity, $data = [])
 {
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $entityData = $this->createEntityRow->execute($entityType, array_merge($hydrator->extract($entity), $data));
     $entity = $hydrator->hydrate($entity, $entityData);
     return $entity;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:13,代码来源:CreateMain.php

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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