*
Get ids of zones, and store in session
public static cache_zone_ids ( Address $address ) | ||
$address | Address |
function testLocalRates() { $address_loc = $this->objFromFixture("Address", "wnz6022"); //New Zealand address Zone::cache_zone_ids($address_loc); //weight based $type = "weight"; $this->assertMatch($type, $this->p0, $address_loc, 4); //weight = 0kg $this->assertMatch($type, $this->p1, $address_loc, 4); //weight = 2.34kg $this->assertMatch($type, $this->p2, $address_loc, 48); //weight= 17kg, $this->assertMatch($type, $this->p3, $address_loc, 58); //weight = 100kg $this->assertNoMatch($type, $this->p4, $address_loc); //weight = 1000kg //volume based $type = "volume"; $this->assertMatch($type, $this->p0, $address_loc, 1); //volume = 0cm3 $this->assertMatch($type, $this->p1, $address_loc, 1); //volume = 1cm3 $this->assertMatch($type, $this->p2, $address_loc, 3); //volume = 6cm3 $this->assertMatch($type, $this->p3, $address_loc, 520); //volume = 18927.783cm3 $this->assertNoMatch($type, $this->p4, $address_loc); //volume = 2000000cm3 //value based $type = "value"; $this->assertMatch($type, $this->p0, $address_loc, 1); //value = $0 $this->assertMatch($type, $this->p1, $address_loc, 1); //value = $2 $this->assertMatch($type, $this->p2, $address_loc, 3); //value = $6 $this->assertNoMatch($type, $this->p3, $address_loc); //value = $1000 $this->assertNoMatch($type, $this->p4, $address_loc); //value = $1,000,000 //quantity based $type = "quantity"; $this->assertNoMatch($type, $this->p0, $address_loc); //quantity = 0 $this->assertMatch($type, $this->p1, $address_loc, 5.5); //quantity = 3 $this->assertMatch($type, $this->p2, $address_loc, 9.300000000000001); //quantity = 10 $this->assertNoMatch($type, $this->p3, $address_loc); //quantity = 155 $this->assertNoMatch($type, $this->p4, $address_loc); //quantity = 12412 }
public function setShippingAddress(Address $address) { $this->order->ShippingAddressID = $address->ID; if (Member::currentUserID()) { $this->order->MemberID = Member::currentUserID(); } $this->order->write(); $this->order->extend('onSetShippingAddress', $address); //update zones and userinfo ShopUserInfo::singleton()->setAddress($address); Zone::cache_zone_ids($address); }
/** * Create a new address if the existing address has changed, or is not yet * created. * * @param Order $order order to get addresses from * @param array $data data to set */ public function setData(Order $order, array $data) { $address = $this->getAddress($order); //if the value matches the current address then unset //this is to fix issues with blank fields & the readonly Country field $addressfields = Address::database_fields(get_class($address)); foreach ($data as $key => $value) { if (!isset($addressfields[$key]) || !$value && !$address->{$key}) { unset($data[$key]); } } $address->update($data); //if only one country is available, then set it if ($country = SiteConfig::current_site_config()->getSingleCountry()) { $address->Country = $country; } //write new address, or duplicate if changed if (!$address->isInDB()) { $address->write(); } elseif ($address->isChanged()) { $address = $address->duplicate(); } //set billing address, if not already set $order->{$this->addresstype . "AddressID"} = $address->ID; if (!$order->BillingAddressID) { $order->BillingAddressID = $address->ID; } $order->write(); //update user info based on shipping address if ($this->addresstype === "Shipping") { ShopUserInfo::singleton()->setAddress($address); Zone::cache_zone_ids($address); } //associate member to address if ($member = Member::currentUser()) { $default = $member->{"Default" . $this->addresstype . "Address"}(); //set default address if (!$default->exists()) { $member->{"Default" . $this->addresstype . "AddressID"} = $address->ID; $member->write(); } if ($this->addtoaddressbook) { $member->AddressBook()->add($address); } } //extension hooks $order->extend('onSet' . $this->addresstype . 'Address', $address); }
/** * Create a new address if the existing address has changed, or is not yet * created. * * @param Order $order order to get addresses from * @param array $data data to set */ public function setData(Order $order, array $data) { $address = $this->getAddress($order); $address->update($data); //if only one country is available, then set it if ($country = SiteConfig::current_site_config()->getSingleCountry()) { $address->Country = $country; } //write new address, or duplicate if changed if (!$address->isInDB()) { $address->write(); } elseif ($address->isChanged()) { $address = $address->duplicate(); } //set billing address, if not already set $order->{$this->addresstype . "AddressID"} = $address->ID; if (!$order->BillingAddressID) { $order->BillingAddressID = $address->ID; } $order->write(); //update user info based on shipping address if ($this->addresstype === "Shipping") { ShopUserInfo::singleton()->setAddress($address); Zone::cache_zone_ids($address); } //associate member to address if ($member = Member::currentUser()) { $default = $member->{"Default" . $this->addresstype . "Address"}(); //set default address if (!$default->exists()) { $member->{"Default" . $this->addresstype . "AddressID"} = $address->ID; $member->write(); } if ($this->addtoaddressbook) { $member->AddressBook()->add($address); } } //extension hooks $order->extend('onSet' . $this->addresstype . 'Address', $address); }
public function setData(Order $order, array $data) { if (!isset($data['Use'])) { parent::setData($order, $data); return; } $member = Member::currentUser() ?: $order->Member(); if (strpos($data['Use'], 'address-') === 0) { $address = Address::get()->byID(substr($data['Use'], 8)); if (!$address) { throw new ValidationException('That address does not exist'); } if (isset($data[$data['Use']]) && isset($data[$data['Use']]['saveAsNew']) && $data[$data['Use']]['saveAsNew']) { if (!$address->canCreate()) { throw new ValidationException('You do not have permission to add a new address'); } $address = $address->duplicate(); } else { if (isset($data[$data['Use']]) && !$address->canEdit() && $address->MemberID != $member->ID) { throw new ValidationException('You do not have permission to use this address'); } } } else { if (!singleton('Address')->canCreate()) { throw new ValidationException('You do not have permission to add a new address'); } $address = Address::create(); } if (isset($data[$data['Use']])) { $address->castedUpdate($data[$data['Use']]); // FIX for missing name fields $fields = array_intersect_key($data, array_flip(['FirstName', 'Surname', 'Name', 'Email'])); foreach ($fields as $field => $value) { if (!$address->{$field}) { $address->{$field} = $value; } } if ($country = ShopConfig::current()->SingleCountry) { $address->Country = $country; } if ($this->addtoaddressbook) { $address->MemberID = $member->ID; } $address->write(); if (isset($data[$data['Use']]['useAsDefaultShipping']) && $data[$data['Use']]['useAsDefaultShipping']) { $member->DefaultShippingAddressID = $address->ID; } if (isset($data[$data['Use']]['useAsDefaultBilling']) && $data[$data['Use']]['useAsDefaultBilling']) { $member->DefaultBillingAddressID = $address->ID; } if ($member->isChanged()) { $member->write(); } } if ($address->exists()) { if ($this->addresstype === 'Shipping') { ShopUserInfo::singleton()->setAddress($address); Zone::cache_zone_ids($address); } $order->{$this->addresstype . 'AddressID'} = $address->ID; if (!$order->BillingAddressID) { $order->BillingAddressID = $address->ID; } $order->write(); $order->extend('onSet' . $this->addresstype . 'Address', $address); } }