當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataObject::setRegionId方法代碼示例

本文整理匯總了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;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:17,代碼來源:Region.php

示例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;
 }
開發者ID:tingyeeh,項目名稱:magento2,代碼行數:18,代碼來源:Region.php

示例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;
         }
     }
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:23,代碼來源:Nvp.php


注:本文中的Magento\Framework\DataObject::setRegionId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。