本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::setCreatedAt方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::setCreatedAt方法的具体用法?PHP AbstractModel::setCreatedAt怎么用?PHP AbstractModel::setCreatedAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::setCreatedAt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$object->getId()) {
$object->setCreatedAt($this->_date->gmtDate());
}
$object->setUpdatedAt($this->_date->gmtDate());
return $this;
}
示例2: _beforeSave
/**
* Prepare data to be saved to database
* @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
*
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($object->isObjectNew()) {
$object->setCreatedAt($this->dateTime->formatDate(true));
}
$object->setUpdatedAt($this->dateTime->formatDate(true));
return $this;
}
示例3: _beforeSave
/**
* @param \Magento\Framework\Model\AbstractModel $object
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($object->isObjectNew() && !$object->hasCreatedAt()) {
$object->setCreatedAt($this->_date->gmtDate());
}
$object->setUpdatedAt($this->_date->gmtDate());
return parent::_beforeSave($object);
}
示例4: _prepareDataForSave
/**
* Prepare data for save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return array
*/
protected function _prepareDataForSave(\Magento\Framework\Model\AbstractModel $object)
{
$currentTime = $this->dateTime->now();
if ((!$object->getId() || $object->isObjectNew()) && !$object->getCreatedAt()) {
$object->setCreatedAt($currentTime);
}
$object->setUpdatedAt($currentTime);
$data = parent::_prepareDataForSave($object);
return $data;
}
示例5: _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);
}
示例6: _beforeSave
/**
* before save callback
*
* @param \Magento\Framework\Model\AbstractModel|\Mageplaza\Blog\Model\Topic $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
$object->setUpdatedAt($this->date->date());
if ($object->isObjectNew()) {
$object->setCreatedAt($this->date->date());
}
//Check Url Key
if ($object->isObjectNew()) {
$count = 0;
$objName = $object->getName();
if ($object->getUrlKey()) {
$urlKey = $object->getUrlKey();
} else {
$urlKey = $this->generateUrlKey($objName, $count);
}
while ($this->checkUrlKey($urlKey)) {
$count++;
$urlKey = $this->generateUrlKey($urlKey, $count);
}
$object->setUrlKey($urlKey);
} else {
$objectId = $object->getId();
$count = 0;
$objName = $object->getName();
if ($object->getUrlKey()) {
$urlKey = $object->getUrlKey();
} else {
$urlKey = $this->generateUrlKey($objName, $count);
}
while ($this->checkUrlKey($urlKey, $objectId)) {
$count++;
$urlKey = $this->generateUrlKey($urlKey, $count);
}
$object->setUrlKey($urlKey);
}
return parent::_beforeSave($object);
}
示例7: _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;
}
示例8: _afterSave
/**
* Perform actions after object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
$connection = $this->getConnection();
$columns = $connection->describeTable($this->getMainTable());
if (isset($columns['created_at'], $columns['updated_at'])) {
$select = $connection->select()->from($this->getMainTable(), ['created_at', 'updated_at'])->where($this->getIdFieldName() . ' = :entity_id');
$row = $connection->fetchRow($select, [':entity_id' => $object->getId()]);
if (is_array($row) && isset($row['created_at'], $row['updated_at'])) {
$object->setCreatedAt($row['created_at']);
$object->setUpdatedAt($row['updated_at']);
}
}
parent::_afterSave($object);
return $this;
}
示例9: _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->setCreatedAt($this->dateTime->formatDate(true));
}
$object->setModifiedAt($this->dateTime->formatDate(true));
$object->setTemplateType((int) $object->getTemplateType());
return parent::_beforeSave($object);
}
示例10: _beforeSave
/**
* before save callback
*
* @param AbstractModel|\Sample\News\Model\Author $object
* @return $this
*/
protected function _beforeSave(AbstractModel $object)
{
foreach (['dob'] as $field) {
$value = !$object->getData($field) ? null : $object->getData($field);
$object->setData($field, $this->dateTime->formatDate($value));
}
$object->setUpdatedAt($this->date->gmtDate());
if ($object->isObjectNew()) {
$object->setCreatedAt($this->date->gmtDate());
}
$urlKey = $object->getData('url_key');
if ($urlKey == '') {
$urlKey = $object->getName();
}
$urlKey = $object->formatUrlKey($urlKey);
$object->setUrlKey($urlKey);
$validKey = false;
while (!$validKey) {
if ($this->getIsUniqueAuthorToStores($object)) {
$validKey = true;
} else {
$parts = explode('-', $urlKey);
$last = $parts[count($parts) - 1];
if (!is_numeric($last)) {
$urlKey = $urlKey . '-1';
} else {
$suffix = '-' . ($last + 1);
unset($parts[count($parts) - 1]);
$urlKey = implode('-', $parts) . $suffix;
}
$object->setData('url_key', $urlKey);
}
}
return parent::_beforeSave($object);
}
示例11: _beforeSave
/**
* before save callback
*
* @param \Magento\Framework\Model\AbstractModel|\Mageplaza\Blog\Model\Category $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
$object->setUpdatedAt($this->date->date());
if ($object->isObjectNew()) {
$object->setCreatedAt($this->date->date());
}
/** @var \Mageplaza\Blog\Model\Category $object */
parent::_beforeSave($object);
if (!$object->getChildrenCount()) {
$object->setChildrenCount(0);
}
if ($object->isObjectNew()) {
if ($object->getPosition() === null) {
$object->setPosition($this->getMaxPosition($object->getPath()) + 1);
}
$path = explode('/', $object->getPath());
$level = count($path) - ($object->getId() ? 1 : 0);
$toUpdateChild = array_diff($path, [$object->getId()]);
if (!$object->hasPosition()) {
$object->setPosition($this->getMaxPosition(implode('/', $toUpdateChild)) + 1);
}
if (!$object->hasLevel()) {
$object->setLevel($level);
}
if (!$object->hasParentId() && $level && !$object->getInitialSetupFlag()) {
$object->setParentId($path[$level - 1]);
}
if (!$object->getId() && !$object->getInitialSetupFlag()) {
$object->setPath($object->getPath() . '/');
}
if (!$object->getInitialSetupFlag()) {
$this->getConnection()->update($this->getMainTable(), ['children_count' => new \Zend_Db_Expr('children_count+1')], ['category_id IN(?)' => $toUpdateChild]);
}
}
//Check Url Key
if ($object->isObjectNew()) {
$count = 0;
$objName = $object->getName();
if ($object->getUrlKey()) {
$urlKey = $object->getUrlKey();
} else {
$urlKey = $this->generateUrlKey($objName, $count);
}
while ($this->checkUrlKey($urlKey)) {
$count++;
$urlKey = $this->generateUrlKey($urlKey, $count);
}
$object->setUrlKey($urlKey);
} else {
$objectId = $object->getId();
$count = 0;
$objName = $object->getName();
if ($object->getUrlKey()) {
$urlKey = $object->getUrlKey();
} else {
$urlKey = $this->generateUrlKey($objName, $count);
}
while ($this->checkUrlKey($urlKey, $objectId)) {
$count++;
$urlKey = $this->generateUrlKey($urlKey, $count);
}
$object->setUrlKey($urlKey);
}
return $this;
}