Пример #1
0
 /**
  * update customer when edit shipping address to paypal
  *
  * @param $accessCode
  */
 public function updateCustomer($accessCode)
 {
     $response = $this->_doRapidAPI('Transaction/' . $accessCode, 'GET');
     if ($response->isSuccess()) {
         $customer = $this->_quote->getCustomer();
         $billingAddress = $this->_quote->getBillingAddress();
         $shippingAddress = $this->_quote->getShippingAddress();
         $trans = $response->getTransactions();
         if (isset($trans[0]['Customer'])) {
             $billing = $trans[0]['Customer'];
             $billingAddress->setFirstname($billing['FirstName'])->setLastName($billing['LastName'])->setCompany($billing['CompanyName'])->setJobDescription($billing['JobDescription'])->setStreet($billing['Street1'])->setStreet2($billing['Street2'])->setCity($billing['City'])->setState($billing['State'])->setPostcode($billing['PostalCode'])->setCountryId(strtoupper($billing['Country']))->setEmail($billing['Email'])->setTelephone($billing['Phone'])->setMobile($billing['Mobile'])->setComments($billing['Comments'])->setFax($billing['Fax'])->setUrl($billing['Url']);
         }
         if (isset($trans[0]['ShippingAddress'])) {
             $shipping = $trans[0]['ShippingAddress'];
             $shippingAddress->setFirstname($shipping['FirstName'])->setLastname($shipping['LastName'])->setStreet($shipping['Street1'])->setStreet2($shipping['Street2'])->setCity($shipping['City'])->setPostcode($shipping['PostalCode'])->setCountryId(strtoupper($shipping['Country']))->setEmail($shipping['Email'])->setFax($shipping['Fax']);
             if ($shipping['State'] && $shipping['Country'] && ($region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country']))) {
                 $shippingAddress->setRegion($region->getName())->setRegionId($region->getId());
             }
             if ($shipping['Phone']) {
                 $shippingAddress->setTelephone($shipping['Phone']);
             }
         }
         $this->_quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
     }
 }
Пример #2
0
 /**
  * Assign customer model to quote with billing and shipping address change
  *
  * @param  Mage_Customer_Model_Customer    $customer
  * @param  Mage_Sales_Model_Quote_Address  $billingAddress
  * @param  Mage_Sales_Model_Quote_Address  $shippingAddress
  * @return Kkoepke_CheckoutAddressFix_Model_Quote
  */
 public function assignCustomerWithAddressChange(Mage_Customer_Model_Customer $customer, Mage_Sales_Model_Quote_Address $billingAddress = null, Mage_Sales_Model_Quote_Address $shippingAddress = null)
 {
     // customer has id
     if ($customer->getId()) {
         // indiviual billing address and shipping address has been defined
         if (!is_null($billingAddress) && !is_null($shippingAddress)) {
             return parent::assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress);
         }
         // if billing address is not set
         if (is_null($billingAddress)) {
             $tmpBillingAddress = $this->getBillingAddress();
             /* @var $tmpBillingAddress Mage_Sales_Model_Quote_Address */
             $caid = (int) $tmpBillingAddress->getCustomerAddressId();
             if (is_null($tmpBillingAddress->getCustomerAddressId()) && is_null($tmpBillingAddress->getCity()) || $caid > 0 && $customer->getDefaultBillingAddress() && $caid == $customer->getDefaultBillingAddress()->getId()) {
                 $billingAddress = null;
             } else {
                 // set billing address from quote
                 $billingAddress = $tmpBillingAddress;
             }
         }
         // if shipping address is not set
         if (is_null($shippingAddress)) {
             $tmpShippingAddress = $this->getShippingAddress();
             /* @var $tmpShippingAddress Mage_Sales_Model_Quote_Address */
             $caid = (int) $tmpShippingAddress->getCustomerAddressId();
             if (is_null($tmpShippingAddress->getCustomerAddressId()) && is_null($tmpShippingAddress->getCity()) || $caid > 0 && $customer->getDefaultShippingAddress() && $caid == $customer->getDefaultShippingAddress()->getId()) {
                 $shippingAddress = null;
             } else {
                 // set billing address from quote
                 $shippingAddress = $tmpShippingAddress;
             }
         }
         return parent::assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress);
         // on else use origin magento model
     } else {
         return parent::assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress);
     }
     return $this;
 }
 /**
  * Setter for customer with billing and shipping address changing ability
  *
  * @param  Mage_Customer_Model_Customer   $customer
  * @param  Mage_Sales_Model_Quote_Address $billingAddress
  * @param  Mage_Sales_Model_Quote_Address $shippingAddress
  *
  * @return Mage_Paypal_Model_Express_Checkout
  */
 public function setCustomerWithAddressChange($customer, $billingAddress = null, $shippingAddress = null)
 {
     $this->_quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress);
     $this->_customerId = $customer->getId();
     return $this;
 }
Пример #4
0
 /**
  * Update customer info
  * @param $transId
  * @return mixed
  */
 public function updateCustomer($accessCode, Mage_Sales_Model_Quote $quote)
 {
     try {
         $results = $this->_doRapidAPI("Transaction/{$accessCode}", 'GET');
         if (!$results->isSuccess()) {
             Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)', $results->getMessage()));
         }
         $customer = $quote->getCustomer();
         $billingAddress = $quote->getBillingAddress();
         $shippingAddress = $quote->getShippingAddress();
         if ($results->isSuccess()) {
             $trans = $results->getTransactions();
             if (isset($trans[0]['Customer'])) {
                 $billing = $trans[0]['Customer'];
                 $billingAddress->setFirstname($billing['FirstName'])->setLastName($billing['LastName'])->setCompany($billing['CompanyName'])->setJobDescription($billing['JobDescription'])->setStreet($billing['Street1'])->setStreet2($billing['Street2'])->setCity($billing['City'])->setState($billing['State'])->setPostcode($billing['PostalCode'])->setCountryId(strtoupper($billing['Country']))->setEmail($billing['Email'])->setTelephone($billing['Phone'])->setMobile($billing['Mobile'])->setComments($billing['Comments'])->setFax($billing['Fax'])->setUrl($billing['Url']);
             }
             if (isset($trans[0]['ShippingAddress'])) {
                 $shipping = $trans[0]['ShippingAddress'];
                 $shippingAddress->setFirstname($shipping['FirstName'])->setLastname($shipping['LastName'])->setStreet($shipping['Street1'])->setStreet2($shipping['Street2'])->setCity($shipping['City'])->setPostcode($shipping['PostalCode'])->setCountryId(strtoupper($shipping['Country']))->setEmail($shipping['Email'])->setFax($shipping['Fax']);
                 if ($shipping['State'] && $shipping['Country'] && ($region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country']))) {
                     $shippingAddress->setRegion($region->getName())->setRegionId($region->getId());
                 }
                 if ($shipping['Phone']) {
                     $shippingAddress->setTelephone($shipping['Phone']);
                 }
             }
             return $quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
         }
         return false;
     } catch (Exception $e) {
         Mage::throwException($e->getMessage());
         return false;
     }
 }