public function testShouldNotCreateBlankAddresses() { $beforeCount = Address::get()->count(); $this->config->setData(array('BillingAddressBookCheckoutComponent_BillingAddressID' => $this->address1->ID)); $this->assertEquals($this->cart->BillingAddressID, $this->address1->ID); $this->assertEquals($beforeCount, Address::get()->count()); }
public function onAfterWrite() { parent::onAfterWrite(); //Make sure there is only one default address if ($this->Default == true) { $addrs = Address::get()->where("\"ClassName\" = '" . get_class($this) . "' AND \"MemberID\" = '{$this->MemberID}' AND \"Default\" = 1 AND \"ID\" != {$this->ID}"); if ($addrs && $addrs->exists()) { foreach ($addrs as $addr) { $addr->Default = 0; $addr->write(); } } } }
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); } }
public function testAddressBookWithReadonlyFieldForCountry() { $member = $this->objFromFixture("Member", "joebloggs"); $this->logInAs($member); $this->controller->init(); //reinit to connect up member // setup a single-country site $siteconfig = DataObject::get_one('SiteConfig'); $siteconfig->AllowedCountries = "NZ"; $siteconfig->write(); $singlecountry = SiteConfig::current_site_config(); $this->assertEquals("NZ", $singlecountry->getSingleCountry(), "Confirm that the website is setup as a single country site"); // Open the Address Book page to test form submission with a readonly field $page = $this->get("account/addressbook/"); // goto address book page $this->assertEquals(200, $page->getStatusCode(), "a page should load"); $this->assertContains("Form_CreateAddressForm_Country_readonly", $page->getBody(), "The Country field is readonly"); $this->assertNotContains("<option value=\"NZ\">New Zealand</option>", $page->getBody(), "Dropdown field is not shown"); // Create an address $data = array("Address" => "234 Hereford Street", "City" => "Christchurch", "State" => "Canterbury", "PostalCode" => "8011"); $this->submitForm("Form_CreateAddressForm", "action_saveaddress", $data); $this->assertEquals(200, $page->getStatusCode(), "a page should load"); $nz_address = Address::get()->filter('PostalCode', '8011')->sort('ID')->last(); $this->assertEquals("NZ", $nz_address->Country, "New address successfully saved; even with a Country readonly field in the form"); $this->assertEquals("234 Hereford Street", $nz_address->Address, "Ensure that the Address is 234 Hereford Street"); }
<?php /* * Created at 8/10/2015 * Page to add and display the addresses * */ require_once 'includes/header.php'; require_once 'classess/class.address.php'; /** *code to display all address from table */ $address = new Address(); $a_addresses = $address->get(); ?> <div class="col-md-12 no-padding"> <div class="col-md-12 sub-container"> <div class="row"> <div class="row margine-top"> <button type="button" class="btn btn-primary margine-bottom float-right" data-toggle="modal" data-target="#addForm"> Add Address </button> <div class="col-md-12"> <div class="alert alert-success alert-dismissable hide" aria-hidden="true" id="address_success_alert"></div> </div> <input type="hidden" name="site_url" id="site_url" value="<?php echo SITE_URL; ?> "> <table class="table table_bordered" id="table_info"> <thead>
/** * Calculate the broadcast address of a Block given an IPV4 network address and SubnetMask. * * @param \JAAulde\IP\V4\Address $address The IP address from which a broadcast address will be derived * @param \JAAulde\IP\V4\SubnetMask $subnetMask The subnet mask (in address form) used in the derivation * * @return \JAAulde\IP\V4\Address */ public static function calculateBroadcastAddress(Address $address, SubnetMask $subnetMask) { return new Address($address->get() | ~$subnetMask->get()); }
/** * Determine if a given address is contained within the range. * * @param \JAAulde\IP\V4\Address $address The address we want to know about * * @return bool */ public function contains(Address $address) { $addressValue = $address->get(); return $addressValue >= $this->firstAddress->get() && $addressValue <= $this->lastAddress->get(); }
public function testOrderAddress() { $order = $this->objFromFixture('Order', 'paid'); // assert that order doesn't contain user information $this->assertNull($order->FirstName); $this->assertNull($order->Surname); $this->assertNull($order->Email); // The shipping address should use the members default shipping address $this->assertEquals('Joe Bloggs, 12 Foo Street, Bar, Farmville, New Sandwich, US', $order->getShippingAddress()->toString()); $address = $this->objFromFixture('Address', 'pukekohe'); $order->ShippingAddressID = $address->ID; $order->write(); // Address doesn't have firstname and surname $this->assertNull(Address::get()->byID($order->ShippingAddressID)->FirstName); $this->assertNull(Address::get()->byID($order->ShippingAddressID)->Surname); // Shipping address should contain the name from the member object and new address information $this->assertEquals('Joe Bloggs, 1 Queen Street, Pukekohe, Auckland, 2120', $order->getShippingAddress()->toString()); // changing fields on the Order will have precendence! $order->FirstName = 'Tester'; $order->Surname = 'Mc. Testerson'; $order->write(); // Reset caches, otherwise the previously set name will persist (eg. Joe Bloggs) DataObject::reset(); $this->assertEquals('Tester Mc. Testerson, 1 Queen Street, Pukekohe, Auckland, 2120', $order->getShippingAddress()->toString()); }
/** * Given two (2) IP (V4) addresses, calculate a CIDR prefix for the network which could contain them both. * * @param \JAAulde\IP\V4\Address $address1 * @param \JAAulde\IP\V4\Address $address2 */ public static function calculateCIDRToFit(Address $address1, Address $address2) { return (int) floor(32 - log(($address1->get() ^ $address2->get()) + 1, 2)); }
public function testAddress() { //$address = new Address('63 Point West Circle', NULL, 'Little Rock', 'AR', '72211', NULL); $address = new Address('911 BROKHAVEN DR', NULL, 'RUSSELLVILLE', 'KY', '42276', NULL); $this->assertEquals('KY', $address->get('state')); }