/** * Set region to the attribute * * @param Varien_Object $object * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Region */ public function beforeSave($object) { if (is_numeric($object->getRegion())) { $region = Mage::getModel('directory/region')->load((int) $object->getRegion()); if ($region) { $object->setRegionId($region->getId()); $object->setRegion($region->getCode()); } } return $this; }
public function formatAddress(Varien_Object $address, $html = false) { $address->getRegion(); $address->getCountry(); $template = $this->getData('address_template_' . ($html ? 'html' : 'plain')); if (empty($template)) { if (!$this->getId()) { $template = '{{firstname}} {{lastname}}'; } elseif (!$html) { $template = "{{firstname}} {{lastname}}\n{{company}}\n{{street1}}\n{{street2}}\n{{city}}, {{region}} {{postcode}}"; } else { $template = "{{firstname}} {{lastname}}<br/>\n{{street}}<br/>\n{{city}}, {{region}} {{postcode}}<br/>\nT: {{telephone}}"; } } $filter = new Varien_Filter_Template_Simple(); $addressText = $filter->setData($address->getData())->filter($template); if ($html) { $addressText = preg_replace('#(<br\\s*/?>\\s*){2,}#im', '<br/>', $addressText); } else { $addressText = preg_replace('#(\\n\\s*){2,}#m', "\n", $addressText); } return $addressText; }
/** * Get billing address request data * * @param Varien_Object $address * @return array */ protected function _getBillingAddress(Varien_Object $address) { $request = array('billing_first_name' => $address->getFirstname(), 'billing_last_name' => $address->getLastname(), 'billing_city' => $address->getCity(), 'billing_state' => $address->getRegion(), 'billing_zip' => $address->getPostcode(), 'billing_country' => $address->getCountry()); // convert streets to tow lines format $street = Mage::helper('customer/address')->convertStreetLines($address->getStreet(), 2); $request['billing_address1'] = isset($street[0]) ? $street[0] : ''; $request['billing_address2'] = isset($street[1]) ? $street[1] : ''; return $request; }
/** * Assigning shipping address to soap object * * @param Varien_Object $shipping */ protected function addShippingAddress($shipping) { //checking if we have shipping address, in case of virtual order we will not have it if ($shipping) { $shipTo = new stdClass(); $shipTo->firstName = $shipping->getFirstname(); $shipTo->lastName = $shipping->getLastname(); $shipTo->company = $shipping->getCompany(); $shipTo->street1 = $shipping->getStreet(1); $shipTo->street2 = $shipping->getStreet(2); $shipTo->city = $shipping->getCity(); $shipTo->state = $shipping->getRegion(); $shipTo->postalCode = $shipping->getPostcode(); $shipTo->country = $shipping->getCountry(); $shipTo->phoneNumber = $this->cleanPhoneNum($shipping->getTelephone()); $this->_request->shipTo = $shipTo; Mage::getSingleton('core/session')->setShipping($shipTo); } }
/** * Adopt specified address object to be compatible with Magento * * @param Varien_Object $address */ protected function _applyStreetAndRegionWorkarounds(Varien_Object $address) { // merge street addresses into 1 if ($address->hasStreet2()) { $address->setStreet(implode("\n", array($address->getStreet(), $address->getStreet2()))); $address->unsStreet2(); } // attempt to fetch region_id from directory if ($address->getCountryId() && $address->getRegion()) { $regions = Mage::getModel('directory/country')->loadByCode($address->getCountryId())->getRegionCollection()->addRegionCodeOrNameFilter($address->getRegion())->setPageSize(1); foreach ($regions as $region) { $address->setRegionId($region->getId()); $address->setExportedKeys(array_merge($address->getExportedKeys(), array('region_id'))); break; } } }
/** * Create new AccessCode * @param Varien_Object $billing * @param Varien_Object $infoInstance * @param string $method * @param null $request * @return Eway_Rapid31_Model_Response */ public function createAccessCode(Varien_Object $billing, Varien_Object $infoInstance, $method = 'AccessCodes', $request = null) { // Empty Varien_Object's data $tokenCustomerID = $request->get('TokenCustomerID'); $this->unsetData(); $customerParam = Mage::getModel('ewayrapid/field_customer'); $customerParam->setTokenCustomerID($tokenCustomerID)->setTitle($billing->getPrefix())->setFirstName($billing->getFirstname())->setLastName($billing->getLastname())->setCompanyName($billing->getCompany())->setJobDescription($billing->getJobDescription())->setStreet1($billing->getStreet1())->setStreet2($billing->getStreet2())->setCity($billing->getCity())->setState($billing->getRegion())->setPostalCode($billing->getPostcode())->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))->setEmail($billing->getEmail())->setPhone($billing->getTelephone())->setMobile($billing->getMobile())->setComments('')->setFax($billing->getFax())->setUrl(''); $returnUrl = Mage::getBaseUrl() . '/ewayrapid/mycards/saveToken?ccType=' . $infoInstance->getCcType() . '&expYear=' . $infoInstance->getCcExpYear(); if ($request->get('is_default') == 'on') { $returnUrl .= '&is_default=on'; } if ($infoInstance->getCcStartMonth()) { $returnUrl .= '&startMonth=' . $infoInstance->getCcStartMonth(); } if ($infoInstance->getCcStartYear()) { $returnUrl .= '&startYear=' . $infoInstance->getCcStartYear(); } if ($infoInstance->getCcIssueNumber()) { $returnUrl .= '&issueNumber=' . $infoInstance->getCcIssueNumber(); } // Binding address on url param $returnUrl .= '&street1=' . base64_encode($billing->getStreet1()) . '&street2=' . base64_encode($billing->getStreet2()); $tokenId = $request->get('token_id'); if (!empty($tokenId)) { // ID token customer will be defined to update $returnUrl = $returnUrl . '&token_id=' . $tokenId; } $this->setCustomer($customerParam); $this->setRedirectUrl($returnUrl); $this->setCancelUrl($returnUrl); $this->setMethod(!empty($tokenCustomerID) ? 'UpdateTokenCustomer' : 'CreateTokenCustomer'); $this->setCustomerIP($_SERVER["REMOTE_ADDR"]); $this->setDeviceID(''); $this->setTransactionType("Purchase"); $this->setCustomerReadOnly(true); // Create new access code //$formMethod = !empty($tokenCustomerID) ? 'PUT' : 'POST'; $response = $this->_doRapidAPI($method); return $response; }
/** * Copy address * * @param Varien_Object $srcAddress * @param Varien_Object $dstAddress * @return Innoexts_Warehouse_Helper_Data */ public function copy($srcAddress, $dstAddress) { $dstAddress->setCountryId($srcAddress->getCountryId()); $dstAddress->setRegionId($srcAddress->getRegionId()); $dstAddress->setRegion($srcAddress->getRegion()); $dstAddress->setCity($srcAddress->getCity()); $dstAddress->setPostcode($srcAddress->getPostcode()); $dstAddress->setStreet($srcAddress->getStreet()); return $this; }