本文整理汇总了PHP中Magento\Framework\Model\AbstractExtensibleModel::beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractExtensibleModel::beforeSave方法的具体用法?PHP AbstractExtensibleModel::beforeSave怎么用?PHP AbstractExtensibleModel::beforeSave使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractExtensibleModel
的用法示例。
在下文中一共展示了AbstractExtensibleModel::beforeSave方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
/**
* 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();
}
示例2: beforeSave
/**
* 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();
}
示例3: beforeSave
/**
* 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();
}
示例4: beforeSave
/**
* @return $this
*/
public function beforeSave()
{
parent::beforeSave();
$this->getRegion();
return $this;
}
示例5: beforeSave
/**
* Prepare data before save
*
* @return $this
*/
public function beforeSave()
{
/**
* Currency logic
*
* global - currency which is set for default in backend
* base - currency which is set for current website. all attributes that
* have 'base_' prefix saved in this currency
* quote/order - currency which was selected by customer or configured by
* admin for current store. currency in which customer sees
* price thought all checkout.
*
* Rates:
* base_to_global & base_to_quote/base_to_order
*/
$globalCurrencyCode = $this->_config->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, 'default');
$baseCurrency = $this->getStore()->getBaseCurrency();
if ($this->hasForcedCurrency()) {
$quoteCurrency = $this->getForcedCurrency();
} else {
$quoteCurrency = $this->getStore()->getCurrentCurrency();
}
$this->setGlobalCurrencyCode($globalCurrencyCode);
$this->setBaseCurrencyCode($baseCurrency->getCode());
$this->setStoreCurrencyCode($baseCurrency->getCode());
$this->setQuoteCurrencyCode($quoteCurrency->getCode());
$this->setBaseToGlobalRate($baseCurrency->getRate($globalCurrencyCode));
$this->setBaseToQuoteRate($baseCurrency->getRate($quoteCurrency));
if (!$this->hasChangedFlag() || $this->getChangedFlag() == true) {
$this->setIsChanged(1);
} else {
$this->setIsChanged(0);
}
if ($this->_customer) {
$this->setCustomerId($this->_customer->getId());
}
//mark quote if it has virtual products only
$this->setIsVirtual($this->getIsVirtual());
parent::beforeSave();
}
示例6: beforeSave
/**
* 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();
}
示例7: beforeSave
/**
* Prepare data before saving
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function beforeSave()
{
// Check if discount amount not negative
if ($this->hasDiscountAmount()) {
if ((int) $this->getDiscountAmount() < 0) {
throw new \Magento\Framework\Exception\LocalizedException(__('Please choose a valid discount amount.'));
}
}
// Serialize conditions
if ($this->getConditions()) {
$this->setConditionsSerialized(serialize($this->getConditions()->asArray()));
$this->_conditions = null;
}
// Serialize actions
if ($this->getActions()) {
$this->setActionsSerialized(serialize($this->getActions()->asArray()));
$this->_actions = null;
}
/**
* Prepare website Ids if applicable and if they were set as string in comma separated format.
* Backwards compatibility.
*/
if ($this->hasWebsiteIds()) {
$websiteIds = $this->getWebsiteIds();
if (is_string($websiteIds) && !empty($websiteIds)) {
$this->setWebsiteIds(explode(',', $websiteIds));
}
}
/**
* Prepare customer group Ids if applicable and if they were set as string in comma separated format.
* Backwards compatibility.
*/
if ($this->hasCustomerGroupIds()) {
$groupIds = $this->getCustomerGroupIds();
if (is_string($groupIds) && !empty($groupIds)) {
$this->setCustomerGroupIds(explode(',', $groupIds));
}
}
parent::beforeSave();
return $this;
}
示例8: beforeSave
/**
* Before save unlock attributes
*
* @return \Magento\Catalog\Model\AbstractModel
*/
public function beforeSave()
{
$this->unlockAttributes();
return parent::beforeSave();
}
示例9: beforeSave
/**
* Specify parent item id before saving data
*
* @return $this
*/
public function beforeSave()
{
parent::beforeSave();
if ($this->getParentItem()) {
$this->setParentItemId($this->getParentItem()->getId());
}
return $this;
}
示例10: beforeSave
/**
* Prepare location settings and tax postcode before save rate
*
* @return \Magento\Tax\Model\Calculation\Rate
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function beforeSave()
{
$isWrongRange = $this->getZipIsRange() && ($this->getZipFrom() === '' || $this->getZipTo() === '');
$isEmptyValues = $this->getCode() === '' || $this->getTaxCountryId() === '' || $this->getRate() === '' || $this->getTaxPostcode() === '' && !$this->getZipIsRange();
if ($isEmptyValues || $isWrongRange) {
throw new \Magento\Framework\Exception\LocalizedException(__('Make sure all required information is valid.'));
}
if (!is_numeric($this->getRate()) || $this->getRate() < 0) {
throw new \Magento\Framework\Exception\LocalizedException(__('The Rate Percent should be a positive number.'));
}
if ($this->getZipIsRange()) {
$zipFrom = $this->getZipFrom();
$zipTo = $this->getZipTo();
if (strlen($zipFrom) > 9 || strlen($zipTo) > 9) {
throw new \Magento\Framework\Exception\LocalizedException(__('Maximum zip code length is 9.'));
}
if (!is_numeric($zipFrom) || !is_numeric($zipTo) || $zipFrom < 0 || $zipTo < 0) {
throw new \Magento\Framework\Exception\LocalizedException(__('Use digits only for the zip code.'));
}
if ($zipFrom > $zipTo) {
throw new \Magento\Framework\Exception\LocalizedException(__('Range To should be equal or greater than Range From.'));
}
$this->setTaxPostcode($zipFrom . '-' . $zipTo);
} else {
$taxPostCode = $this->getTaxPostcode();
if (strlen($taxPostCode) > 10) {
$taxPostCode = substr($taxPostCode, 0, 10);
}
$this->setTaxPostcode($taxPostCode)->setZipIsRange(null)->setZipFrom(null)->setZipTo(null);
}
parent::beforeSave();
$country = $this->getTaxCountryId();
$region = $this->getTaxRegionId();
/** @var $regionModel \Magento\Directory\Model\Region */
$regionModel = $this->_regionFactory->create();
$regionModel->load($region);
if ($regionModel->getCountryId() != $country) {
$this->setTaxRegionId('*');
}
return $this;
}
示例11: beforeSave
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function beforeSave()
{
parent::beforeSave();
if ($this->getData('previous_type') != '') {
$previousType = $this->getData('previous_type');
/**
* if previous option has different group from one is came now
* need to remove all data of previous group
*/
if ($this->getGroupByType($previousType) != $this->getGroupByType($this->getData('type'))) {
switch ($this->getGroupByType($previousType)) {
case self::OPTION_GROUP_SELECT:
$this->unsetData('values');
if ($this->getId()) {
$this->getValueInstance()->deleteValue($this->getId());
}
break;
case self::OPTION_GROUP_FILE:
$this->setData('file_extension', '');
$this->setData('image_size_x', '0');
$this->setData('image_size_y', '0');
break;
case self::OPTION_GROUP_TEXT:
$this->setData('max_characters', '0');
break;
case self::OPTION_GROUP_DATE:
break;
}
if ($this->getGroupByType($this->getData('type')) == self::OPTION_GROUP_SELECT) {
$this->setData('sku', '');
$this->unsetData('price');
$this->unsetData('price_type');
if ($this->getId()) {
$this->deletePrices($this->getId());
}
}
}
}
return $this;
}