本文整理汇总了PHP中Magento\Framework\Model\ResourceModel\Db\AbstractDb::_beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractDb::_beforeSave方法的具体用法?PHP AbstractDb::_beforeSave怎么用?PHP AbstractDb::_beforeSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\ResourceModel\Db\AbstractDb
的用法示例。
在下文中一共展示了AbstractDb::_beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
/**
* Perform actions before object save
*
* @param \Smart2Pay\GlobalPay\Model\ConfiguredMethods $object
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($existing_arr = $this->checkMethodCountryID($object->getMethodID(), $object->getCountryID())) {
$this->getConnection()->delete($this->getMainTable(), $this->getConnection()->quoteInto($this->getIdFieldName() . '=?', $existing_arr[$this->getIdFieldName()]));
}
return 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 $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);
}
示例4: _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)
{
$this->resolveDate($object, 'from_date');
$this->resolveDate($object, 'to_date');
parent::_beforeSave($object);
return $this;
}
示例5: _beforeSave
/**
* Perform actions before object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$object->getSortOrder()) {
$object->setSortOrder($this->_getMaxSortOrder($object) + 1);
}
return parent::_beforeSave($object);
}
示例6: _beforeSave
/**
* Process post data before saving
*
* @param \Smart2Pay\GlobalPay\Model\Method $object
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($this->checkObjectMethodID($object)) {
throw new \Magento\Framework\Exception\LocalizedException(__('Method ID already exists in database.'));
}
return parent::_beforeSave($object);
}
示例7: _beforeSave
/**
* Process post data before saving
*
* @param \Smart2Pay\GlobalPay\Model\Transaction $object
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$object->getMethodId()) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please provide a method id.'));
}
if (!$object->getMerchantTransactionId()) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please provide merchant transaction id.'));
}
if ($current_id = $this->checkMerchantTransactionID($object->getMerchantTransactionId()) and $object->getID() != $current_id) {
throw new \Magento\Framework\Exception\LocalizedException(__('Merchant transaction id already exists in database.'));
}
$time = time();
if (!$object->getPaymentID()) {
$object->setPaymentID(0);
}
if (!$object->getSiteId()) {
$object->setSiteId(0);
}
if (!$object->getPaymentStatus()) {
$object->setPaymentStatus(0);
}
if (!$object->getCreated()) {
$object->setCreated($time);
}
$object->setUpdated($time);
return parent::_beforeSave($object);
}
示例8: _beforeSave
/**
* Process testimonial 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 (!$object->getId() || !$object->getDate()) {
$object->setDate($this->_date->gmtDate());
}
return parent::_beforeSave($object);
}
示例9: _beforeSave
/**
* {@inheritdoc}
*/
protected function _beforeSave(AbstractModel $tag)
{
/** @var \Mirasvit\Blog\Model\Tag $tag */
if (!$tag->getData('url_key')) {
$tag->setData('url_key', $this->filter->translitUrl($tag->getName()));
}
return parent::_beforeSave($tag);
}
示例10: _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->isValidNewsblock($object)) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please fill out newsblock fields.'));
}
$object->setUpdateTime($this->_date->gmtDate());
return parent::_beforeSave($object);
}
示例11: _beforeSave
/**
* Before saving the object, add the created or updated times
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($object->isObjectNew() && !$object->hasCreationTime()) {
$object->setCreationTime($this->_date->gmtDate());
}
$object->setUpdateTime($this->_date->gmtDate());
return parent::_beforeSave($object);
}
示例12: _beforeSave
/**
* Process category 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->isValidPageIdentifier($object)) {
throw new \Magento\Framework\Exception\LocalizedException(__('The category URL key contains capital letters or disallowed symbols.'));
}
if ($this->isNumericPageIdentifier($object)) {
throw new \Magento\Framework\Exception\LocalizedException(__('The category URL key cannot be made of only numbers.'));
}
return parent::_beforeSave($object);
}
示例13: _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);
}
示例14: _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);
}
示例15: _beforeSave
/**
* Set date of last update
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
*/
protected function _beforeSave(AbstractModel $object)
{
/* @var $object \ClassyLlama\AvaTax\Model\Queue */
$date = $this->dateTime->gmtDate();
if ($object->isObjectNew() && !$object->getCreatedAt()) {
$object->setCreatedAt($date);
} else {
$object->setUpdatedAt($date);
}
return parent::_beforeSave($object);
}