本文整理汇总了PHP中Magento\Framework\Object::getResource方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::getResource方法的具体用法?PHP Object::getResource怎么用?PHP Object::getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Object
的用法示例。
在下文中一共展示了Object::getResource方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepareMultiselectValue
/**
* Prepare multiselect attribute value
*
* @param mixed $value
* @param \Magento\Framework\Object $object
* @return mixed
*/
protected function _prepareMultiselectValue($value, $object)
{
$attribute = $object->getResource()->getAttribute($this->getAttribute());
if ($attribute && $attribute->getFrontendInput() == 'multiselect') {
$value = strlen($value) ? explode(',', $value) : array();
}
return $value;
}
示例2: validate
/**
* Validate product attribute value for condition
*
* @param \Magento\Framework\Object $object
* @return bool
*/
public function validate(\Magento\Framework\Object $object)
{
$attrCode = $this->getAttribute();
if ('category_ids' == $attrCode) {
return $this->validateAttribute($object->getAvailableInCategories());
} elseif (!isset($this->_entityAttributeValues[$object->getId()])) {
if (!$object->getResource()) {
return false;
}
$attr = $object->getResource()->getAttribute($attrCode);
if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
$this->setValue(strtotime($this->getValue()));
$value = strtotime($object->getData($attrCode));
return $this->validateAttribute($value);
}
if ($attr && $attr->getFrontendInput() == 'multiselect') {
$value = $object->getData($attrCode);
$value = strlen($value) ? explode(',', $value) : array();
return $this->validateAttribute($value);
}
return parent::validate($object);
} else {
$result = false;
// any valid value will set it to TRUE
// remember old attribute state
$oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
foreach ($this->_entityAttributeValues[$object->getId()] as $value) {
$attr = $object->getResource()->getAttribute($attrCode);
if ($attr && $attr->getBackendType() == 'datetime') {
$value = strtotime($value);
} elseif ($attr && $attr->getFrontendInput() == 'multiselect') {
$value = strlen($value) ? explode(',', $value) : array();
}
$object->setData($attrCode, $value);
$result |= parent::validate($object);
if ($result) {
break;
}
}
if (is_null($oldAttrValue)) {
$object->unsetData($attrCode);
} else {
$object->setData($attrCode, $oldAttrValue);
}
return (bool) $result;
}
}
示例3: getSmallImageUrl
/**
* Retrieve small image url
*
* @param ModelProduct|\Magento\Framework\Object $product
* @return string|bool
*/
public function getSmallImageUrl($product)
{
$url = false;
$attribute = $product->getResource()->getAttribute('small_image');
if (!$product->getSmallImage()) {
$url = $this->_assetRepo->getUrl('Magento_Catalog::images/product/placeholder/small_image.jpg');
} elseif ($attribute) {
$url = $attribute->getFrontend()->getUrl($product);
}
return $url;
}