本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::hasData方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::hasData方法的具体用法?PHP AbstractModel::hasData怎么用?PHP AbstractModel::hasData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::hasData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
/**
* Perform actions before object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
$belongsToQuoteItem = $object->hasData(CommentInterface::QUOTE_ITEM_ID_COLUMN);
$belongsToOrderItem = $object->hasData(CommentInterface::ORDER_ITEM_ID_COLUMN);
$hasText = $object->hasData(CommentInterface::TEXT_COLUMN);
// A comment should either be attached to a quote item or order item...
if (!$belongsToQuoteItem || !$belongsToOrderItem) {
throw new \Magento\Framework\Exception\LocalizedException(__('A comment should belong to either a quote item or order item.'));
}
// ...but not to both
if ($belongsToQuoteItem && $belongsToOrderItem) {
throw new \Magento\Framework\Exception\LocalizedException(__('A comment cannot belong to both a quote item and order item.'));
}
if (!$hasText) {
throw new \Magento\Framework\Exception\LocalizedException(__('A comment requirescomp text.'));
}
return parent::_beforeSave($object);
}
示例2: validate
/**
* Validate product attribute value for condition
*
* @param \Magento\Framework\Model\AbstractModel $model
* @return bool
*/
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
$attrCode = $this->getAttribute();
if ('category_ids' == $attrCode) {
return $this->validateAttribute($model->getAvailableInCategories());
}
$oldAttrValue = $model->hasData($attrCode) ? $model->getData($attrCode) : null;
$this->_setAttributeValue($model);
$result = $this->validateAttribute($model->getData($this->getAttribute()));
$this->_restoreOldAttrValue($model, $oldAttrValue);
return (bool) $result;
}
示例3: _beforeSave
/**
* {@inheritdoc}
*/
protected function _beforeSave(AbstractModel $object)
{
$reindexRequired = false;
if ($object->hasData('attributes') && is_array($object->getData('attributes'))) {
$serialized = serialize($object->getData('attributes'));
if ($object->getData('attributes_serialized') != $serialized) {
$reindexRequired = true;
}
$object->setData('attributes_serialized', $serialized);
}
if ($object->hasData('properties') && is_array($object->getData('properties'))) {
$serialized = serialize($object->getData('properties'));
if ($object->getData('properties_serialized') != $serialized) {
$reindexRequired = true;
}
$object->setData('properties_serialized', $serialized);
}
if ($reindexRequired && !$object->dataHasChangedFor('status')) {
$object->setStatus(Config::INDEX_STATUS_INVALID);
}
$object->setCode($object->getCode());
return $this;
}
示例4: _beforeSave
/**
* Perform actions before object save
*
* @param AbstractModel $object
* @return $this
*/
protected function _beforeSave(AbstractModel $object)
{
if (!$object->getId()) {
$object->setCreatedAt($this->_date->gmtDate());
}
if ($object->hasData('stores') && is_array($object->getStores())) {
$stores = $object->getStores();
$stores[] = 0;
$object->setStores($stores);
} elseif ($object->hasData('stores')) {
$object->setStores([$object->getStores(), 0]);
}
return $this;
}
示例5: validate
/**
* @param \Magento\Framework\Model\AbstractModel $model
* @return bool
*/
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
if (!$model->hasData($this->getAttribute())) {
$model->load($model->getId());
}
$attributeValue = $model->getData($this->getAttribute());
return $this->validateAttribute($attributeValue);
}