/** * @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; }
/** * @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; }
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); }
/** * {@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); }
/** * @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; }
/** * @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; }
/** * 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; }
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')); }
/** * @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; }
/** * {@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(); }
/** * @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(); }
/** * @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); }
/** * 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; }
/** * @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 ?: []; }
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]); }
/** * @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; }
/** * @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; }
/** * {@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; }
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); }
/** * @param string $entityType * @param object $entity * @param array $data * @return object * @throws \Exception */ public function execute($entityType, $entity, $data = []) { $hydrator = $this->metadataPool->getHydrator($entityType); $entityData = array_merge($hydrator->extract($entity), $data); $actions = $this->extensionPool->getActions($entityType, 'create'); foreach ($actions as $action) { $entityData = $action->execute($entityType, $entityData); } $entity = $hydrator->hydrate($entity, $entityData); return $entity; }
/** * @param string $entityType * @param object $entity * @return object * @throws \Exception */ public function execute($entityType, $entity) { $hydrator = $this->metadataPool->getHydrator($entityType); $entityData = $hydrator->extract($entity); $actions = $this->extensionPool->getActions($entityType, 'read'); foreach ($actions as $action) { $data = $action->execute($entityType, $entityData); $entity = $hydrator->hydrate($entity, $data); } return $entity; }
/** * @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); }
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]); }
public function testExecuteWithString() { $customers = '1,2'; $websites = '3,4,5'; $entityData = ['row_id' => 1, 'rule_id' => 1, 'website_ids' => $websites, 'customer_group_ids' => $customers]; $className = '\\Magento\\Framework\\Model\\Entity\\EntityMetadata'; $metadata = $this->getMock($className, [], [], '', false); $metadata->expects($this->once())->method('getLinkField')->willReturn('rule_id'); $this->metadataPool->expects($this->once())->method('getMetadata')->willReturn($metadata); $this->ruleResource->expects($this->any())->method('bindRuleToEntity')->withConsecutive([1, [3, 4, 5]], [1, [1, 2]]); $result = $this->model->execute(RuleInterface::class, $entityData); $this->assertEquals($entityData, $result); }
/** * 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)); }
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); }
/** * 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; }
/** * @param string $entityType * @param int $identifier * @return int * @throws \Exception */ public function delete($entityType, $identifier) { $metadata = $this->metadataPool->getMetadata($entityType); $sequenceInfo = $this->sequenceRegistry->retrieve($entityType); if (!isset($sequenceInfo['sequenceTable'])) { throw new \Exception('TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesnt exists'); } try { return $metadata->getEntityConnection()->delete($this->appResource->getTableName($sequenceInfo['sequenceTable']), ['sequence_value = ?' => $identifier]); } catch (\Exception $e) { $this->logger->critical($e->getMessage(), $e->getTrace()); throw new \Exception('TODO: use correct Exception class' . PHP_EOL . $e->getMessage()); } }
/** * 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; }
/** * Retrieve Required children ids * Return grouped array, ex array( * group => array(ids) * ) * * @param int $parentId * @param int $typeId * @return array */ public function getChildrenIds($parentId, $typeId) { $connection = $this->getConnection(); $childrenIds = []; $bind = [':product_id' => (int) $parentId, ':link_type_id' => (int) $typeId]; $select = $connection->select()->from(['l' => $this->getMainTable()], ['linked_product_id'])->join(['cpe' => $this->getTable('catalog_product_entity')], sprintf('cpe.%s = l.product_id', $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()))->where('cpe.entity_id = :product_id')->where('link_type_id = :link_type_id'); $select->join(['e' => $this->getTable('catalog_product_entity')], 'e.entity_id = l.linked_product_id AND e.required_options = 0', []); $childrenIds[$typeId] = []; $result = $connection->fetchAll($select, $bind); foreach ($result as $row) { $childrenIds[$typeId][$row['linked_product_id']] = $row['linked_product_id']; } return $childrenIds; }