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; }
function testSerialization() { $user = User::getNewInstance('*****@*****.**'); $user->firstName->set('Rinalds'); $user->lastName->set('Uzkalns'); $user->save(); $address = UserAddress::getNewInstance(); $address->city->set('Vilnius'); $address->save(); $billing = BillingAddress::getNewInstance($user, $address); $billing->save(); $user->defaultBillingAddress->set($billing); $serialized = serialize($user); $unser = unserialize($serialized); $this->assertEqual($user->firstName->get(), $unser->firstName->get()); $this->assertEqual($user->defaultBillingAddress->get()->userAddress->get()->city->get(), $unser->defaultBillingAddress->get()->userAddress->get()->city->get()); }
public function getNextUser() { if (!($data = $this->loadRecord('SELECT * FROM ' . $this->getTablePrefix() . 'customers'))) { return null; } $rec = User::getNewInstance($data['email']); foreach (array('firstName' => 'firstname', 'lastName' => 'lastname', 'companyName' => 'company', 'dateCreated' => 'first_login') as $lc => $xc) { $rec->{$lc}->set($data[$xc]); } $rec->isEnabled->set($data['status'] == 'Y'); if ($address = $this->getUserAddress($data, 's_')) { $rec->defaultShippingAddress->set(ShippingAddress::getNewInstance($rec, $address)); } if ($address = $this->getUserAddress($data, 'b_')) { $rec->defaultBillingAddress->set(BillingAddress::getNewInstance($rec, $address)); } return $rec; }
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); }
public function getNextBillingAddress() { if (!($data = $this->loadRecord('SELECT * FROM ' . $this->getTablePrefix() . 'address_book LEFT JOIN ' . $this->getTablePrefix() . 'countries ON ' . $this->getTablePrefix() . 'address_book.entry_country_id=' . $this->getTablePrefix() . 'countries.countries_id LEFT JOIN ' . $this->getTablePrefix() . 'customers ON ' . $this->getTablePrefix() . 'address_book.customers_id=' . $this->getTablePrefix() . 'customers.customers_id WHERE ' . $this->getTablePrefix() . 'customers.customers_id IS NOT NULL'))) { return null; } $address = $this->getUserAddress($data, 'entry_'); $address->countryID->set($data['countries_iso_code_2']); return BillingAddress::getNewInstance(User::getInstanceById($this->getRealId('User', $data['customers_id'])), $address); }
public function processCheckoutRegistration() { ActiveRecordModel::beginTransaction(); $validator = $this->buildValidator(); if (!$validator->isValid()) { $action = $this->request->get('regType') == 'register' ? 'registerAddress' : 'checkout'; return new ActionRedirectResponse('user', $action, array('query' => array('return' => $this->request->get('return')))); } // create user account $user = $this->createUser($this->request->get('password'), 'billing_'); // create billing and shipping address $address = $this->createAddress('billing_'); $billingAddress = BillingAddress::getNewInstance($user, $address); $billingAddress->save(); $shippingAddress = ShippingAddress::getNewInstance($user, $this->request->get('sameAsBilling') ? clone $address : $this->createAddress('shipping_')); $shippingAddress->save(); $user->defaultShippingAddress->set($shippingAddress); $user->defaultBillingAddress->set($billingAddress); $user->save(); // set order addresses $this->order->billingAddress->set($billingAddress->userAddress->get()); $this->order->loadItems(); if ($this->order->isShippingRequired()) { $this->order->shippingAddress->set($shippingAddress->userAddress->get()); } $this->order->save(); $this->order->setUser($user); SessionOrder::save($this->order); ActiveRecordModel::commit(); if ($return = $this->request->get('return')) { return new RedirectResponse($this->router->createUrlFromRoute($return)); } else { return new ActionRedirectResponse('checkout', 'shipping'); } }
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 getNextBillingAddress() { $addressTable = $this->getTablePrefix() . 'customer_addresses'; $userTable = $this->getTablePrefix() . 'customers'; if (!($data = $this->loadRecord('SELECT * FROM ' . $addressTable . ' LEFT JOIN ' . $userTable . ' ON ' . $userTable . '.addressID = ' . $addressTable . '.customerID WHERE ' . $userTable . '.customerID IS NOT NULL'))) { return null; } $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[$osc])) { $address->{$lc}->set($data[$osc]); } } $address->countryID->set($this->getCountryByID($data['countryID'])); $user = ActiveRecordModel::getInstanceByIDIfExists('User', $this->getRealId('User', $data['customerID']), false); if (!$user || !$user->isExistingRecord()) { return $this->getNextBillingAddress(); } $billing = BillingAddress::getNewInstance($user, $address); $billing->save(); // default address if ($data['Email']) { $user->defaultBillingAddress->set($billing); $user->save(); } return $billing; }
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); }