public function contentcontrollerInit() { $location = ShopUserInfo::singleton()->getAddress(); if (!$location || Controller::curr()->getRequest()->getVar('relocateuser')) { ShopUserInfo::singleton()->setAddress(new Address($this->findLocation())); } }
public function contentcontrollerInit() { $location = ShopUserInfo::singleton()->getAddress(); $autocode = Page::config()->geocode_visitor_ip; if (!$location && $autocode || Controller::curr()->getRequest()->getVar('relocateuser')) { ShopUserInfo::singleton()->setAddress(new Address($this->findLocation())); } }
public function testSetLocation() { ShopUserInfo::singleton()->setLocation(array('Country' => 'NZ', 'State' => 'Wellington', 'City' => 'Newton')); $location = ShopUserInfo::singleton()->getAddress(); $this->assertEquals($location->Country, 'NZ'); $this->assertEquals($location->State, 'Wellington'); $this->assertEquals($location->City, 'Newton'); }
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); } }
public function setLocation($data, $form) { ShopUserInfo::singleton()->setLocation($data); $this->controller->redirectBack(); }