public function setUp() { parent::setUp(); $this->zone = DeliveryZone::getNewInstance(); $this->zone->name->set(':TEST_ZONE'); $this->zone->isEnabled->set(1); $this->zone->isFreeShipping->set(1); $this->zone->save(); $this->alaska = State::getInstanceByID(1, true, true); }
public static function getDefaultEstimateAddress() { $config = ActiveRecordModel::getApplication()->getConfig(); $address = UserAddress::getNewInstance(); $address->countryID->set($config->get('DEF_COUNTRY')); if ($state = $config->get('DEF_STATE')) { $address->state->set(State::getInstanceByID($config->get('DEF_STATE'))); } return $address; }
public function unserialize($serialized) { parent::unserialize($serialized); if ($this->serializedState) { $this->state->set(State::getInstanceByID($this->serializedState, true)); } }
/** * @role update */ public function saveStates() { $zone = DeliveryZone::getInstanceByID((int) $this->getId()); DeliveryZoneState::removeByZone($zone); foreach ((array) $this->request->get('active') as $activeStateID) { $state = State::getInstanceByID((int) $activeStateID); $deliveryZoneState = DeliveryZoneState::getNewInstance($zone, $state); $deliveryZoneState->save(); } return new JSONResponse(false, 'success'); }
public function update() { $request = $this->application->getRequest(); $parser = $this->getParser(); $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); $id = $request->get('ID'); $f = new ARSelectFilter(); if (intval($id) > 0) { $f->mergeCondition(new EqualsCond(new ARFieldHandle('UserAddress', 'ID'), $id)); } else { throw new Exception('Address ID is required'); } $user_address = UserAddress::getInstanceById($id); $firstName = $request->get('firstName'); $lastName = $request->get('lastName'); $companyName = $request->get('companyName'); $address1 = $request->get('address1'); $address2 = $request->get('address2'); $city = $request->get('city'); $stateName = $request->get('stateName'); $stateID = $request->get('stateID'); $postalCode = $request->get('postalCode'); $countryID = $request->get('countryID'); $phone = $request->get('phone'); if (isset($firstName)) { $user_address->setFieldValue('firstName', $firstName); } if (isset($lastName)) { $user_address->setFieldValue('lastName', $lastName); } if (isset($companyName)) { $user_address->setFieldValue('companyName', $companyName); } if (isset($address1)) { $user_address->setFieldValue('address1', $address1); } if (isset($address2)) { $user_address->setFieldValue('address2', $address2); } if (isset($city)) { $user_address->setFieldValue('city', $city); } if (isset($stateName)) { $user_address->setFieldValue('stateName', $stateName); } if (isset($stateID)) { $user_address->state->set(State::getInstanceByID((int) $stateID, true)); } if (isset($postalCode)) { $user_address->setFieldValue('postalCode', $postalCode); } if (isset($countryID)) { $user_address->setFieldValue('countryID', $countryID); } if (isset($phone)) { $user_address->setFieldValue('phone', $phone); } $user_address->save(); $apiFieldNames = $parser->getApiFieldNames(); $user_record = ActiveRecordModel::getRecordSetArray('UserAddress', $f); while ($address = array_shift($user_record)) { $user_address_response = $response->addChild('user_address'); foreach ($address as $k => $v) { if (in_array($k, $apiFieldNames)) { $user_address_response->addChild($k, htmlentities($v)); } } } return new SimpleXMLResponse($response); }
public function testGetDeliveryZoneStates() { $zone = DeliveryZone::getNewInstance(); $zone->name->set(':TEST_ZONE'); $zone->save(); $deliveryState = DeliveryZoneState::getNewInstance($zone, State::getInstanceByID(1)); $deliveryState->save(); $states = $zone->getStates(); $this->assertEquals($states->getTotalRecordCount(), 1); $this->assertTrue($states->get(0) === $deliveryState); }
public function loadRequestData(Request $request, $prefix = '') { parent::loadRequestData($request, $prefix); if ($request->get($prefix . 'stateID')) { $this->state->set(State::getInstanceByID((int) $request->get($prefix . 'stateID'), true)); $this->stateName->set(null); } else { if ($request->isValueSet($prefix . 'stateName')) { $this->stateName->set($request->get($prefix . 'stateName')); $this->state->set(null); } } }
private function getAddresses($array) { $addresses = array(); foreach ($array['CALCULATE'][0]['ADDRESSES'][0]['ANONYMOUS-ADDRESS'] as $address) { $ua = UserAddress::getNewInstance(); foreach (array('COUNTRY-CODE' => 'countryID', 'POSTAL-CODE' => 'postalCode', 'CITY' => 'city', 'REGION' => 'stateName') as $google => $livecart) { $ua->{$livecart}->set($address[$google][0]['VALUE']); } // state lookup if ($stateID = State::getStateIDByName($ua->countryID->get(), $ua->stateName->get())) { $ua->state->set(State::getInstanceByID($stateID, true)); } $ua->countryID->set($address['COUNTRY-CODE'][0]['VALUE']); $addresses[$address['ATTRIBUTES']['ID']] = $ua; } return $addresses; }