public function setUp() { parent::setUp(); ActiveRecord::clearPool(); ActiveRecord::executeUpdate('DELETE FROM Tax'); ActiveRecord::executeUpdate('DELETE FROM TaxRate'); ActiveRecord::executeUpdate('DELETE FROM DeliveryZone'); ActiveRecord::executeUpdate('DELETE FROM Currency'); ActiveRecord::executeUpdate('DELETE FROM ShippingService'); ActiveRecord::executeUpdate('DELETE FROM DeliveryZone'); ActiveRecord::executeUpdate('DELETE FROM TaxClass'); $this->deliveryZone = DeliveryZone::getNewInstance(); $this->deliveryZone->setValueByLang('name', 'en', 'test zone'); $this->deliveryZone->isEnabled->set(true); $this->deliveryZone->save(); DeliveryZoneCountry::getNewInstance($this->deliveryZone, 'US')->save(); $this->tax = Tax::getNewInstance('test type'); $this->tax->save(); $this->currency = ActiveRecord::getInstanceByIdIfExists('Currency', 'USD'); $this->currency->isEnabled->set(true); $this->currency->decimalCount->set(2); $this->currency->save(); $this->product = Product::getNewInstance(Category::getRootNode()); $this->product->setPrice('USD', 100); $this->product->isEnabled->set(true); $this->product->save(); $this->user = User::getNewInstance('*****@*****.**'); $this->user->save(); $this->address = UserAddress::getNewInstance(); $this->address->countryID->set('US'); $this->address->save(); $this->getApplication()->getConfig()->setRuntime('DELIVERY_TAX_CLASS', null); }
protected function initOrder() { // set up currency $this->setUpCurrency(); $this->usd->decimalCount->set(2); $this->usd->clearRoundingRules(); $this->usd->save(); // initialize order ActiveRecordModel::executeUpdate('DELETE FROM User WHERE email="*****@*****.**"'); $user = User::getNewInstance('*****@*****.**'); $user->save(); $this->user = $user; $address = UserAddress::getNewInstance(); $address->countryID->set('US'); $state = State::getInstanceById(1, State::LOAD_DATA); $address->state->set(State::getInstanceById(1)); $address->postalCode->set(90210); $address->save(); $billing = BillingAddress::getNewInstance($user, $address); $billing->save(); $address = clone $address; $address->save(); $shipping = ShippingAddress::getNewInstance($user, $address); $shipping->save(); $this->order = CustomerOrder::getNewInstance($user); $this->order->shippingAddress->set($shipping->userAddress->get()); $this->order->billingAddress->set($billing->userAddress->get()); // set up products $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test1'); $product->save(); $product->setPrice('USD', 100); $product->stockCount->set(20); $product->isEnabled->set(1); $product->save(); $this->products[] = $product; $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test2'); $product->save(); $product->setPrice('USD', 200); $product->stockCount->set(20); $product->isEnabled->set(1); $product->save(); $this->products[] = $product; $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test3'); $product->save(); $product->setPrice('USD', 400); $product->isSeparateShipment->set(true); $product->stockCount->set(20); $product->isEnabled->set(1); $product->save(); $this->products[] = $product; }
protected function getInstance($record, CsvImportProfile $profile) { pp('User address import get instance'); $fields = $profile->getSortedFields(); if (isset($fields['UserAddress']['ID'])) { $instance = ActiveRecordModel::getInstanceByID('UserAddress', $record[$fields['UserAddress']['ID']], true); } else { if (isset($fields['AddressUser']['ID'])) { $owner = User::getInstanceByID($record[$fields['AddressUser']['ID']], true); } else { if (isset($fields['AddressUser']['email'])) { $owner = User::getInstanceByEmail($record[$fields['AddressUser']['email']]); } } } if (isset($owner)) { if ($profile->isColumnSet('AddressUser.isShipping')) { $type = $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isShipping')])) ? 'ShippingAddress' : 'BillingAddress'; } else { $type = 'BillingAddress'; } $owner->loadAddresses(); } if (empty($instance)) { if (empty($owner)) { return; } $isDefault = $profile->isColumnSet('AddressUser.isDefault') && $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isDefault')])); if ($isDefault) { $field = 'default' . $type; $addressType = $owner->{$field}->get(); $instance = $addressType->userAddress->get(); } if (empty($addressType)) { $instance = UserAddress::getNewInstance(); $addressType = call_user_func_array(array($type, 'getNewInstance'), array($owner, $instance)); if ($isDefault) { $owner->{$field}->set($addressType); } } $addressType->userAddress->set($instance); $instance->addressType = $addressType; } return $instance; }
function testCloning() { $user = User::getNewInstance('*****@*****.**'); $user->firstName->set('Rinalds'); $user->lastName->set('Uzkalns'); $user->save(); $state = ActiveRecordModel::getInstanceByID('State', 2, ActiveRecordModel::LOAD_DATA); $address = UserAddress::getNewInstance(); $address->city->set('Vilnius'); $address->state->set($state); $address->save(); $newAddress = clone $address; // simple value $this->assertEqual($address->city->get(), $newAddress->city->get()); // foreign key $this->assertEqual($address->state->get(), $newAddress->state->get()); $newAddress->save(); // primary key (autoincrement) $this->assertNotEquals($address->getID(), $newAddress->getID()); }
public function filter() { $request = $this->application->getRequest(); $ID = $request->get('ID'); if (intval($ID) > 0 && isset($ID)) { $order = CustomerOrder::getInstanceById($ID); $order->loadAll(); $order->getTotal(true); $order->totalAmount->set($order->getTotal(true)); $order->getTaxAmount(); $user = $order->user->get(); $user->load(); $user->loadAddresses(); $shipping = $user->defaultShippingAddressID->get(); $billing = $user->defaultBillingAddressID->get(); if (!isset($shipping)) { $user_shipping_address = UserAddress::getNewInstance(); $user_shipping_address->firstName->set($user->firstName->get()); $user_shipping_address->lastName->set($user->lastName->get()); $user_shipping_address->companyName->set($user->companyName->get()); $user_shipping_address->save(); $shipping_address = ShippingAddress::getNewInstance($user, $user_shipping_address); $shipping_address->save(); } if (!isset($billing)) { $user_billing_address = UserAddress::getNewInstance(); $user_billing_address->firstName->set($user->firstName->get()); $user_billing_address->lastName->set($user->lastName->get()); $user_billing_address->companyName->set($user->companyName->get()); $user_billing_address->save(); $billing_address = BillingAddress::getNewInstance($user, $user_billing_address); $billing_address->save(); } $shippingAddressID = $order->shippingAddressID->get(); $billingAddressID = $order->billingAddressID->get(); if (!isset($shippingAddressID)) { $_shipping = $user->defaultShippingAddressID->get(); $_shipping->load(); $ua1 = $_shipping->userAddress->get(); $ua1->load(); $order->shippingAddressID->set($ua1); } if (!isset($billingAddressID)) { $_billing = $user->defaultBillingAddressID->get(); $_billing->load(); $ua2 = $_billing->userAddress->get(); $ua2->load(); $order->billingAddressID->set($ua2); } foreach ($order->getShipments() as $shipment) { if (!$shipment->getSelectedRate()) { $shipment->shippingAmount->set(0); } } foreach ($order->getShipments() as $shipment) { $shipment->setAvailableRates(null); $shipment->shippingAddress->set($order->shippingAddress->get()); } $order->serializeShipments(); $order->save(true); } return $this->apiActionGetOrdersBySelectFilter($this->getParser()->getARSelectFilter(), true); }
private function getUserAddress($data, $prefix) { $address = UserAddress::getNewInstance(); $map = array('company' => 'companyName', 'street_address' => 'address1', 'city' => 'city', 'postcode' => 'postalCode', 'state' => 'stateName', 'firstname' => 'firstName', 'lastname' => 'lastName'); foreach ($map as $osc => $lc) { if (isset($data[$prefix . $osc])) { $address->{$lc}->set($data[$prefix . $osc]); } } if (!empty($data[$prefix . 'name'])) { $names = explode(' ', $data[$prefix . 'name'], 2); $address->firstName->set(array_shift($names)); $address->lastName->set(array_shift($names)); } if (isset($data['customers_telephone'])) { $address->phone->set($data['customers_telephone']); } if (isset($data[$prefix . 'country'])) { $country = array_search($data[$prefix . 'country'], Locale::getInstance('en')->info()->getAllCountries()); if (!$country) { $country = 'US'; } $address->countryID->set($country); } return $address; }
/** * @return Form */ public function createUserAddressForm($addressArray = array(), ActionResponse $response) { $form = new Form($this->createUserAddressFormValidator()); if (!empty($addressArray)) { if (isset($addressArray['State']['ID'])) { $addressArray['stateID'] = $addressArray['State']['ID']; } $form->setData($addressArray); } $address = !empty($addressArray['ID']) ? ActiveRecordModel::getInstanceByID('UserAddress', $addressArray['ID'], true) : UserAddress::getNewInstance(); $address->getSpecification()->setFormResponse($response, $form); return $form; }
public function validateAddress(RequestValidator $validator, $fieldPrefix = '', $orCheck = false) { $this->validateName($validator, $fieldPrefix, $orCheck); $fields = $checks = array(); $displayedFields = $this->config->get('USER_FIELDS'); if ($this->config->get('REQUIRE_PHONE') && !empty($displayedFields['PHONE'])) { $fields[] = $fieldPrefix . 'phone'; $checks[] = new IsNotEmptyCheck($this->translate('_err_enter_phone')); } if (!empty($displayedFields['ADDRESS1'])) { $fields[] = $fieldPrefix . 'address1'; $checks[] = new IsNotEmptyCheck($this->translate('_err_enter_address')); } if (!empty($displayedFields['CITY'])) { $fields[] = $fieldPrefix . 'city'; $checks[] = new IsNotEmptyCheck($this->translate('_err_enter_city')); } if (!empty($displayedFields['COUNTRY'])) { $fields[] = $fieldPrefix . 'country'; $checks[] = new IsNotEmptyCheck($this->translate('_err_select_country')); } if (!empty($displayedFields['POSTALCODE'])) { $fields[] = $fieldPrefix . 'postalCode'; $checks[] = new IsNotEmptyCheck($this->translate('_err_enter_zip')); } // custom field validation $tempVal = $this->getValidator('tempVal', $this->request); UserAddress::getNewInstance()->getSpecification()->setValidation($tempVal, null, $fieldPrefix); foreach ($tempVal->getValidatorVars() as $var) { foreach ($var->getChecks() as $check) { $fields[] = $var->getName(); $checks[] = $check; } foreach ($var->getFilters() as $filter) { $validator->addFilter($var->getName(), $filter); } } foreach ($fields as $key => $field) { $check = $orCheck ? new OrCheck(array($field, 'sameAsBilling'), array($checks[$key], new IsNotEmptyCheck('')), $this->request) : $checks[$key]; $validator->addCheck($field, $check); } if (!empty($displayedFields['STATE'])) { $fieldList = array($fieldPrefix . 'state_select', $fieldPrefix . 'state_text'); $checkList = array(new IsNotEmptyCheck($this->translate('_err_select_state')), new IsNotEmptyCheck('')); if ($orCheck) { $fieldList[] = 'sameAsBilling'; $checkList[] = new IsNotEmptyCheck(''); } $stateCheck = new OrCheck($fieldList, $checkList, $this->request); $validator->addCheck($fieldPrefix . 'state_select', $stateCheck); } }
private function getUserAddress($data, $prefix) { $address = UserAddress::getNewInstance(); $map = array('company' => 'companyName', 'address' => 'address1', 'city' => 'city', 'zipcode' => 'postalCode', 'state' => 'stateName', 'firstname' => 'firstName', 'lastname' => 'lastName', 'country' => 'countryID'); $isData = false; foreach ($map as $osc => $lc) { if (isset($data[$prefix . $osc])) { $address->{$lc}->set($data[$prefix . $osc]); $isData = true; } } if (!$isData) { return null; } if (!empty($data['phone'])) { $address->phone->set($data['phone']); } return $address; }
private function importAddress($instance, $record, CsvImportProfile $profile, $type) { $address = $instance->{$type}->get(); if (!$address) { $address = UserAddress::getNewInstance(); } else { $address->load(); } $profile->renameType(ucfirst($type), 'UserAddress'); $id = $this->importRelatedRecord('UserAddress', $address, $record, $profile); $address = ActiveRecordModel::getInstanceByID('UserAddress', $id, true); $address->save(); $instance->{$type}->set($address); // if billing or shipping address is not provided, use the same address $otherType = 'billingAddress' == $type ? 'shippingAddress' : 'billingAddress'; if (!$instance->{$otherType}->get()) { $clone = clone $address; $clone->save(); $instance->{$otherType}->set($clone); } $instance->save(); }
private function createAddress($addressClass, $prefix) { $address = UserAddress::getNewInstance(); $this->saveAddress($address, $prefix); $addressType = call_user_func_array(array($addressClass, 'getNewInstance'), array($this->user, $address)); if (!$this->user->isAnonymous()) { $addressType->save(); } return $addressType; }
private function importAddress($instance, $record, CsvImportProfile $profile, $type) { $field = 'default' . $type; $instance->loadAddresses(); if (!$instance->{$field}->get()) { $address = UserAddress::getNewInstance(); $address->firstName->setAsModified(); $address->save(); $shippingAddress = call_user_func(array($type, 'getNewInstance'), $instance, $address); $shippingAddress->save(); } else { $address = $instance->{$field}->get()->userAddress->get(); } $id = $this->importRelatedRecord('UserAddress', $address, $record, $profile); $related = ActiveRecordModel::getInstanceByID('UserAddress', $id, true); foreach (array('firstName', 'lastName', 'companyName') as $field) { if (!$related->{$field}->get() && $instance->{$field}->get()) { $related->{$field}->set($instance->{$field}->get()); } } $related->save(); }
private function createOrderWithZone(DeliveryZone $zone = null) { if (is_null($zone)) { $zone = DeliveryZone::getNewInstance(); } $zone->name->set('Latvia'); $zone->isEnabled->set(true); $zone->save(); $this->newZone = $zone; $country = DeliveryZoneCountry::getNewInstance($zone, 'LV'); $country->save(); $tax = Tax::getNewInstance('VAT'); $tax->save(); $taxRate = TaxRate::getNewInstance($zone, $tax, 20); $taxRate->save(); $service = ShippingService::getNewInstance($zone, 'def', ShippingService::SUBTOTAL_BASED); $service->save(); $this->newService = $service; $shippingRate = ShippingRate::getNewInstance($service, 0, 10000000); $shippingRate->flatCharge->set(100); $shippingRate->save(); $this->newRate = $shippingRate; // user address $address = UserAddress::getNewInstance(); $address->countryID->set('LV'); $billingAddress = BillingAddress::getNewInstance($this->user, $address); $billingAddress->save(); // set up order $this->order->user->set($this->user); $this->order->billingAddress->set($address); $this->order->shippingAddress->set($address); $this->order->save(); }
public function testFindZoneWithMasks() { $zone1 = DeliveryZone::getNewInstance(); $zone1->name->set('With ZIP'); $zone1->isEnabled->set(true); $zone1->save(); DeliveryZoneZipMask::getNewInstance($zone1, 'asd')->save(); DeliveryZoneCountry::getNewInstance($zone1, 'LT')->save(); $zone2 = DeliveryZone::getNewInstance(); $zone2->name->set('Without ZIP'); $zone2->isEnabled->set(true); $zone2->save(); DeliveryZoneCountry::getNewInstance($zone2, 'LT')->save(); $address = UserAddress::getNewInstance(); $address->countryID->set('LT'); $this->assertSame(DeliveryZone::getZoneByAddress($address), $zone2); $address->postalCode->set('asd'); $this->assertSame(DeliveryZone::getZoneByAddress($address), $zone1); }
private function getUserAddress($data, $prefix) { $address = UserAddress::getNewInstance(); $map = array('address' => 'address1', 'city' => 'city', 'zip' => 'postalCode', 'state' => 'stateName', 'first_name' => 'firstName', 'last_name' => 'lastName'); foreach ($map as $osc => $lc) { if (isset($data[$prefix . $osc])) { $address->{$lc}->set($data[$prefix . $osc]); } } $address->countryID->set($this->getCountryByName($data[$prefix . 'country'])); return $address; }
private function saveAddresses(User $user = null) { $user->loadAddresses(); foreach (array('defaultBillingAddress' => 'billingAddress', 'defaultShippingAddress' => 'shippingAddress') as $field => $prefix) { $address = $user->{$field}->get() ? $user->{$field}->get()->userAddress->get() : UserAddress::getNewInstance(); $address->loadRequestData($this->request, $prefix . '_'); // get address state if ($stateID = $this->request->get($prefix . '_stateID')) { $address->state->set(ActiveRecordModel::getInstanceByID('State', $stateID, ActiveRecordModel::LOAD_DATA)); $address->stateName->setNull(); } else { $address->stateName->set($this->request->get($prefix . '_stateName')); $address->state->setNull(); } $modified = false; foreach (ActiveRecordModel::getSchemaInstance('UserAddress')->getFieldList() as $f) { if ($address->getFieldValue($f->getName())) { $modified = true; } } if ($modified) { $address->save(); if (!$user->{$field}->get()) { $addressType = call_user_func_array(array($prefix, 'getNewInstance'), array($user, $address)); $addressType->save(); } } } if ($this->request->get('sameAddresses') && $user->defaultBillingAddress->get()) { $shippingAddress = ShippingAddress::getNewInstance($user, clone $user->defaultBillingAddress->get()->userAddress->get()); $shippingAddress->save(); } }
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; }
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 do_login() { $request = $this->application->getRequest(); $email = $request->get('email'); $password = $request->get('password'); $user = User::getInstanceByLogin($email, $password); if (!$user) { throw new Exception('User error login for email: ' . $email . ', password: '******'User', select(eq(f('User.ID'), $user->getID()))); $apiFieldNames = $parser->getApiFieldNames(); $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . " users" . count($users_record) . '"></response>'); $responseCustomer = $response->addChild('customer'); $_user = array_shift($users_record); unset($_user['password']); foreach ($_user as $k => $v) { if (in_array($k, $apiFieldNames)) { $responseCustomer->addChild($k, $v); } } return new SimpleXMLResponse($response); }
public function saveAddress() { $this->loadLanguageFile('backend/Shipment'); ClassLoader::import('application.controller.backend.CustomerOrderController'); $shipment = Shipment::getInstanceByID('Shipment', $this->request->get('id'), true, array('CustomerOrder', 'User')); $address = $shipment->shippingAddress->get(); if (!$address) { $address = UserAddress::getNewInstance(); $address->save(); $shipment->shippingAddress->set($address); $shipment->save(); } else { $address->load(); } $controller = new CustomerOrderController($this->application); $validator = $controller->createUserAddressFormValidator(); if ($validator->isValid()) { $address->loadRequestData($this->request); $address->save(); return new JSONResponse($shipment->shippingAddress->get()->toArray(), 'success', $this->translate('_shipment_address_changed')); } else { return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure'); } }
public function testAddress() { $address = UserAddress::getNewInstance(); $address->loadRequestData($this->request); $zone = DeliveryZone::getZoneByAddress($address, $this->request->get('type')); return new JSONResponse($zone->toArray()); }