本文整理汇总了PHP中Magento\Framework\Model\Resource\Db\AbstractDb::_beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractDb::_beforeSave方法的具体用法?PHP AbstractDb::_beforeSave怎么用?PHP AbstractDb::_beforeSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\Resource\Db\AbstractDb
的用法示例。
在下文中一共展示了AbstractDb::_beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
/**
* Perform actions before object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($date = $object->getDateFrom()) {
$object->setDateFrom($this->dateTime->formatDate($date));
} else {
$object->setDateFrom(null);
}
if ($date = $object->getDateTo()) {
$object->setDateTo($this->dateTime->formatDate($date));
} else {
$object->setDateTo(null);
}
if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && (new \DateTime($object->getDateFrom()))->getTimestamp() > (new \DateTime($object->getDateTo()))->getTimestamp()) {
throw new \Magento\Framework\Exception\LocalizedException(__('The start date can\'t follow the end date.'));
}
$check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
if ($check) {
throw new \Magento\Framework\Exception\LocalizedException(__('The date range for this design change overlaps another design change for the specified store.'));
}
if ($object->getDateFrom() === null) {
$object->setDateFrom(new \Zend_Db_Expr('null'));
}
if ($object->getDateTo() === null) {
$object->setDateTo(new \Zend_Db_Expr('null'));
}
parent::_beforeSave($object);
}
示例2: _beforeSave
/**
* Validate website code before object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $object->getCode())) {
throw new \Magento\Framework\Exception\LocalizedException(__('Website code may only contain letters (a-z), numbers (0-9) or underscore (_),' . ' and the first character must be a letter.'));
}
return parent::_beforeSave($object);
}
示例3: _beforeSave
/**
* Perform actions before object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return \Magento\Framework\Model\Resource\Db\AbstractDb
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$object->getSortOrder()) {
$object->setSortOrder($this->_getMaxSortOrder($object) + 1);
}
return parent::_beforeSave($object);
}
示例4: _beforeSave
/**
* Set template type, added at and modified at time
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _beforeSave(AbstractModel $object)
{
if ($object->isObjectNew()) {
$object->setAddedAt($this->dateTime->formatDate(true));
}
$object->setModifiedAt($this->dateTime->formatDate(true));
$object->setTemplateType((int) $object->getTemplateType());
return parent::_beforeSave($object);
}
示例5: _beforeSave
/**
* Convert array to comma separated value
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$object->getId()) {
$this->_checkUnique($object);
}
if (is_array($object->getValue())) {
$object->setValue(join(',', $object->getValue()));
}
return parent::_beforeSave($object);
}
示例6: _beforeSave
/**
* Perform actions before object save
*
* @param AbstractModel $object
* @return $this
*/
public function _beforeSave(AbstractModel $object)
{
if (!$object->getExpirationDate()) {
$object->setExpirationDate(null);
} elseif ($object->getExpirationDate() instanceof \DateTimeInterface) {
$object->setExpirationDate($object->getExpirationDate()->format('Y-m-d H:i:s'));
}
// maintain single primary coupon per rule
$object->setIsPrimary($object->getIsPrimary() ? 1 : null);
return parent::_beforeSave($object);
}
示例7: _beforeSave
/**
* Serialize additional information, if any
*
* @param \Magento\Framework\Model\AbstractModel $transaction
* @return $this
* @throws \Magento\Framework\Model\Exception
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transaction)
{
$txnId = $transaction->getData('txn_id');
$idFieldName = $this->getIdFieldName();
// make sure unique key won't cause trouble
if ($transaction->isFailsafe()) {
$autoincrementId = (int) $this->_lookupByTxnId($txnId, $idFieldName);
if ($autoincrementId) {
$transaction->setData($idFieldName, $autoincrementId)->isObjectNew(false);
}
}
return parent::_beforeSave($transaction);
}
示例8: _beforeSave
/**
* Perform actions before object save
*
* @param AbstractModel $object
* @return $this
*/
public function _beforeSave(AbstractModel $object)
{
if (!$object->getExpirationDate()) {
$object->setExpirationDate(null);
} else {
if ($object->getExpirationDate() instanceof \Zend_Date) {
$object->setExpirationDate($object->getExpirationDate()->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
}
}
// maintain single primary coupon per rule
$object->setIsPrimary($object->getIsPrimary() ? 1 : null);
return parent::_beforeSave($object);
}
示例9: _beforeSave
/**
* Process post data before saving
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$this->isValidPostUrlKey($object)) {
throw new \Magento\Framework\Exception\LocalizedException(__('The post URL key contains capital letters or disallowed symbols.'));
}
if ($this->isNumericPostUrlKey($object)) {
throw new \Magento\Framework\Exception\LocalizedException(__('The post URL key cannot be made of only numbers.'));
}
if ($object->isObjectNew() && !$object->hasCreationTime()) {
$object->setCreationTime($this->_date->gmtDate());
}
$object->setUpdateTime($this->_date->gmtDate());
return parent::_beforeSave($object);
}
示例10: _beforeSave
/**
* Method to run before save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
// format height
$height = $object->getContentHeight();
$height = $this->filterManager->stripTags($height);
if (!$height) {
$height = '';
}
if ($height && preg_match('/[0-9]$/', $height)) {
$height .= 'px';
}
$object->setContentHeight($height);
return parent::_beforeSave($object);
}
示例11: _beforeSave
/**
* Prepare rule's active "from" and "to" dates
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
$fromDate = $object->getFromDate();
if ($fromDate instanceof \Zend_Date) {
$object->setFromDate($fromDate->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
} elseif (!is_string($fromDate) || empty($fromDate)) {
$object->setFromDate(null);
}
$toDate = $object->getToDate();
if ($toDate instanceof \Zend_Date) {
$object->setToDate($toDate->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
} elseif (!is_string($toDate) || empty($toDate)) {
$object->setToDate(null);
}
parent::_beforeSave($object);
return $this;
}
示例12: _beforeSave
/**
* Prepare rule's active "from" and "to" dates
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
$fromDate = $object->getFromDate();
if ($fromDate instanceof \DateTime) {
$object->setFromDate($fromDate->format('Y-m-d H:i:s'));
} elseif (!is_string($fromDate) || empty($fromDate)) {
$object->setFromDate(null);
}
$toDate = $object->getToDate();
if ($toDate instanceof \DateTime) {
$object->setToDate($toDate->format('Y-m-d H:i:s'));
} elseif (!is_string($toDate) || empty($toDate)) {
$object->setToDate(null);
}
parent::_beforeSave($object);
return $this;
}
示例13: _beforeSave
/**
* Check if semilar event exist before start saving data
*
* @param AbstractModel $object
* @return $this
*/
protected function _beforeSave(AbstractModel $object)
{
/**
* Check if event already exist and merge previous data
*/
if (!$object->getId()) {
$select = $this->_getReadAdapter()->select()->from($this->getMainTable())->where('type=?', $object->getType())->where('entity=?', $object->getEntity());
if ($object->hasEntityPk()) {
$select->where('entity_pk=?', $object->getEntityPk());
}
$data = $this->_getWriteAdapter()->fetchRow($select);
if ($data) {
$object->mergePreviousData($data);
}
}
$object->cleanNewData();
return parent::_beforeSave($object);
}
示例14: _beforeSave
/**
* Validate attribute data before save
*
* @param EntityAttribute|AbstractModel $object
* @return $this
* @throws \Magento\Framework\Model\Exception
*/
protected function _beforeSave(AbstractModel $object)
{
$frontendLabel = $object->getFrontendLabel();
if (is_array($frontendLabel)) {
if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0] == '') {
throw new \Magento\Framework\Model\Exception(__('Frontend label is not defined'));
}
$object->setFrontendLabel($frontendLabel[0])->setStoreLabels($frontendLabel);
}
/**
* @todo need use default source model of entity type !!!
*/
if (!$object->getId()) {
if ($object->getFrontendInput() == 'select') {
$object->setSourceModel('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table');
}
}
return parent::_beforeSave($object);
}
示例15: _beforeSave
/**
* Process page data before saving
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Magento\Framework\Model\Exception
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
/*
* For two attributes which represent timestamp data in DB
* we should make converting such as:
* If they are empty we need to convert them into DB
* type NULL so in DB they will be empty and not some default value
*/
foreach (array('custom_theme_from', 'custom_theme_to') as $field) {
$value = !$object->getData($field) ? null : $object->getData($field);
$object->setData($field, $this->dateTime->formatDate($value));
}
if (!$object->getData('identifier')) {
$object->setData('identifier', $this->filter->translitUrl($object->getData('title')));
}
if (!$this->getIsUniquePageToStores($object)) {
throw new \Magento\Framework\Model\Exception(__('A page URL key for specified store already exists.'));
}
if (!$this->isValidPageIdentifier($object)) {
throw new \Magento\Framework\Model\Exception(__('The page URL key contains capital letters or disallowed symbols.'));
}
if ($this->isNumericPageIdentifier($object)) {
throw new \Magento\Framework\Model\Exception(__('The page URL key cannot be made of only numbers.'));
}
// modify create / update dates
if ($object->isObjectNew() && !$object->hasCreationTime()) {
$object->setCreationTime($this->_date->gmtDate());
}
$object->setUpdateTime($this->_date->gmtDate());
return parent::_beforeSave($object);
}