本文整理汇总了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;
}
}
}