当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractModel::getResource方法代码示例

本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::getResource方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::getResource方法的具体用法?PHP AbstractModel::getResource怎么用?PHP AbstractModel::getResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Model\AbstractModel的用法示例。


在下文中一共展示了AbstractModel::getResource方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->model = $this->objectManager->create('Magento\\Security\\Model\\PasswordResetRequestEvent');
     $this->resourceModel = $this->model->getResource();
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:7,代码来源:PasswordResetRequestEventTest.php

示例2: processRelation

 /**
  * Save relations for Customer
  *
  * @param \Magento\Framework\Model\AbstractModel $customer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function processRelation(\Magento\Framework\Model\AbstractModel $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     /** @var \Magento\Customer\Model\Address $address */
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             $removedAddressId = $address->getId();
             $address->delete();
             // Remove deleted address from customer address collection
             $customer->getAddressesCollection()->removeItemByKey($removedAddressId);
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
     }
     $changedAddresses = [];
     $changedAddresses['default_billing'] = $customer->getData('default_billing');
     $changedAddresses['default_shipping'] = $customer->getData('default_shipping');
     $customer->getResource()->getConnection()->update($customer->getResource()->getTable('customer_entity'), $changedAddresses, $customer->getResource()->getConnection()->quoteInto('entity_id = ?', $customer->getId()));
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:39,代码来源:Relation.php

示例3: 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

示例4: df_eav_partial_save

/**
 * 2016-08-22
 * @param AbstractModel $model
 * @return void
 */
function df_eav_partial_save(AbstractModel $model)
{
    /** @var AbstractEntity $resource */
    $resource = $model->getResource();
    $resource->isPartialSave(true);
    try {
        $model->save();
    } finally {
        $resource->isPartialSave(false);
    }
}
开发者ID:mage2pro,项目名称:core,代码行数:16,代码来源:main.php

示例5: validate

 /**
  * Validate product attribute value for condition
  *
  * @param \Magento\Framework\Model\AbstractModel $model
  * @return bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function validate(\Magento\Framework\Model\AbstractModel $model)
 {
     $attrCode = $this->getAttribute();
     if ('category_ids' == $attrCode) {
         return $this->validateAttribute($model->getAvailableInCategories());
     } elseif (!isset($this->_entityAttributeValues[$model->getId()])) {
         if (!$model->getResource()) {
             return false;
         }
         $attr = $model->getResource()->getAttribute($attrCode);
         if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
             $this->setValue(strtotime($this->getValue()));
             $value = strtotime($model->getData($attrCode));
             return $this->validateAttribute($value);
         }
         if ($attr && $attr->getFrontendInput() == 'multiselect') {
             $value = $model->getData($attrCode);
             $value = strlen($value) ? explode(',', $value) : [];
             return $this->validateAttribute($value);
         }
         return parent::validate($model);
     } else {
         $result = false;
         // any valid value will set it to TRUE
         // remember old attribute state
         $oldAttrValue = $model->hasData($attrCode) ? $model->getData($attrCode) : null;
         foreach ($this->_entityAttributeValues[$model->getId()] as $value) {
             $attr = $model->getResource()->getAttribute($attrCode);
             if ($attr && $attr->getBackendType() == 'datetime') {
                 $value = strtotime($value);
             } elseif ($attr && $attr->getFrontendInput() == 'multiselect') {
                 $value = strlen($value) ? explode(',', $value) : [];
             }
             $model->setData($attrCode, $value);
             $result |= parent::validate($model);
             if ($result) {
                 break;
             }
         }
         if ($oldAttrValue === null) {
             $model->unsetData($attrCode);
         } else {
             $model->setData($attrCode, $oldAttrValue);
         }
         return (bool) $result;
     }
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:55,代码来源:AbstractProduct.php

示例6: _prepareMultiselectValue

 /**
  * Prepare multiselect attribute value
  *
  * @param mixed $value
  * @param \Magento\Framework\Model\AbstractModel $model
  * @return mixed
  */
 protected function _prepareMultiselectValue($value, \Magento\Framework\Model\AbstractModel $model)
 {
     $attribute = $model->getResource()->getAttribute($this->getAttribute());
     if ($attribute && $attribute->getFrontendInput() == 'multiselect') {
         $value = strlen($value) ? explode(',', $value) : [];
     }
     return $value;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Product.php

示例7: _getAttributes

 /**
  * Get attributes involved in validation.
  *
  * This method return specified $_attributes if they defined by setAttributes method, otherwise if $entity
  * is EAV-model it returns it's all available attributes, otherwise it return empty array.
  *
  * @param \Magento\Framework\Model\AbstractModel $entity
  * @return array
  */
 protected function _getAttributes($entity)
 {
     /** @var \Magento\Eav\Model\Attribute[] $attributes */
     $attributes = [];
     if ($this->_attributes) {
         $attributes = $this->_attributes;
     } elseif ($entity instanceof \Magento\Framework\Model\AbstractModel && $entity->getResource() instanceof \Magento\Eav\Model\Entity\AbstractEntity) {
         // $entity is EAV-model
         /** @var \Magento\Eav\Model\Entity\Type $entityType */
         $entityType = $entity->getEntityType();
         $attributes = $entityType->getAttributeCollection()->getItems();
     }
     $attributesByCode = [];
     $attributesCodes = [];
     foreach ($attributes as $attribute) {
         if (!$attribute->getIsVisible()) {
             continue;
         }
         $attributeCode = $attribute->getAttributeCode();
         $attributesByCode[$attributeCode] = $attribute;
         $attributesCodes[] = $attributeCode;
     }
     $ignoreAttributes = $this->_attributesBlackList;
     if ($this->_attributesWhiteList) {
         $ignoreAttributes = array_merge($ignoreAttributes, array_diff($attributesCodes, $this->_attributesWhiteList));
     }
     foreach ($ignoreAttributes as $attributeCode) {
         unset($attributesByCode[$attributeCode]);
     }
     return $attributesByCode;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:40,代码来源:Data.php


注:本文中的Magento\Framework\Model\AbstractModel::getResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。