Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #517: add class that extends UcAddress for quotes #522

Open
wants to merge 2 commits into
base: 1.x-3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions shipping/uc_quote/address_quote.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* UcAddressQuote class
*/

/**
* Defines an object to hold Ubercart address for shipping quotes on products.
*/
class UcAddressQuote extends UcAddress {
/**
* The node ID of the product with the quote.
*
* @var int
*/
public $nid;
}
10 changes: 6 additions & 4 deletions shipping/uc_quote/uc_quote.module
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function uc_quote_node_load($nodes, $types) {
$shipping_type = config_get('uc_shipping.settings', 'uc_store_shipping_type');
$shipping_types = db_query("SELECT id, shipping_type FROM {uc_quote_shipping_types} WHERE id_type = :type AND id IN (:ids)", array(':type' => 'product', ':ids' => array_keys($nodes)))->fetchAllKeyed();

$addresses = db_query("SELECT nid, first_name, last_name, company, street1, street2, city, zone, postal_code, country, phone FROM {uc_quote_product_locations} WHERE nid IN (:nids)", array(':nids' => array_keys($nodes)), array('fetch' => 'UcAddress'))->fetchAllAssoc('nid');
$addresses = db_query("SELECT nid, first_name, last_name, company, street1, street2, city, zone, postal_code, country, phone FROM {uc_quote_product_locations} WHERE nid IN (:nids)", array(':nids' => array_keys($nodes)), array('fetch' => 'UcAddressQuote'))->fetchAllAssoc('nid');

foreach ($nodes as $nid => &$node) {
if (!in_array($node->type, $product_types)) {
Expand Down Expand Up @@ -479,10 +479,10 @@ function uc_product_get_shipping_type($product) {
* the store's shipping address if the product's is not set.
*/
function uc_quote_get_default_shipping_address($nid) {
$address = db_query("SELECT first_name, last_name, company, street1, street2, city, zone, postal_code, country, phone FROM {uc_quote_product_locations} WHERE nid = :nid", array(':nid' => $nid))->fetchObject('UcAddress');
$address = db_query("SELECT first_name, last_name, company, street1, street2, city, zone, postal_code, country, phone FROM {uc_quote_product_locations} WHERE nid = :nid", array(':nid' => $nid))->fetchObject('UcAddressQuote');

if (empty($address)) {
$address = UcAddress::__set_state(config_get('uc_quote.settings', 'uc_quote_store_default_address'));
$address = UcAddressQuote::__set_state(config_get('uc_quote.settings', 'uc_quote_store_default_address'));
}

return $address;
Expand Down Expand Up @@ -1082,5 +1082,7 @@ function uc_quote_get_shipping_types() {
* Implements hook_autoload_info().
*/
function uc_quote_autoload_info() {
return array();
return array(
'UcAddressQuote' => 'address_quote.inc',
);
}
69 changes: 52 additions & 17 deletions uc_store/classes/address.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,86 @@
class UcAddress {

/**
* Given name. */
* Given name.
*
* @var string
*/
public $first_name = '';

/**
* Surname. */
* Surname.
*
* @var string
*/
public $last_name = '';

/**
* Company or organization. */
* Company or organization.
*
* @var string
*/
public $company = '';

/**
* First line of street address. */
* First line of street address.
*
* @var string
*/
public $street1 = '';

/**
* Second line of street address. */
* Second line of street address.
*
* @var string
*/
public $street2 = '';

/**
* City name. */
* City name.
*
* @var string
*/
public $city = '';

/**
* State, provence, or region id. */
* State, provence, or region id.
*
* @var int
*/
public $zone = 0;

/**
* ISO 3166-1 3-digit numeric country code. */
* ISO 3166-1 3-digit numeric country code.
*
* @var int
*/
public $country = 0;

/**
* Postal code. */
* Postal code.
*
* @var string
*/
public $postal_code = '';

/**
* Telephone number. */
* Telephone number.
*
* @var string
*/
public $phone = '';

/**
* Email address. */
* Email address.
*
* @var string
*/
public $email = '';

/**
* Constructor.
*
* @param $country
* @param int|null $country
* ISO 3166-1 3-digit numeric country code. Defaults to the value of the
* uc_store_country system variable if that variable is set, or 840
* (United States of America) if it is not set.
Expand All @@ -75,10 +108,10 @@ class UcAddress {
* in this comparison because they don't contain information about the
* physical location.
*
* @param $address
* @param UcAddress $address
* An object of type UcAddress.
*
* @return
* @return bool
* TRUE if the two addresses are the same physical location, else FALSE.
*/
public function isSamePhysicalLocation(UcAddress $address) {
Expand Down Expand Up @@ -110,10 +143,10 @@ class UcAddress {
* human would consider identical, but may be capitalized differently or
* have different whitespace.
*
* @param $string
* @param string $string
* String to make canonical.
*
* @return
* @return string
* Canonical form of input string.
*/
public static function makeCanonical($string = '') {
Expand All @@ -128,7 +161,7 @@ class UcAddress {
/**
* Formats the address for display based on the country's address format.
*
* @return
* @return string
* A formatted string containing the address.
*/
public function __toString() {
Expand Down Expand Up @@ -194,6 +227,8 @@ class UcAddress {
*
* @param array $data
* Data to import
*
* @return UcAddress
*/
public static function __set_state($data) {
$obj = new self;
Expand Down