本文整理汇总了PHP中Magento\Framework\Model\AbstractModel类的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel类的具体用法?PHP AbstractModel怎么用?PHP AbstractModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validate
*
* @param \Magento\Framework\Model\AbstractModel $model
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
$all = $this->getAggregator() === 'all';
$true = (bool) $this->getValue();
$found = false;
foreach ($model->getAllItems() as $item) {
$found = $all;
foreach ($this->getConditions() as $cond) {
$validated = $cond->validate($item);
if ($all && !$validated || !$all && $validated) {
$found = $validated;
break;
}
}
if ($found && $true || !$true && $found) {
break;
}
}
// found an item and we're looking for existing one
if ($found && $true) {
return true;
} elseif (!$found && !$true) {
// not found and we're making sure it doesn't exist
return true;
}
return false;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:34,代码来源:Found.php
示例2: isValid
/**
* Returns true if and only if $value meets the validation requirements.
*
* @param \Magento\Framework\Model\AbstractModel $entity
* @return bool
* @throws \InvalidArgumentException
*/
public function isValid($entity)
{
$this->_messages = [];
if (!$entity instanceof \Magento\Framework\Model\AbstractModel) {
throw new \InvalidArgumentException('Model must be extended from \\Magento\\Framework\\Model\\AbstractModel');
}
/** @var \Magento\Eav\Model\Entity\AbstractEntity $resource */
$resource = $entity->getResource();
if (!$resource instanceof \Magento\Eav\Model\Entity\AbstractEntity) {
throw new \InvalidArgumentException('Model resource must be extended from \\Magento\\Eav\\Model\\Entity\\AbstractEntity');
}
$resource->loadAllAttributes($entity);
$attributes = $resource->getAttributesByCode();
/** @var \Magento\Eav\Model\Entity\Attribute $attribute */
foreach ($attributes as $attribute) {
$backend = $attribute->getBackend();
if (!method_exists($backend, 'validate') || !is_callable([$backend, 'validate'])) {
continue;
}
try {
$result = $backend->validate($entity);
if (false === $result) {
$this->_messages[$attribute->getAttributeCode()][] = __('The value of attribute "%1" is invalid', $attribute->getAttributeCode());
} elseif (is_string($result)) {
$this->_messages[$attribute->getAttributeCode()][] = $result;
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->_messages[$attribute->getAttributeCode()][] = $e->getMessage();
}
}
return 0 == count($this->_messages);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:39,代码来源:Backend.php
示例3: _getMaxSortOrder
/**
* Retrieve max sort order
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return int
*/
protected function _getMaxSortOrder($object)
{
$adapter = $this->_getReadAdapter();
$bind = [':attribute_set_id' => $object->getAttributeSetId()];
$select = $adapter->select()->from($this->getMainTable(), new \Zend_Db_Expr("MAX(sort_order)"))->where('attribute_set_id = :attribute_set_id');
return $adapter->fetchOne($select, $bind);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Group.php
示例4: changeQueueStatusWithLocking
/**
* Update the status of a queue record and check to confirm the exclusive change
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return bool
*/
public function changeQueueStatusWithLocking(AbstractModel $object)
{
/* @var $object \ClassyLlama\AvaTax\Model\Queue */
$object->setUpdatedAt($this->dateTime->gmtDate());
$data = $this->prepareDataForUpdate($object);
$originalQueueStatus = $object->getOrigData(self::QUEUE_STATUS_FIELD_NAME);
$originalUpdatedAt = $object->getOrigData(self::UPDATED_AT_FIELD_NAME);
// A conditional update does a read lock on update so we use the condition on the old
// queue status here to guarantee that nothing else has modified the status for processing
$condition = array();
// update only the queue record identified by Id
$condition[] = $this->getConnection()->quoteInto($this->getIdFieldName() . '=?', $object->getId());
// only update the record if it is still pending
$condition[] = $this->getConnection()->quoteInto(self::QUEUE_STATUS_FIELD_NAME . '=?', $originalQueueStatus);
// only update the record if nothing else has updated it
if ($originalUpdatedAt === null) {
$condition[] = self::UPDATED_AT_FIELD_NAME . ' IS NULL';
} else {
$condition[] = $this->getConnection()->quoteInto(self::UPDATED_AT_FIELD_NAME . '=?', $originalUpdatedAt);
}
// update the record and get the number of affected records
$affectedRowCount = $this->getConnection()->update($this->getMainTable(), $data, $condition);
$result = false;
if ($affectedRowCount > 0) {
$object->setHasDataChanges(false);
$result = true;
}
return $result;
}
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:35,代码来源:Queue.php
示例5: _afterSave
/**
* Save entity types after save form type
*
* @see \Magento\Framework\Model\ModelResource\Db\AbstractDb#_afterSave($object)
*
* @param FormType|AbstractModel $object
* @return $this
*/
protected function _afterSave(AbstractModel $object)
{
if ($object->hasEntityTypes()) {
$new = $object->getEntityTypes();
$old = $this->getEntityTypes($object);
$insert = array_diff($new, $old);
$delete = array_diff($old, $new);
$connection = $this->getConnection();
if (!empty($insert)) {
$data = [];
foreach ($insert as $entityId) {
if (empty($entityId)) {
continue;
}
$data[] = ['entity_type_id' => (int) $entityId, 'type_id' => $object->getId()];
}
if ($data) {
$connection->insertMultiple($this->getTable('eav_form_type_entity'), $data);
}
}
if (!empty($delete)) {
$where = ['entity_type_id IN (?)' => $delete, 'type_id = ?' => $object->getId()];
$connection->delete($this->getTable('eav_form_type_entity'), $where);
}
}
return parent::_afterSave($object);
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:35,代码来源:Type.php
示例6: _beforeSave
/**
* {@inheritdoc}
*
* @param \Magento\Framework\Model\AbstractModel $change
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $change)
{
if (!$change->getChangeTime()) {
$change->setChangeTime($this->dateTime->formatDate(true));
}
return $this;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Change.php
示例7: _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);
}
开发者ID:smart2pay,项目名称:magento20,代码行数:14,代码来源:ConfiguredMethods.php
示例8: processRelation
/**
* Save relations for Order
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return void
* @throws \Exception
*/
public function processRelation(\Magento\Framework\Model\AbstractModel $object)
{
/** @var \Magento\Sales\Model\Order $object */
if (null !== $object->getItems()) {
/** @var \Magento\Sales\Model\Order\Item $item */
foreach ($object->getItems() as $item) {
$item->setOrderId($object->getId());
$item->setOrder($object);
$this->orderItemRepository->save($item);
}
}
if (null !== $object->getPayment()) {
$payment = $object->getPayment();
$payment->setParentId($object->getId());
$payment->setOrder($object);
$this->orderPaymentResource->save($payment);
}
if (null !== $object->getStatusHistories()) {
/** @var \Magento\Sales\Model\Order\Status\History $statusHistory */
foreach ($object->getStatusHistories() as $statusHistory) {
$statusHistory->setParentId($object->getId());
$statusHistory->setOrder($object);
$this->orderStatusHistoryResource->save($statusHistory);
}
}
if (null !== $object->getRelatedObjects()) {
foreach ($object->getRelatedObjects() as $relatedObject) {
$relatedObject->setOrder($object);
$relatedObject->save();
}
}
$this->addressHandler->removeEmptyAddresses($object);
$this->addressHandler->process($object);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:41,代码来源:Relation.php
示例9: _afterDelete
/**
* Delete all Nonce entries associated with the consumer
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
public function _afterDelete(\Magento\Framework\Model\AbstractModel $object)
{
$connection = $this->getConnection();
$connection->delete($this->getTable('oauth_nonce'), ['consumer_id' => $object->getId()]);
$connection->delete($this->getTable('oauth_token'), ['consumer_id' => $object->getId()]);
return parent::_afterDelete($object);
}
开发者ID:razbakov,项目名称:magento2,代码行数:13,代码来源:Consumer.php
示例10: aroundDelete
/**
* Reindex on product delete
*
* @param \Magento\Catalog\Model\ResourceModel\Product $productResource
* @param \Closure $proceed
* @param \Magento\Framework\Model\AbstractModel $product
* @return \Magento\Catalog\Model\ResourceModel\Product
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDelete(\Magento\Catalog\Model\ResourceModel\Product $productResource, \Closure $proceed, \Magento\Framework\Model\AbstractModel $product)
{
$productResource->addCommitCallback(function () use($product) {
$this->reindexRow($product->getEntityId());
});
return $proceed($product);
}
开发者ID:dragonsword007008,项目名称:magento2,代码行数:16,代码来源:Product.php
示例11: _afterDelete
/**
* Delete all Nonce entries associated with the consumer
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
public function _afterDelete(\Magento\Framework\Model\AbstractModel $object)
{
$adapter = $this->_getWriteAdapter();
$adapter->delete($this->getTable('oauth_nonce'), array('consumer_id' => $object->getId()));
$adapter->delete($this->getTable('oauth_token'), array('consumer_id' => $object->getId()));
return parent::_afterDelete($object);
}
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:Consumer.php
示例12: _afterSave
/**
* Perform actions after object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
/** @var \Magento\Sales\Model\Order\Invoice\Item $object */
if (null == !$object->getOrderItem()) {
$object->getOrderItem()->save();
}
return parent::_afterSave($object);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:Item.php
示例13: _beforeSave
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!$object->getId()) {
$object->setCreatedAt($this->_date->gmtDate());
}
$object->setUpdatedAt($this->_date->gmtDate());
return $this;
}
开发者ID:pradeeprcs,项目名称:TestModule,代码行数:8,代码来源:Test.php
示例14: beforeSave
/**
* Set created date
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
public function beforeSave($object)
{
$attributeCode = $this->getAttribute()->getAttributeCode();
if ($object->isObjectNew() && $object->getData($attributeCode) === null) {
$object->setData($attributeCode, gmdate(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
}
return $this;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:Created.php
示例15: _afterLoad
/**
* Method to run after load
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterLoad(\Magento\Framework\Model\AbstractModel $object)
{
$select = $this->getConnection()->select()->from($this->getTable('checkout_agreement_store'), ['store_id'])->where('agreement_id = :agreement_id');
if ($stores = $this->getConnection()->fetchCol($select, [':agreement_id' => $object->getId()])) {
$object->setData('store_id', $stores);
}
return parent::_afterLoad($object);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Agreement.php
示例16: beforeSave
/**
* Before save handler
*
* @param \Magento\Cms\Model\ResourceModel\Page $subject
* @param \Magento\Framework\Model\AbstractModel $object
*
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeSave(\Magento\Cms\Model\ResourceModel\Page $subject, \Magento\Framework\Model\AbstractModel $object)
{
/** @var $object \Magento\Cms\Model\Page */
$urlKey = $object->getData('identifier');
if ($urlKey === '' || $urlKey === null) {
$object->setData('identifier', $this->cmsPageUrlPathGenerator->generateUrlKey($object));
}
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:Page.php
示例17: _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);
}
开发者ID:mirasvit,项目名称:module-blog,代码行数:11,代码来源:Tag.php
示例18: _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;
}
开发者ID:nja78,项目名称:magento2,代码行数:14,代码来源:Bookmark.php
示例19: resolveDate
/**
* @param \Magento\Framework\Model\AbstractModel $object
* @param string $dateIdentifier
* @return void
*/
private function resolveDate(\Magento\Framework\Model\AbstractModel $object, $dateIdentifier)
{
$date = $object->getData($dateIdentifier);
if ($date instanceof \DateTime) {
$object->setData($dateIdentifier, $date->format('Y-m-d H:i:s'));
} elseif (!is_string($date) || empty($date)) {
$object->setData($dateIdentifier, null);
}
}
开发者ID:dragonsword007008,项目名称:magento2,代码行数:14,代码来源:AbstractResource.php
示例20: _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);
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:Template.php
注:本文中的Magento\Framework\Model\AbstractModel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论