本文整理汇总了PHP中Mage_Eav_Model_Entity_Attribute_Abstract::getSource方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Eav_Model_Entity_Attribute_Abstract::getSource方法的具体用法?PHP Mage_Eav_Model_Entity_Attribute_Abstract::getSource怎么用?PHP Mage_Eav_Model_Entity_Attribute_Abstract::getSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Eav_Model_Entity_Attribute_Abstract
的用法示例。
在下文中一共展示了Mage_Eav_Model_Entity_Attribute_Abstract::getSource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setPricingLabelFromAttribute
public function setPricingLabelFromAttribute(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
{
if ($attribute->getSource()) {
$this->setLabel($attribute->getSource()->getOptionText($this->getValueIndex()));
} else {
$this->setLabel($this->getValueIndex());
}
return $this;
}
示例2: getAttributeSelectElement
/**
* Build attribute select element html string
*
* @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
* @return string
*/
public function getAttributeSelectElement($attribute)
{
$extra = '';
$options = $attribute->getSource()->getAllOptions(false);
$name = $attribute->getAttributeCode();
// 2 - avoid yes/no selects to be multiselects
if (is_array($options) && count($options) > 2) {
$extra = 'multiple="multiple" size="4"';
$name .= '[]';
} else {
array_unshift($options, array('value' => '', 'label' => Mage::helper('catalogsearch')->__('All')));
}
return $this->_getSelectBlock()->setName($name)->setId($attribute->getAttributeCode())->setTitle($this->getAttributeLabel($attribute))->setExtraParams($extra)->setValue($this->getAttributeValue($attribute))->setOptions($options)->setClass('multiselect')->getHtml();
}
示例3: getAttributeOptions
/**
* Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased.
*
* @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
* @return array
*/
public function getAttributeOptions(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
{
$options = array();
if ($attribute->usesSource()) {
// should attribute has index (option value) instead of a label?
$index = in_array($attribute->getAttributeCode(), $this->_indexValueAttributes) ? 'value' : 'label';
// only default (admin) store values used
$attribute->setStoreId(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
try {
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
foreach (is_array($option['value']) ? $option['value'] : array($option) as $innerOption) {
if (strlen($innerOption['value'])) {
// skip ' -- Please Select -- ' option
$options[$innerOption['value']] = $innerOption[$index];
}
}
}
} catch (Exception $e) {
// ignore exceptions connected with source models
}
}
return $options;
}
示例4: _validateAttributeWithSource
/**
* Validate attribute value for attributes with source models
*
* @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
* @param mixed $attrValue
* @return array|bool
*/
protected function _validateAttributeWithSource(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $attrValue)
{
$errors = array();
// validate attributes with source models
if (null !== $attrValue && $attribute->getSourceModel()) {
if ('multiselect' !== $attribute->getFrontendInput() && is_array($attrValue)) {
return array('Invalid value type for ' . $attribute->getAttributeCode());
}
$possibleValues = $attribute->getSource()->getAllOptions(false);
foreach ((array) $attrValue as $value) {
if (is_scalar($value)) {
$value = (string) $value;
$isValid = false;
foreach ($possibleValues as $optionData) {
// comparison without types check is performed only when both values are numeric
$useStrictMode = !(is_numeric($value) && is_numeric($optionData['value']));
$isValid = $useStrictMode ? $value === $optionData['value'] : $value == $optionData['value'];
if ($isValid) {
break;
}
}
if (!$isValid) {
$errors[] = 'Invalid value "' . $value . '" for ' . $attribute->getAttributeCode();
}
} else {
$errors[] = 'Invalid value type for ' . $attribute->getAttributeCode();
}
}
}
return $errors ? $errors : true;
}
示例5: getAttributeOptions
/**
* Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased.
*
* @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
* @return array
*/
public function getAttributeOptions(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
{
$options = array();
if ($attribute->usesSource()) {
// should attribute has index (option value) instead of a label?
$index = in_array($attribute->getAttributeCode(), $this->_indexValueAttributes) ? 'value' : 'label';
/* MEP changed admin store to current profile store id */
$attribute->setStoreId($this->getProfile()->getStoreId());
try {
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
foreach (is_array($option['value']) ? $option['value'] : array($option) as $innerOption) {
if (strlen($innerOption['value'])) {
// skip ' -- Please Select -- ' option
$options[$innerOption['value']] = $innerOption[$index];
}
}
}
} catch (Exception $e) {
// ignore exceptions connected with source models
}
}
return $options;
}