Add Address via Script.. is there any API ?

  • Posts: 175
  • Thank you received: 0
8 years 5 months ago #242963

-- HikaShop version -- : 2.6.3

Hello,
i have a custom checkout, i need to add address via script.. is there any API that handle this ? if not, can you point me which script that done this process.. i will try to duplicate the script in my custom script

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
8 years 5 months ago #242965

Hi,

I would recommend to have a look at the code of the the PayPal Express plugin where it creates an address based on the data provided by PayPal:

						$address = $this->createAddress($vars,$userid);
						$addressClass = hikashop_get('class.address');
						$addressid = $addressClass->save($address);

	function createAddress($vars,$userid) {
		
		if (empty($userid) )
			return false;
		else {
			
			$db = JFactory::getDBO();

			if(!empty($vars['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] ) ) {
				
				$db->setQuery('SELECT zone_namekey FROM `#__hikashop_zone` WHERE zone_code_2 = '.
				$db->Quote($vars['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE']).' AND zone_type = \'country\';');
				
				$country = $db->loadResult();
			}
			
			if (empty($country) ) {
				
				$db->setQuery('SELECT zone_namekey FROM `#__hikashop_zone` WHERE zone_name_english = '.
					$db->Quote($vars['PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME']).' AND zone_type = \'country\';');
				
				$country = $db->loadResult();
				
				if (empty($country))
					$country = $vars['PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME'];
			}

			if (empty($vars['PAYMENTREQUEST_0_SHIPTOSTATE'] ) )
				$state = "NULL";
			else {
				$db->setQuery('SELECT zone_namekey FROM `#__hikashop_zone` WHERE zone_code_2 = '
						.$db->Quote($vars['PAYMENTREQUEST_0_SHIPTOSTATE']).' AND zone_type = \'state\';');
				
				$state = $db->loadResult();
				
				if (empty($state) )
					$state = $vars['PAYMENTREQUEST_0_SHIPTOSTATE'];
			}
			
			$address = new stdClass();
			$address->address_user_id = $userid;
			$address->address_firstname = $vars['FIRSTNAME'];
			$address->address_lastname = $vars['LASTNAME'];
			$address->address_street = $vars['PAYMENTREQUEST_0_SHIPTOSTREET'];
			$address->address_post_code = $vars['PAYMENTREQUEST_0_SHIPTOZIP'];
			$address->address_city = $vars['PAYMENTREQUEST_0_SHIPTOCITY'];
			$address->address_state = $state;
			$address->address_country = $country;
		}

		return $address;
	}
You can find that in plugins/hikashoppayment/paypalexpress/

Please Log in or Create an account to join the conversation.

Time to create page: 0.052 seconds
Powered by Kunena Forum