本文整理汇总了PHP中Magento\Eav\Model\Config::getEntityType方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::getEntityType方法的具体用法?PHP Config::getEntityType怎么用?PHP Config::getEntityType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Config
的用法示例。
在下文中一共展示了Config::getEntityType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEntityTypeId
/**
* Retrieve catalog_product entity type id
*
* @return int
*/
public function getEntityTypeId()
{
if ($this->_entityTypeId === null) {
$this->_entityTypeId = (int) $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
}
return $this->_entityTypeId;
}
示例2: __construct
/**
* Constructor
*
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param EavValidationRules $eavValidationRules
* @param CustomerCollectionFactory $customerCollectionFactory
* @param Config $eavConfig
* @param FilterPool $filterPool
* @param array $meta
* @param array $data
*/
public function __construct($name, $primaryFieldName, $requestFieldName, EavValidationRules $eavValidationRules, CustomerCollectionFactory $customerCollectionFactory, Config $eavConfig, FilterPool $filterPool, array $meta = [], array $data = [])
{
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->eavValidationRules = $eavValidationRules;
$this->collection = $customerCollectionFactory->create();
$this->collection->addAttributeToSelect('*');
$this->eavConfig = $eavConfig;
$this->filterPool = $filterPool;
$this->meta['customer']['fields'] = $this->getAttributesMeta($this->eavConfig->getEntityType('customer'));
$this->meta['address']['fields'] = $this->getAttributesMeta($this->eavConfig->getEntityType('customer_address'));
}
示例3: validateSkeletonSet
/**
* @param int $skeletonId
* @return void
* @throws StateException
*/
protected function validateSkeletonSet($skeletonId)
{
try {
$skeletonSet = $this->attributeSetRepository->get($skeletonId);
$productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
if ($skeletonSet->getEntityTypeId() != $productEntityId) {
throw new StateException(__('Can not create attribute set based on non product attribute set.'));
}
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
throw new StateException(__('Can not create attribute set based on not existing attribute set'));
}
}
示例4: getPrefixes
/**
* Get fields prefixes
*
* @return array
*/
public function getPrefixes()
{
// use cached eav config
$entityTypeId = $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
/* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection */
$collection = $this->_attributeCollectionFactory->create();
$collection->setEntityTypeFilter($entityTypeId);
$collection->setFrontendInputTypeFilter('media_image');
$prefixes = [];
foreach ($collection as $attribute) {
/* @var $attribute \Magento\Eav\Model\Entity\Attribute */
$prefixes[] = ['field' => $attribute->getAttributeCode() . '_', 'label' => $attribute->getFrontend()->getLabel()];
}
return $prefixes;
}
示例5: eavAttributeChange
/**
* Update all attribute-dependant index
*
* @param \Magento\Framework\Event\Observer $observer
* @return \Magento\CatalogSearch\Model\Fulltext\Observer
*/
public function eavAttributeChange(\Magento\Framework\Event\Observer $observer)
{
$attribute = $observer->getEvent()->getAttribute();
/* @var $attribute \Magento\Eav\Model\Entity\Attribute */
$entityType = $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY);
/* @var $entityType \Magento\Eav\Model\Entity\Type */
if ($attribute->getEntityTypeId() != $entityType->getId()) {
return $this;
}
$delete = $observer->getEventName() == 'eav_entity_attribute_delete_after';
if (!$delete && !$attribute->dataHasChangedFor('is_searchable')) {
return $this;
}
$showNotice = false;
if ($delete) {
if ($attribute->getIsSearchable()) {
$showNotice = true;
}
} elseif ($attribute->dataHasChangedFor('is_searchable')) {
$showNotice = true;
}
if ($showNotice) {
$url = $this->_backendUrl->getUrl('adminhtml/system_cache');
$this->messageManager->addNotice(__('Attribute setting change related with Search Index. Please run <a href="%1">Rebuild Search Index</a> process.', $url));
}
return $this;
}
示例6: create
/**
* {@inheritdoc}
*/
public function create(\Magento\Catalog\Service\V1\Data\Eav\AttributeMetadata $attributeMetadata)
{
/**
* @var $model \Magento\Catalog\Model\Resource\Eav\Attribute
*/
$model = $this->attributeFactory->create();
$data = $attributeMetadata->__toArray();
// unset attribute id because we create new attribute (does not rewrite existing one)
unset($data[AttributeMetadata::ATTRIBUTE_ID]);
// define frontend label
if (!$attributeMetadata->getFrontendLabel()) {
throw InputException::requiredField(AttributeMetadata::FRONTEND_LABEL);
}
$data[AttributeMetadata::FRONTEND_LABEL] = [];
foreach ($attributeMetadata->getFrontendLabel() as $label) {
$data[AttributeMetadata::FRONTEND_LABEL][$label->getStoreId()] = $label->getLabel();
}
if (!isset($data[AttributeMetadata::FRONTEND_LABEL][0]) || !$data[AttributeMetadata::FRONTEND_LABEL][0]) {
throw InputException::invalidFieldValue(AttributeMetadata::FRONTEND_LABEL, null);
}
$data[AttributeMetadata::ATTRIBUTE_CODE] = $attributeMetadata->getAttributeCode() ?: $this->generateCode($data[AttributeMetadata::FRONTEND_LABEL][0]);
$this->validateCode($data[AttributeMetadata::ATTRIBUTE_CODE]);
$this->validateFrontendInput($attributeMetadata->getFrontendInput());
$data[AttributeMetadata::BACKEND_TYPE] = $model->getBackendTypeByInput($attributeMetadata->getFrontendInput());
$data[AttributeMetadata::SOURCE_MODEL] = $this->helper->getAttributeSourceModelByInputType($attributeMetadata->getFrontendInput());
$data[AttributeMetadata::BACKEND_MODEL] = $this->helper->getAttributeBackendModelByInputType($attributeMetadata->getFrontendInput());
$model->addData($data);
$model->setEntityTypeId($this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId())->setIsUserDefined(1);
return $model->save()->getAttributeCode();
}
示例7: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
/** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */
$collection = $this->collectionFactory->create();
$defaultAttributeSetId = $this->eavConfig->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)->getDefaultAttributeSetId();
$extendedSearchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($defaultAttributeSetId)->create()]);
foreach ($this->metadataService->getList($extendedSearchCriteria->create())->getItems() as $metadata) {
$collection->addAttributeToSelect($metadata->getAttributeCode());
}
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
//Add filters from root filter group to the collection
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $collection);
}
/** @var SortOrder $sortOrder */
foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
$field = $sortOrder->getField();
$collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
$collection->load();
$searchResult = $this->searchResultsFactory->create();
$searchResult->setSearchCriteria($searchCriteria);
$searchResult->setItems($collection->getItems());
$searchResult->setTotalCount($collection->getSize());
return $searchResult;
}
示例8: validate
/**
* Validate Frontend Input Type
*
* @param \Magento\Eav\Api\Data\AttributeSetInterface $attributeSet
* @return void
* @throws \Magento\Framework\Exception\InputException
*/
protected function validate(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet)
{
$productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
if ($attributeSet->getEntityTypeId() != $productEntityId) {
throw new \Magento\Framework\Exception\StateException(__('Provided Attribute set non product Attribute set.'));
}
}
示例9: getAttributes
/**
* Retrieve all attributes
*
* @return Attribute[]
*/
private function getAttributes()
{
if ($this->attributes === null) {
$this->attributes = [];
$entityType = $this->eavConfig->getEntityType(static::ENTITY);
/** @var \Magento\Customer\Model\Attribute[] $attributes */
$attributes = $entityType->getAttributeCollection()->getItems();
/** @var \Magento\Customer\Model\ResourceModel\Customer $entity */
$entity = $entityType->getEntity();
foreach ($attributes as $attribute) {
$attribute->setEntity($entity);
}
$this->attributes = $attributes;
}
return $this->attributes;
}
示例10: getEntityType
/**
* Return eav entity type instance
*
* @return \Magento\Eav\Model\Entity\Type
*/
public function getEntityType()
{
if ($this->_entityType === null) {
$this->_entityType = $this->_eavConfig->getEntityType($this->_getEntityTypeCode());
}
return $this->_entityType;
}
示例11: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
/** @var \Magento\Eav\Model\Resource\Entity\Attribute\Set\Collection $collection */
$collection = $this->collectionFactory->create();
/** The only possible/meaningful search criteria for attribute set is entity type code */
$entityTypeCode = $this->getEntityTypeCode($searchCriteria);
if ($entityTypeCode !== null) {
$collection->setEntityTypeFilter($this->eavConfig->getEntityType($entityTypeCode)->getId());
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
$searchResults->setItems($collection->getItems());
$searchResults->setTotalCount($collection->getSize());
return $searchResults;
}
示例12: getSearchableAttributes
/**
* Retrieve searchable attributes
*
* @return Attribute[]
*/
private function getSearchableAttributes()
{
if ($this->searchableAttributes === null) {
$this->searchableAttributes = [];
/** @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection $productAttributes */
$productAttributes = $this->collectionFactory->create();
$productAttributes->addToIndexFilter(true);
/** @var \Magento\Eav\Model\Entity\Attribute[] $attributes */
$attributes = $productAttributes->getItems();
$entity = $this->eavConfig->getEntityType(Product::ENTITY)->getEntity();
foreach ($attributes as $attribute) {
$attribute->setEntity($entity);
}
$this->searchableAttributes = $attributes;
}
return $this->searchableAttributes;
}
示例13: eavCollectFields
/**
* Collect fields for the entity with eav type.
*
* @param array $fixture
* @return array
*/
protected function eavCollectFields(array $fixture)
{
$entityType = $fixture['entity_type'];
$collection = $this->eavConfig->getEntityType($entityType)->getAttributeCollection();
$attributes = [];
foreach ($collection as $attribute) {
if (isset($fixture['product_type'])) {
$applyTo = $attribute->getApplyTo();
if (!empty($applyTo) && !in_array($fixture['product_type'], $applyTo)) {
continue;
}
}
/** @var $attribute \Magento\Eav\Model\Entity\Attribute */
$code = $attribute->getAttributeCode();
$attributes[$code] = ['attribute_code' => $code, 'backend_type' => $attribute->getBackendType(), 'is_required' => $attribute->getIsRequired(), 'default_value' => $attribute->getDefaultValue(), 'input' => $attribute->getFrontendInput()];
}
return $attributes;
}
示例14: _beforeDelete
/**
* Perform actions before object delete
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Magento\Framework\Exception\StateException
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _beforeDelete(\Magento\Framework\Model\AbstractModel $object)
{
/** @var \Magento\Eav\Api\Data\AttributeSetInterface $object */
$defaultAttributeSetId = $this->eavConfig->getEntityType($object->getEntityTypeId())->getDefaultAttributeSetId();
if ($object->getAttributeSetId() == $defaultAttributeSetId) {
throw new \Magento\Framework\Exception\StateException(__('Default attribute set can not be deleted'));
}
return parent::_beforeDelete($object);
}
示例15: __construct
/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\ImportExport\Model\Export\Factory $collectionFactory
* @param \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Eav\Model\Config $eavConfig
* @param array $data
*/
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Eav\Model\Config $eavConfig, array $data = [])
{
$this->_localeDate = $localeDate;
parent::__construct($scopeConfig, $storeManager, $collectionFactory, $resourceColFactory, $data);
if (isset($data['entity_type_id'])) {
$this->_entityTypeId = $data['entity_type_id'];
} else {
$this->_entityTypeId = $eavConfig->getEntityType($this->getEntityTypeCode())->getEntityTypeId();
}
}