本文整理汇总了PHP中Magento\Framework\Model\AbstractModel类的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel类的具体用法?PHP AbstractModel怎么用?PHP AbstractModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}