本文整理汇总了PHP中Magento\Eav\Model\Config::getEntityAttributeCodes方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::getEntityAttributeCodes方法的具体用法?PHP Config::getEntityAttributeCodes怎么用?PHP Config::getEntityAttributeCodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Config
的用法示例。
在下文中一共展示了Config::getEntityAttributeCodes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAndInitAttributes
/**
* @param AbstractEntity $resource
* @param DataObject|null $object
* @return array
*/
private function checkAndInitAttributes(AbstractEntity $resource, DataObject $object = null)
{
$attributeCodes = $this->config->getEntityAttributeCodes($resource->getEntityType(), $object);
$attributes = [];
/**
* Check and init default attributes
*/
$defaultAttributes = $resource->getDefaultAttributes();
foreach ($defaultAttributes as $attributeCode) {
$attributeIndex = array_search($attributeCode, $attributeCodes);
if ($attributeIndex !== false) {
$attribute = $resource->getAttribute($attributeCodes[$attributeIndex]);
$attributes[] = $attribute;
unset($attributeCodes[$attributeIndex]);
} else {
$attribute = $this->_getDefaultAttribute($resource, $attributeCode);
$attributes[] = $attribute;
$resource->addAttribute($attribute);
}
}
foreach ($attributeCodes as $code) {
$attribute = $resource->getAttribute($code);
$attributes[] = $attribute;
}
return $attributes;
}
示例2: getAllAttributeCodes
/**
* Get all attribute codes for a given entity type and attribute set
*
* @param string $entityType
* @param int $attributeSetId
* @param string|null $storeId
* @return array Attribute codes
*/
public function getAllAttributeCodes($entityType, $attributeSetId = 0, $storeId = null)
{
if (null === $storeId) {
$storeId = $this->storeManager->getStore()->getId();
}
$object = new \Magento\Framework\DataObject(['store_id' => $storeId, 'attribute_set_id' => $attributeSetId]);
return $this->eavConfig->getEntityAttributeCodes($entityType, $object);
}
示例3: afterGetUsedProductCollection
/**
* Returns Configurable Products Collection with added swatch attributes
*
* @param ConfigurableProduct $subject
* @param Collection $result
* @return Collection
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetUsedProductCollection(ConfigurableProductType $subject, Collection $result)
{
$attributeCodes = ['image'];
$entityType = $result->getEntity()->getType();
foreach ($this->eavConfig->getEntityAttributeCodes($entityType) as $code) {
$attribute = $this->eavConfig->getAttribute($entityType, $code);
if ($this->swatchHelper->isVisualSwatch($attribute) || $this->swatchHelper->isTextSwatch($attribute)) {
$attributeCodes[] = $code;
}
}
$result->addAttributeToSelect($attributeCodes);
return $result;
}
示例4: getProductAttributes
/**
*
* @return array
*/
public function getProductAttributes()
{
if (is_null($this->prodAttributes)) {
$this->prodAttributes = $this->eavConfig->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY);
}
return $this->prodAttributes;
}
示例5: getFilterArray
/**
* Get filters from request
*
* @param array $request
* @return array
*/
protected function getFilterArray(array $request)
{
$filterArray = [];
$attributeCodes = $this->eavConfig->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY);
foreach ($request as $code => $value) {
if (in_array($code, $attributeCodes)) {
$attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $code);
if ($attribute->getId() && $this->canReplaceImageWithSwatch($attribute)) {
$filterArray[$code] = $value;
}
}
}
return $filterArray;
}
示例6: getAllAttributeSetMetadata
/**
* {@inheritdoc}
*/
public function getAllAttributeSetMetadata($entityType, $attributeSetId = 0, $storeId = null)
{
if (null === $storeId) {
$storeId = $this->_storeManager->getStore()->getId();
}
$object = new \Magento\Framework\Object(['store_id' => $storeId, 'attribute_set_id' => $attributeSetId]);
$attributeCodes = $this->_eavConfig->getEntityAttributeCodes($entityType, $object);
$attributesMetadata = [];
foreach ($attributeCodes as $attributeCode) {
try {
$attributesMetadata[] = $this->getAttributeMetadata($entityType, $attributeCode);
} catch (NoSuchEntityException $e) {
//If no such entity, skip
}
}
return $attributesMetadata;
}
示例7: loadAllAttributes
/**
* Retrieve configuration for all attributes
*
* @param null|\Magento\Framework\Object $object
* @return $this
*/
public function loadAllAttributes($object = null)
{
$attributeCodes = $this->_eavConfig->getEntityAttributeCodes($this->getEntityType(), $object);
/**
* Check and init default attributes
*/
$defaultAttributes = $this->getDefaultAttributes();
foreach ($defaultAttributes as $attributeCode) {
$attributeIndex = array_search($attributeCode, $attributeCodes);
if ($attributeIndex !== false) {
$this->getAttribute($attributeCodes[$attributeIndex]);
unset($attributeCodes[$attributeIndex]);
} else {
$this->addAttribute($this->_getDefaultAttribute($attributeCode));
}
}
foreach ($attributeCodes as $code) {
$this->getAttribute($code);
}
return $this;
}
示例8: _removeNotApplicableAttributes
/**
* Remove don't applicable attributes data
*
* @param \Magento\Catalog\Model\Product $product
* @return void
*/
protected function _removeNotApplicableAttributes($product)
{
$entityType = $product->getResource()->getEntityType();
foreach ($this->_eavConfig->getEntityAttributeCodes($entityType, $product) as $attributeCode) {
$attribute = $this->_eavConfig->getAttribute($entityType, $attributeCode);
$applyTo = $attribute->getApplyTo();
if (is_array($applyTo) && count($applyTo) > 0 && !in_array($product->getTypeId(), $applyTo)) {
$product->unsetData($attribute->getAttributeCode());
}
}
}
示例9: _processProductAttributes
/**
* Process product attributes on collection.
*
* @param $collection
*
* @return mixed
*/
public function _processProductAttributes($collection)
{
//if no product attribute or collection empty return collection
if (empty($this->productAttribute) or !$collection->getSize()) {
return $collection;
}
foreach ($collection as $collectionItem) {
$items = $collectionItem->getAllItems();
foreach ($items as $item) {
//loaded product
$product = $item->getProduct();
//attributes array from loaded product
$attributes = $this->config->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY, $product);
foreach ($this->productAttribute as $productAttribute) {
$attribute = $productAttribute['attribute'];
$cond = $productAttribute['conditions'];
$value = $productAttribute['cvalue'];
if ($cond == 'null') {
if ($value == '0') {
$cond = 'neq';
} elseif ($value == '1') {
$cond = 'eq';
}
$value = '';
}
//if attribute is in product's attributes array
if (in_array($attribute, $attributes)) {
$attr = $this->config->getAttribute('catalog_product', $attribute);
//frontend type
$frontType = $attr->getFrontend()->getInputType();
//if type is select
if ($frontType == 'select' or $frontType == 'multiselect') {
$attributeValue = $product->getAttributeText($attribute);
//evaluate conditions on values. if true then unset item from collection
if ($this->_evaluate($value, $cond, $attributeValue)) {
$collection->removeItemByKey($collectionItem->getId());
continue 3;
}
} else {
$getter = 'get';
$exploded = explode('_', $attribute);
foreach ($exploded as $one) {
$getter .= ucfirst($one);
}
//@codingStandardsIgnoreStart
$attributeValue = call_user_func([$product, $getter]);
//@codingStandardsIgnoreEnd
//if retrieved value is an array then loop through all array values.
// example can be categories
if (is_array($attributeValue)) {
foreach ($attributeValue as $attrValue) {
//evaluate conditions on values. if true then unset item from collection
if ($this->_evaluate($value, $cond, $attrValue)) {
$collection->removeItemByKey($collectionItem->getId());
continue 3;
}
}
} else {
//evaluate conditions on values. if true then unset item from collection
if ($this->_evaluate($value, $cond, $attributeValue)) {
$collection->removeItemByKey($collectionItem->getId());
continue 3;
}
}
}
}
}
}
}
return $collection;
}