作者:vasiljo
项目:magento
/**
* @param string[] $attributesAsArray
* @param \Magento\Framework\Model\AbstractExtensibleModel $model
* @return \Magento\Framework\Api\AttributeInterface[]
*/
protected function addCustomAttributesToModel($attributesAsArray, $model)
{
$addedAttributes = [];
foreach ($attributesAsArray as $attributeCode => $attributeValue) {
$addedAttributes[$attributeCode] = new AttributeValue([AttributeValue::ATTRIBUTE_CODE => $attributeCode, AttributeValue::VALUE => $attributeValue]);
}
$model->setData(array_merge($model->getData(), [\Magento\Framework\Api\CustomAttributesDataInterface::CUSTOM_ATTRIBUTES => $addedAttributes]));
return $addedAttributes;
}
作者:opexs
项目:magento
/**
* After save process
*
* @return $this
*/
public function afterSave()
{
parent::afterSave();
$this->_getResource()->saveLabel($this);
$this->_getResource()->savePrices($this);
return $this;
}
作者:shabbirvividad
项目:magento
/**
* Processing object before save data
*
* @return $this
*/
public function beforeSave()
{
if (!$this->getAttributeGroupCode()) {
$groupName = $this->getAttributeGroupName();
if ($groupName) {
$this->setAttributeGroupCode(trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($groupName)), '-'));
}
}
return parent::beforeSave();
}
作者:niranjanssie
项目:magento
/**
* Processing object before save data
*
* @return $this
*/
public function beforeSave()
{
if ($this->getContentHeight() == 0) {
$this->setContentHeight('');
//converting zero Content-Height
}
if ($this->getContentHeight() && !preg_match('/(' . implode("|", $this->allowedCssUnits) . ')/', $this->getContentHeight())) {
$contentHeight = $this->getContentHeight() . 'px';
//setting default units for Content-Height
$this->setContentHeight($contentHeight);
}
return parent::beforeSave();
}
作者:shabbirvividad
项目:magento
/**
* Retrieve data
*
* @param string $key
* @param mixed $index
* @return mixed
*/
public function getData($key = '', $index = null)
{
if ('cc_number' === $key) {
if (empty($this->_data['cc_number']) && !empty($this->_data['cc_number_enc'])) {
$this->_data['cc_number'] = $this->decrypt($this->getCcNumberEnc());
}
}
if ('cc_cid' === $key) {
if (empty($this->_data['cc_cid']) && !empty($this->_data['cc_cid_enc'])) {
$this->_data['cc_cid'] = $this->decrypt($this->getCcCidEnc());
}
}
return parent::getData($key, $index);
}
作者:whoopl
项目:magento2-testin
/**
* Processing object before save data
*
* @return $this
*/
public function beforeSave()
{
if (!$this->getAttributeGroupCode()) {
$groupName = $this->getAttributeGroupName();
if ($groupName) {
$attributeGroupCode = trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($groupName)), '-');
if (empty($attributeGroupCode)) {
// in the following code md5 is not used for security purposes
$attributeGroupCode = md5($groupName);
}
$this->setAttributeGroupCode($attributeGroupCode);
}
}
return parent::beforeSave();
}
作者:opexs
项目:magento
/**
* Validate tax class can be deleted
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function beforeDelete()
{
$this->checkClassCanBeDeleted();
return parent::beforeDelete();
}
作者:stepzerosolution
项目:cabbybas
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
* @param AttributeValueFactory $customAttributeFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
*/
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
{
$this->_storeManager = $storeManager;
parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
$this->setIncludePath();
}
作者:kidaa3
项目:magento2-platforms
/**
* Rewrite in order to clear configuration cache
*
* @return $this
*/
public function afterDelete()
{
$this->_storeManager->reinitStores();
parent::afterDelete();
return $this;
}
作者:Doabilit
项目:magento2de
/**
* @inheritdoc
*/
public function __wakeup()
{
parent::__wakeup();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$this->metadataPool = $objectManager->get(MetadataPool::class);
}
作者:pradeep-wagent
项目:magento
/**
* @return \Magento\Framework\Model\AbstractModel
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function afterSave()
{
$this->getValueInstance()->unsetValues();
if (is_array($this->getData('values'))) {
foreach ($this->getData('values') as $value) {
$this->getValueInstance()->addValue($value);
}
$this->getValueInstance()->setOption($this)->saveValues();
} elseif ($this->getGroupByType($this->getType()) == self::OPTION_GROUP_SELECT) {
throw new LocalizedException(__('Select type options required values rows.'));
}
return parent::afterSave();
}
作者:mrbada
项目:magento-c
/**
* Rewrite in order to clear configuration cache
*
* @return $this
*/
public function afterDelete()
{
parent::afterDelete();
$this->_configCacheType->clean();
return $this;
}
作者:shabbirvividad
项目:magento
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param ExtensionAttributesFactory $extensionFactory
* @param AttributeValueFactory $customAttributeFactory
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param StockConfigurationInterface $stockConfiguration
* @param StockRegistryInterface $stockRegistry
* @param StockItemRepositoryInterface $stockItemRepository
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\Db $resourceCollection
* @param array $data
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Customer\Model\Session $customerSession, \Magento\Store\Model\StoreManagerInterface $storeManager, StockConfigurationInterface $stockConfiguration, StockRegistryInterface $stockRegistry, StockItemRepositoryInterface $stockItemRepository, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = [])
{
parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
$this->customerSession = $customerSession;
$this->storeManager = $storeManager;
$this->stockConfiguration = $stockConfiguration;
$this->stockRegistry = $stockRegistry;
$this->stockItemRepository = $stockItemRepository;
}
作者:BlackIkeEagl
项目:magento2-continuousph
/**
* @return $this
*/
public function beforeDelete()
{
$this->_configDataResource->clearScopeData(\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $this->getStoreIds());
return parent::beforeDelete();
}
作者:Doabilit
项目:magento2de
/**
* @inheritdoc
*/
public function __wakeup()
{
parent::__wakeup();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$this->_eavConfig = $objectManager->get(\Magento\Eav\Model\Config::class);
$this->_eavTypeFactory = $objectManager->get(\Magento\Eav\Model\Entity\TypeFactory::class);
$this->_storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
$this->_resourceHelper = $objectManager->get(\Magento\Eav\Model\ResourceModel\Helper::class);
$this->_universalFactory = $objectManager->get(\Magento\Framework\Validator\UniversalFactory::class);
$this->optionDataFactory = $objectManager->get(\Magento\Eav\Api\Data\AttributeOptionInterfaceFactory::class);
$this->dataObjectProcessor = $objectManager->get(\Magento\Framework\Reflection\DataObjectProcessor::class);
$this->dataObjectHelper = $objectManager->get(\Magento\Framework\Api\DataObjectHelper::class);
}
作者:opexs
项目:magento
/**
* After rule delete
* Re-declared for dispatch tax_settings_change_after event
*
* @return $this
*/
public function afterDelete()
{
$this->_eventManager->dispatch('tax_settings_change_after');
return parent::afterDelete();
}
作者:shabbirvividad
项目:magento
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
* @param AttributeValueFactory $customAttributeFactory
* @param Resource\Message $resource
* @param \Magento\Framework\Data\Collection\Db $resourceCollection
* @param TypeFactory $typeFactory
* @param array $data
*/
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\GiftMessage\Model\Resource\Message $resource, \Magento\Framework\Data\Collection\Db $resourceCollection, \Magento\GiftMessage\Model\TypeFactory $typeFactory, array $data = [])
{
$this->_typeFactory = $typeFactory;
parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $resource, $resourceCollection, $data);
}
作者:Doabilit
项目:magento2de
/**
* Before save unlock attributes
*
* @return \Magento\Catalog\Model\AbstractModel
*/
public function beforeSave()
{
$this->unlockAttributes();
return parent::beforeSave();
}
作者:shabbirvividad
项目:magento
/**
* Verify data required for saving
*
* @return $this
*/
public function beforeSave()
{
// set parent id
$this->_verifyPaymentObject();
if (!$this->getId()) {
// We need to set order and payment ids only for new transactions
if (null !== $this->_paymentObject) {
$this->setPaymentId($this->_paymentObject->getId());
}
if (null !== $this->_order) {
$this->setOrderId($this->_order->getId());
}
$this->setCreatedAt($this->_dateFactory->create()->gmtDate());
}
return parent::beforeSave();
}
作者:BlackIkeEagl
项目:magento2-continuousph
/**
* Get resource instance
*
* @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
*/
protected function _getResource()
{
return $this->_resource ?: parent::_getResource();
}