本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Attribute::getId方法的具体用法?PHP Attribute::getId怎么用?PHP Attribute::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Entity\Attribute
的用法示例。
在下文中一共展示了Attribute::getId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveAttribute
private function saveAttribute()
{
if ($this->attributeObj->getId()) {
return array('result' => true, 'obj' => $this->attributeObj);
}
if (!$this->validate()) {
return array('result' => false, 'error' => 'Attribute builder. Validation failed.');
}
$this->attributeObj = $this->catalogAttributeFactory->create();
$data = $this->params;
$data['attribute_code'] = $this->code;
$data['frontend_label'] = array(\Magento\Store\Model\Store::DEFAULT_STORE_ID => $this->primaryLabel);
$data['frontend_input'] = $this->inputType;
$data['entity_type_id'] = $this->entityTypeId;
$data['is_user_defined'] = 1;
$data['source_model'] = $this->productHelper->getAttributeSourceModelByInputType($this->inputType);
$data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType($this->inputType);
$data['backend_type'] = $this->attributeObj->getBackendTypeByInput($this->inputType);
!isset($data['is_global']) && ($data['is_global'] = self::SCOPE_STORE);
!isset($data['is_configurable']) && ($data['is_configurable'] = 0);
!isset($data['is_filterable']) && ($data['is_filterable'] = 0);
!isset($data['is_filterable_in_search']) && ($data['is_filterable_in_search'] = 0);
!isset($data['apply_to']) && ($data['apply_to'] = array());
$this->prepareOptions($data);
$this->prepareDefault($data);
$this->attributeObj->addData($data);
try {
$this->attributeObj->save();
} catch (\Exception $e) {
return array('result' => false, 'error' => $e->getMessage());
}
return array('result' => true, 'obj' => $this->attributeObj);
}
示例2: findWhereAttributeIs
/**
* Return entities where attribute value is
*
* @param array|int $entityIdsFilter
* @param \Magento\Eav\Model\Entity\Attribute $attribute
* @param mixed $expectedValue
* @return array
*/
public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
{
$bind = array('attribute_id' => $attribute->getId(), 'value' => $expectedValue);
$select = $this->_getReadAdapter()->select()->from($attribute->getBackend()->getTable(), array('entity_id'))->where('attribute_id = :attribute_id')->where('value = :value')->where('entity_id IN(?)', $entityIdsFilter);
return $this->_getReadAdapter()->fetchCol($select, $bind);
}
示例3: findWhereAttributeIs
/**
* Return entities where attribute value is
*
* @param array|int $entityIdsFilter
* @param \Magento\Eav\Model\Entity\Attribute $attribute
* @param mixed $expectedValue
* @return array
*/
public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
{
$linkField = $this->getLinkField();
$bind = ['attribute_id' => $attribute->getId(), 'value' => $expectedValue];
$selectEntities = $this->getConnection()->select()->from(['ce' => $this->getTable('catalog_category_entity')], ['entity_id'])->joinLeft(['ci' => $attribute->getBackend()->getTable()], "ci.{$linkField} = ce.{$linkField} AND attribute_id = :attribute_id", ['value'])->where('ci.value = :value')->where('ce.entity_id IN (?)', $entityIdsFilter);
return $this->getConnection()->fetchCol($selectEntities, $bind);
}
示例4: checkIsAlreadyInSet
private function checkIsAlreadyInSet()
{
/* @var $collection \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection */
$collection = $this->attributeFactory->create()->getResourceCollection()->setAttributeSetFilter($this->setId)->addFieldToFilter('entity_attribute.attribute_id', $this->attributeObj->getId());
return $collection->getSize() > 0;
}
示例5: next
/**
* {@inheritDoc}
*/
public function next()
{
\next($this->products);
if (\key($this->products) === null) {
// check if storage has more items to process
$this->products = $this->dataProvider->getSearchableProducts($this->storeId, $this->staticFields, $this->productIds, $this->lastProductId);
if (!count($this->products)) {
$this->isValid = false;
return;
}
$productAttributes = [];
$this->productRelations = [];
foreach ($this->products as $productData) {
$this->lastProductId = $productData['entity_id'];
$productAttributes[$productData['entity_id']] = $productData['entity_id'];
$productChildren = $this->dataProvider->getProductChildIds($productData['entity_id'], $productData['type_id']);
$this->productRelations[$productData['entity_id']] = $productChildren;
if ($productChildren) {
foreach ($productChildren as $productChildId) {
$productAttributes[$productChildId] = $productChildId;
}
}
}
\reset($this->products);
$this->productAttributes = $this->dataProvider->getProductAttributes($this->storeId, $productAttributes, $this->dynamicFields);
}
$productData = \current($this->products);
if (!isset($this->productAttributes[$productData['entity_id']])) {
$this->next();
return;
}
$productAttr = $this->productAttributes[$productData['entity_id']];
if (!isset($productAttr[$this->visibility->getId()]) || !in_array($productAttr[$this->visibility->getId()], $this->allowedVisibility)) {
$this->next();
return;
}
if (!isset($productAttr[$this->status->getId()]) || !in_array($productAttr[$this->status->getId()], $this->statusIds)) {
$this->next();
return;
}
$productIndex = [$productData['entity_id'] => $productAttr];
$hasChildren = false;
$productChildren = $this->productRelations[$productData['entity_id']];
if ($productChildren) {
foreach ($productChildren as $productChildId) {
if (isset($this->productAttributes[$productChildId])) {
$productChildAttr = $this->productAttributes[$productChildId];
if (!isset($productChildAttr[$this->status->getId()]) || !in_array($productChildAttr[$this->status->getId()], $this->statusIds)) {
continue;
}
$hasChildren = true;
$productIndex[$productChildId] = $productChildAttr;
}
}
}
if ($productChildren !== null && !$hasChildren) {
$this->next();
return;
}
$index = $this->dataProvider->prepareProductIndex($productIndex, $productData, $this->storeId);
$this->current = $index;
$this->key = $productData['entity_id'];
}