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); }
/** * Add products to the database * * @return void */ private function seedUser() { User::truncate(); UserAddress::truncate(); Input::replace(array('username' => 'Test', 'email' => '*****@*****.**', 'addresses' => array(array('address' => '123 Fake Street', 'city' => 'Faketon'), array('address' => '10 Test Street', 'city' => 'Testville')))); $user = new User(); $user->saveRecursive(); }
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()); }
/** * @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; }
protected function getaddrdata() { $msg = array(); //名字 $data['consignee'] = empty($_POST['consignee']) ? '' : htmlspecialchars(trim($_POST['consignee'])); if (!$data['consignee']) { // $msg = '请输入姓名!\r\n'; $msg['error'] = '-1'; $msg['msg'] = '请输入姓名!'; echo json_encode($msg); throw new Exception('exit'); } //手机 $data['mobile'] = empty($_POST['mobile']) ? 0 : htmlspecialchars(trim($_POST['mobile'])); if ($data['mobile']) { $exp = "/^1\\d{10}\$/"; if (!preg_match($exp, $data['mobile'])) { // $msg .= '输入的手机格式错误!\r\n'; $msg['error'] = '-2'; $msg['msg'] = '输入的手机格式错误!'; echo json_encode($msg); throw new Exception('exit'); } } else { // $msg .= '请输入手机号码!\r\n'; $msg['error'] = '-3'; $msg['msg'] = '请输入手机号码!'; echo json_encode($msg); throw new Exception('exit'); } //电话 $tel_area = empty($_POST['tel_area']) ? '' : htmlspecialchars(trim($_POST['tel_area'])); $data['tel'] = empty($_POST['tel']) ? '' : htmlspecialchars(trim($_POST['tel'])); if ($data['tel']) { //填写了区号 if ($tel_area) { $data['tel'] = $tel_area . $data['tel']; } $exp = '/^(0?(([1-9]\\d)|([3-9]\\d{2}))-?)?\\d{7,8}$/'; if (!preg_match($exp, $data['tel'])) { // $msg .= '输入的固定电话错误!\r\n'; $msg['error'] = '-4'; $msg['msg'] = '输入的固定电话错误!'; echo json_encode($msg); throw new Exception('exit'); } } //省份 $data['province'] = empty($_POST['province']) ? 0 : htmlspecialchars(trim($_POST['province'])); if (!$data['province']) { // $msg .= '省不能为空!\r\n'; // $msg['error'] = '-5'; // $msg['msg'] = '省不能为空!'; // echo json_encode( $msg ); // throw new Exception('exit'); } // Assert::num_gt_zero($data['province'], '省份不能为空'); //城市 $data['city'] = empty($_POST['city']) ? 0 : htmlspecialchars(trim($_POST['city'])); if (!$data['city']) { // $msg .= '市不能为空!\r\n'; // $msg['error'] = '-6'; // $msg['msg'] = '市不能为空!'; // echo json_encode( $msg ); // throw new Exception('exit'); } // Assert::num_gt_zero($data['city'], '城市不能为空'); //地区 $data['district'] = empty($_POST['district']) ? 0 : htmlspecialchars(trim($_POST['district'])); // if( !$data['district'] ){ // // $msg .= '区不能为空!\r\n'; // $msg['error'] = '-7'; // $msg['msg'] = '区不能为空!'; // echo json_encode( $msg ); // throw new Exception('exit'); // } // Assert::num_gt_zero($data['district'], '区县不能为空'); //详细地址 $data['address'] = empty($_POST['address']) ? '' : htmlspecialchars(trim($_POST['address'])); if (!$data['address']) { // $msg .= '请输入详细地址!\r\n'; $msg['error'] = '-8'; $msg['msg'] = '请输入详细地址!'; echo json_encode($msg); throw new Exception('exit'); } //是否默认地址 $data['is_default'] = isset($_POST['is_default']) && !empty($_POST['is_default']) ? "yes" : 'no'; //用户id $data['uid'] = User::getLoginUid(); //如果有跳转地址,用户下单的时候添加地址,默认设置为默认地址 $addr_jump_url = LuS::get('addr_jump_url'); if (isset($addr_jump_url) && !empty($addr_jump_url)) { UserAddress::setDefaultAddressToNull($data['uid']); //去掉默认地址 $data['is_default'] = 'yes'; //设置当前为默认地址 } if ($msg) { // echo "$msg"; $msg['error'] = '-9'; $msg['msg'] = $msg; echo json_encode($msg); throw new Exception('exit'); } return $data; }
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; }
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 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; }
} else { $message = "Insufficient information provided."; } } if ($call == "saveUserAddress") { $userSeq = $_GET["userSeq"]; $addressType = $_GET["addressType"]; $isSameForShipping = $_GET["isSameForShipping"]; $address = $_GET["address"]; $city = $_GET["city"]; $state = $_GET["state"]; $country = $_GET["country"]; $pincode = $_GET["pincode"]; if ($userSeq != null) { try { $userAddress = new UserAddress(); $userAddress->setUserSeq($userSeq); $userAddress->setAddressType($addressType); $userAddress->setAddress($address); $userAddress->setCity($city); $userAddress->setState($state); $userAddress->setCountry($country); $userAddress->setPinCode($pincode); $userAddress->setIsSameForShipping($isSameForShipping); $userAddressSeq = $userManager->SaveUserAddress($userAddress); if ($userAddressSeq != null) { $success = 1; $message = "Address saved successfully"; } } catch (Exception $e) { $message = "Exception occured. Please try again.";
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(); }
/** * @param CartRequest $request */ public function processCart(CartRequest $request) { $re = array(); if (Request::isMethod('post') && $request->all()) { //save user $user = new User(); $uid = 0; $username = ""; $email = ""; $existUser = $user->getUserByEmail($request->get('email')); if (!empty($existUser)) { $uid = $existUser->id; $username = $existUser->name; $email = $existUser->email; } else { $item = array('name' => $request->get('name'), 'email' => $request->get('email'), 'phone' => $request->get('phone'), 'role' => BUYER); $createdUser = $user->createItem($item); $uid = $createdUser->id; $username = $createdUser->name; $email = $createdUser->email; } //save address receive $userReceive = new addressReceiveModel(); $item2 = array('name' => $request->get('name_2'), 'phone' => $request->get('phone_2'), 'street' => $request->get('street'), 'city_id' => $request->get('city_id'), 'ward_id' => $request->get('ward_id')); $address = $userReceive->createItem($item2); if ($uid != 0 && $address) { //create user address $userAddress = new UserAddress(); $option = array('user_id' => $uid, 'address_id' => $address->id); $userAddress->createItem($option); //create order and order detail $order = new Order(); $orderAtt = array('user_id' => $uid, 'address_id' => $address->id, 'total' => Cart::total(), 'ship' => 0, 'address' => $address->street . ", " . addressWardModel::showName($address->ward_id) . ", " . addressCityModel::showName($address->city_id)); $createdOrder = $order->createItem($orderAtt); $orderDetail = new OrderDetail(); if ($orderDetail->createItems($createdOrder->id, Cart::content())) { //send email $data = array('username' => $username, 'linkWebsite' => SITE_LINK, 'receiveName' => $address->name, 'receiveAddress' => $createdOrder->address, 'receivePhone' => $address->phone, 'carts' => Cart::content(), 'total' => Cart::total()); Cart::destroy(); if ($this->sendEmailOrder($email, $username, $data)) { $re = array('status' => 'ok', 'id' => $createdOrder->id); } else { $re = array('status' => 'error', 'message' => 'Bị lỗi trong quá trình gửi mail'); } } } echo json_encode($re); } }
public function balance() { //是否已经登录 User::isLogin(); $uid = LuS::get('uid'); //取出默认地址,没有默认地址默认为第一条 $default_address = UserAddress::getDefaultAddress($uid); if ($default_address) { $default_address_id = $default_address['address_id']; //地址详情 $address_detail = RegionM::getAddressDetail($default_address['province'], $default_address['city'], $default_address['district']); $default_address['address_detail'] = $address_detail . $default_address['address']; //电话 $call = UserAddress::getDefaultCall($default_address); $default_address['call'] = $call; } else { $default_address = null; $default_address_id = 0; } //取出购物车信息 $cart_goods_list = Cart::select($uid); if (!$cart_goods_list) { //购物车空空如也 $url = HOMEURL; header('Location:' . $url); throw new Exception('exit'); } $data = Cart::getOrderTotal($cart_goods_list); $total = $data['total']; $shipping_fee = Cart::getOrderShippingFee($total); $money_paid = $total + $shipping_fee; //下单链接 $add_order_url = url('goods', 'goods::addtoorder'); //详情链接,不带订单号,在页面上拼接上 $order_detail_url = url('usercenter', 'usercenter::detail'); //添加地址链接 $add_addr_url = url('usercenter', 'usercenter::addaddr'); //地址链接 $addr_url = url('usercenter', 'usercenter::addr'); //填写完地址后回跳 $addr_jump_url = url('goods', 'goods::balance'); LuS::set('addr_jump_url', $addr_jump_url); $smarty = get_smarty(); $smarty->assign('total', $total); $smarty->assign('amount', $money_paid); $smarty->assign('shipping_fee', $shipping_fee); $smarty->assign('default_address_id', $default_address_id); $smarty->assign('default_address', $default_address); $smarty->assign('goods_list', $cart_goods_list); $smarty->assign('add_order_url', $add_order_url); $smarty->assign('order_detail_url', $order_detail_url); $smarty->assign('add_addr_url', $add_addr_url); $smarty->assign('addr_url', $addr_url); $smarty->display('goods/order.html'); }
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; }
public function order_shoppers() { $id = Input::get('order_id'); $order = Order::find($id); $address = UserAddress::find($order->address_id); $shoppers = Shopper::where('zipcode', $address->zipcode)->get()->toArray(); $response = Response::json($shoppers); return $response; }
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 checkout_step3() { // Processing Cart $cart_id = $this->cart_id; if (!$cart_id) { $cart_id = Input::get('cart_id'); } $address_id = Input::get('address_id'); $payment_id = Input::get('payment_id'); $cart_products = DB::table('cart_products')->where('cart_id', $cart_id)->leftJoin('products', 'cart_products.product_id', '=', 'products.id')->leftJoin('users', 'cart_products.added_by', '=', 'users.id')->select('products.*', 'cart_products.quantity as cart_quantity', 'users.first_name as added_by')->orderBy('store_id')->get(); $cart_users = DB::table('cart_users')->leftJoin('users', 'cart_users.user_id', '=', 'users.id')->select('users.*')->get(); $response_array['cart'] = Cart::find($cart_id)->toArray(); $response_array['cart']['total_amount'] = 0; $response_array['cart']['total_quantity'] = 0; $response_array['cart']['users'] = array(); $response_array['cart']['stores'] = array(); $store_id = 0; if ($cart_products) { $response_array['cart']['is_minimum_reached'] = 1; foreach ($cart_products as $cart_product) { if ($store_id != $cart_product->store_id) { $store_id = $cart_product->store_id; // Retriving Store $store = Store::find($store_id)->toArray(); // Retriving Delivery Slot $time = date("Y-m-d H:i:s"); $slot = Slot::where('store_id', $store_id)->where('start_time', '>', $time)->where('is_available', 1)->orderBy('start_time')->first(); if ($slot) { $next_slot_start = date("D, jS M, H a", strtotime($slot->start_time)); $next_slot_end = date("h a", strtotime($slot->end_time)); $next_slot = $next_slot_start . " - " . $next_slot_end; } else { $next_slot = "No Slots available"; } $store['slot'] = $next_slot; $store['count'] = 1; $store['sub_total'] = 0; $response_array['cart']['stores'][$store_id] = $store; $response_array['cart']['stores'][$store_id]['products'] = array(); } else { $response_array['cart']['stores'][$store_id]['count'] += 1; } $product = json_decode(json_encode($cart_product), true); $product['sub_total'] = $product['cart_quantity'] * $product['price']; $response_array['cart']['stores'][$store_id]['sub_total'] += $product['sub_total']; $response_array['cart']['total_amount'] += $product['sub_total']; $response_array['cart']['total_quantity']++; array_push($response_array['cart']['stores'][$store_id]['products'], $product); } } if ($cart_users) { foreach ($cart_users as $cart_user) { $product = json_decode(json_encode($cart_user), true); array_push($response_array['cart']['users'], $cart_user); } } foreach ($response_array['cart']['stores'] as $st) { if ($st['sub_total'] < $st['minimum_order_amount']) { $response_array['cart']['is_minimum_reached'] = 0; } } if (isset($response_array['cart']['is_minimum_reached']) && $response_array['cart']['is_minimum_reached'] == 1) { $order = new Order(); $order->user_id = $this->user_id; $order->date = date("Y-m-d H:i:s"); $order->total_products = $response_array['cart']['total_quantity']; $order->total_amount = $response_array['cart']['total_amount']; $order->payment_id = $payment_id; $order->address_id = $address_id; $payment = Payment::find($payment_id); $order->payment_customer_id = $payment->customer_id; $address = UserAddress::find($address_id); $order->address = $address->address . " " . $address->zipcode; $order->status = "Initiated"; $order->save(); foreach ($cart_products as $cart_product) { $order_product = new OrderProduct(); $order_product->order_id = $order->id; $product = Product::find($cart_product->id); $product->total_sale += $cart_product->cart_quantity; $product->save(); $order_product->price = $cart_product->price; $order_product->quantity = $cart_product->cart_quantity; $order_product->fulfilment_status = "Pending"; $order_product->type = "Product"; $order_product->parent_id = 0; $order_product->product_name = $product->name; $order_product->product_image_url = $product->image_url; $order_product->product_quantity = $product->quantity; $order_product->product_unit = $product->unit; $order_product->store_id = $product->store_id; $order_product->save(); } // removing products from cart CartProduct::where('cart_id', $cart_id)->delete(); // Order Placement Mail $user = User::find($this->user_id); Mail::send('emails.order_success', array('user' => $user, 'order' => $order), function ($message) use($user) { $message->to($user->email, $user->first_name)->subject('Thanks for placing the order!'); }); // Order Placement Mail to Admin $admin_email = Config::get('app.admin_email'); Mail::send('emails.admin_order_success', array('user' => $user, 'order' => $order), function ($message) use($admin_email) { $message->to($admin_email, "Admin")->subject('New Order!'); }); } else { $message = "Minimum order amount not reached"; if (Request::format() == 'html') { return View::make('checkout_step3')->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores1', $this->stores)->with('message', $message); } else { $response_array = array('success' => false, 'error_code' => 411, 'error' => $message); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } if (Request::format() == 'html') { return View::make('checkout_step3')->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores1', $this->stores)->with('message', 'Thanks for placing your Order!!'); } else { $response_array = array('success' => true); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } }
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', '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; }
protected function saveAddress(UserAddress $address, $prefix = '') { $address->loadRequestData($this->request, $prefix); $address->countryID->set($this->request->get($prefix . 'country')); $address->stateName->set($this->request->get($prefix . 'state_text')); if ($this->request->get($prefix . 'state_select')) { $address->state->set(State::getStateByIDAndCountry($this->request->get($prefix . 'state_select'), $this->request->get($prefix . 'country'))); } else { $address->state->set(null); } $address->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); }
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 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); }
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(); } }
public static function addOrder($uid = 0, $username = '', $pay_name = '货到付款', $default_address_id = 0) { if ($uid) { //从购物车里获取到商品列表 $cart_goods_list = Cart::select($uid); if ($cart_goods_list) { //计算订单总金额 $order_total_data = self::getOrderTotal($cart_goods_list); $total = $order_total_data['total']; //运费 $shipping_fee = self::getOrderShippingFee($total); //优惠 $bonus = 0; //使用优惠券... //收货地址 $address_info = UserAddress::getAddrByAddressId($uid, $default_address_id); if (!$address_info) { $address_info = UserAddress::getDefaultAddress($uid); } $data['sn'] = self::createOrderSn(); //订单号 $data['uid'] = $uid; //用户id $data['username'] = $username; //用户名 $data['order_status'] = 'yes'; //订单有效 $data['consignee'] = $address_info['consignee']; //联系人 $data['province'] = $address_info['province']; //省 $data['city'] = $address_info['city']; //市 $data['district'] = $address_info['district']; //区 $data['address'] = $address_info['address']; //详细地址 $data['mobile'] = $address_info['mobile']; //手机或电话 $data['shipping_fee'] = $shipping_fee; //运费 $data['bonus'] = $bonus; //优惠 $data['order_money'] = $total; //货物总金额 $data['money_paid'] = $total + $shipping_fee + $bonus; //应付款金额 $data['pay_name'] = $pay_name; //付款方式 //非货到付款操作 if ($pay_name !== '货到付款') { $data['pay_time'] = time(); //支付时间 $data['confirm_status'] = 'yes'; //确认订单状态(非货到付款自动确认) $data['confirm_time'] = time(); //确认订单时间 } $rs = OrderInfo::addOrder($data); if ($rs) { //下单成功,减少库存 AdminGoodsM::minusStock($cart_goods_list); //添加到订单商品表 OrderGoodsInfo::addGoods($rs, $cart_goods_list); //删除购物车里面的商品信息 $where = self::_where($uid); Cart::delete($where); } //下单成功 return $rs; } } //下单失败 return false; }
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; }
public function actionSaveaddress() { $user_id = Yii::app()->user->id; if (!empty($_POST['UserAddress']['uad_type'])) { foreach ($_POST['UserAddress']['uad_type'] as $key => $uad_type) { $model = new UserAddress(); $model->uad_type = $uad_type; $model->uad_user_id = $user_id; $model->uad_add1 = $_POST['UserAddress']['uad_add1'][$uad_type]; $model->uad_add2 = $_POST['UserAddress']['uad_add2'][$uad_type]; $model->uad_country_id = $_POST['UserAddress']['uad_country_id'][$uad_type]; $model->uad_state_id = $_POST['UserAddress']['uad_state_id'][$uad_type]; $model->uad_city = $_POST['UserAddress']['uad_city'][$uad_type]; $model->uad_zipcode = $_POST['UserAddress']['uad_zipcode'][$uad_type]; $model->uad_mobile = $_POST['UserAddress']['uad_mobile'][$uad_type]; if (!empty($_POST['UserAddress']['uad_id'][$uad_type])) { $model->uad_id = $_POST['UserAddress']['uad_id'][$uad_type]; $model->isNewRecord = false; } else { $model->isNewRecord = true; } $model->save(false); } } Yii::app()->user->setFlash('success', 'Address updated successfully.'); $this->redirect(array('user/profile')); }
public static function updateDefaultAddress($uid, $address_id) { //取出上一条默认地址 $default_address_info = UserAddress::getDefaultAddress($uid); $where['uid'] = $uid; $where['address_id'] = $address_id; $data['is_default'] = 'yes'; $rs = self::_update($data, $where); if ($rs) { //把上一条默认地址的默认设置为no if ($default_address_info && $default_address_info['is_default'] == 'yes') { $old_where['uid'] = $uid; $old_where['address_id'] = $default_address_info['address_id']; $old_data['is_default'] = 'no'; self::_update($old_data, $old_where); } return $rs; } else { return false; } }
public function testAddress() { $address = UserAddress::getNewInstance(); $address->loadRequestData($this->request); $zone = DeliveryZone::getZoneByAddress($address, $this->request->get('type')); return new JSONResponse($zone->toArray()); }