本文整理匯總了PHP中Magento\Framework\DataObject::setRegionId方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataObject::setRegionId方法的具體用法?PHP DataObject::setRegionId怎麽用?PHP DataObject::setRegionId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Framework\DataObject
的用法示例。
在下文中一共展示了DataObject::setRegionId方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: beforeSave
/**
* Set region to the attribute
*
* @param \Magento\Framework\DataObject $object
* @return $this
*/
public function beforeSave($object)
{
if (is_numeric($object->getRegion())) {
$region = $this->_regionFactory->create()->load((int) $object->getRegion());
if ($region) {
$object->setRegionId($region->getId());
$object->setRegion($region->getCode());
}
}
return $this;
}
示例2: beforeSave
/**
* Prepare object for save
*
* @param \Magento\Framework\DataObject $object
* @return $this
*/
public function beforeSave($object)
{
$region = $object->getData('region');
if (is_numeric($region)) {
$regionModel = $this->_createRegionInstance();
$regionModel->load($region);
if ($regionModel->getId() && $object->getCountryId() == $regionModel->getCountryId()) {
$object->setRegionId($regionModel->getId())->setRegion($regionModel->getName());
}
}
return $this;
}
示例3: _applyStreetAndRegionWorkarounds
/**
* Adopt specified address object to be compatible with Magento
*
* @param \Magento\Framework\DataObject $address
* @return void
*/
protected function _applyStreetAndRegionWorkarounds(\Magento\Framework\DataObject $address)
{
// merge street addresses into 1
if ($address->hasStreet2()) {
$address->setStreet(implode("\n", [$address->getStreet(), $address->getStreetLine(2)]));
$address->unsStreet2();
}
// attempt to fetch region_id from directory
if ($address->getCountryId() && $address->getRegion()) {
$regions = $this->_countryFactory->create()->loadByCode($address->getCountryId())->getRegionCollection()->addRegionCodeOrNameFilter($address->getRegion())->setPageSize(1);
foreach ($regions as $region) {
$address->setRegionId($region->getId());
$address->setExportedKeys(array_merge($address->getExportedKeys(), ['region_id']));
break;
}
}
}