Пример #1
0
 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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 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();
     }
 }
Пример #4
0
 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);
 }
Пример #5
0
 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');
     }
 }
Пример #6
0
 private function separateBillingAndShippingAddresses()
 {
     if (!$this->request->get('sameAsShipping') && $this->order->shippingAddress->get() && $this->order->billingAddress->get() && $this->order->shippingAddress->get()->getID() == $this->order->billingAddress->get()->getID() && !$this->user->defaultShippingAddress->get()) {
         $this->user->defaultShippingAddress->set(ShippingAddress::getNewInstance($this->user, clone $this->order->shippingAddress->get()));
         $this->user->defaultShippingAddress->get()->save();
     }
 }
Пример #7
0
 public function doSelectShippingAddress()
 {
     $sameAddress = $this->config->get('REQUIRE_SAME_ADDRESS');
     $this->config->setRuntime('REQUIRE_SAME_ADDRESS', false);
     $this->order->loadAll();
     $this->request->set('step', 'shipping');
     $this->initAnonUser();
     if ($this->user->isAnonymous()) {
         try {
             $billing = $this->user->defaultBillingAddress->get();
             if ($err = $this->setAddress('shipping')) {
                 return $err;
             }
         } catch (Exception $e) {
             $this->user->defaultBillingAddress->set($billing);
             $this->user->defaultShippingAddress->set($this->lastAddress);
             if ($this->user->defaultShippingAddress->get()) {
                 $this->order->shippingAddress->set($this->user->defaultShippingAddress->get()->userAddress->get());
             }
             if ($this->order->shippingAddress->get() && $this->order->shippingAddress->get()->getID() == $this->order->billingAddress->get()->getID()) {
                 $shipping = clone $this->user->defaultBillingAddress->get()->userAddress->get();
                 if (!$this->user->defaultShippingAddress->get()) {
                     $this->user->defaultShippingAddress->set(ShippingAddress::getNewInstance($this->user, $shipping));
                 }
                 $this->user->defaultShippingAddress->get()->userAddress->set($shipping);
             }
             $this->saveAnonUser($this->user);
             $this->order->shippingAddress->resetModifiedStatus();
             SessionOrder::save($this->order);
         }
     } else {
         if ($err = $this->setAddress('shipping')) {
             return $err;
         }
         // UserAddress::toString() uses old data otherwise
         if ($this->order->shippingAddress->get()) {
             $this->order->shippingAddress->get()->resetArrayData();
             if ($sameAddress) {
                 $this->order->billingAddress->set($this->order->shippingAddress->get());
                 $this->order->save();
             } else {
                 if ($this->request->get('sameAsShipping') && (!$this->order->billingAddress->get() && $this->order->shippingAddress->get() && $this->order->isShippingRequired() || $this->order->billingAddress->get() && $this->order->shippingAddress->get() && $this->order->billingAddress->get()->toString() != $this->order->shippingAddress->get()->toString())) {
                     $this->order->billingAddress->set(clone $this->order->shippingAddress->get());
                     $this->order->billingAddress->get()->save();
                     $this->order->save();
                 }
             }
         }
     }
     // attempt to pre-select a shipping method
     ActiveRecord::clearPool();
     $this->config->resetRuntime('DELIVERY_TAX_CLASS');
     $this->order = CustomerOrder::getInstanceById($this->order->getID(), true);
     if (isset($anonOrder)) {
         $this->order->shippingAddress->set($anonOrder->shippingAddress->get());
         $this->order->billingAddress->set($anonOrder->billingAddress->get());
     }
     // @todo: needs to be called twice for the auto-selection to get saved
     $this->init();
     $this->shippingMethods();
     $this->config->setRuntime('REQUIRE_SAME_ADDRESS', $sameAddress);
     return new ActionRedirectResponse('onePageCheckout', 'update');
     //return $this->getUpdateResponse('shippingMethods', 'shippingAddress', 'billingAddress');
 }
Пример #8
0
 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);
 }