本文整理汇总了PHP中Magento\Framework\Model\Entity\MetadataPool类的典型用法代码示例。如果您正苦于以下问题:PHP MetadataPool类的具体用法?PHP MetadataPool怎么用?PHP MetadataPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetadataPool类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: setUp
protected function setUp()
{
$connectionMock = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock();
$this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
$this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
$this->relation = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Relation', [], [], '', false);
$metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
$this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
$this->metadataPool->expects($this->any())->method('getMetadata')->with(\Magento\Catalog\Api\Data\ProductInterface::class)->willReturn($metadata);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable', ['resource' => $this->resource, 'catalogProductRelation' => $this->relation, 'metadataPool' => $this->metadataPool]);
}
开发者ID:dragonsword007008,项目名称:magento2,代码行数:12,代码来源:ConfigurableTest.php
示例8: setUp
protected function setUp()
{
$this->metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
$this->metadata->expects($this->any())->method('getIdentifierField')->willReturn('identifier');
$this->hydrator = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityHydrator', [], [], '', false);
$this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
$this->metadataPool->expects($this->any())->method('getHydrator')->with('Test\\Entity\\Type')->willReturn($this->hydrator);
$this->metadataPool->expects($this->any())->method('getMetadata')->with('Test\\Entity\\Type')->willReturn($this->metadata);
$this->abstractEntity = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], '', false, false, true, []);
$this->writeOperation = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Operation\\WriteInterface', [], '', false, false, true, []);
$this->orchestratorPool = $this->getMock('Magento\\Framework\\Model\\OrchestratorPool', [], [], '', false);
$this->subject = new \Magento\Framework\Model\EntityManager($this->orchestratorPool, $this->metadataPool);
}
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:13,代码来源:EntityManagerTest.php
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: 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
注:本文中的Magento\Framework\Model\Entity\MetadataPool类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论