/** * *@return SQLQuery **/ public function apply(DataQuery $query) { $this->model = $query->applyRelation($this->relation); $value = $this->getValue(); $billingAddressesIDs = array(-1 => -1); $billingAddresses = BillingAddress::get()->where("\r\n\t\t\t\"FirstName\" LIKE '%{$value}%' OR\r\n\t\t\t\"Surname\" LIKE '%{$value}%' OR\r\n\t\t\t\"Email\" LIKE '%{$value}%' OR\r\n\t\t\t\"Address\" LIKE '%{$value}%' OR\r\n\t\t\t\"Address2\" LIKE '%{$value}%' OR\r\n\t\t\t\"City\" LIKE '%{$value}%' OR\r\n\t\t\t\"PostalCode\" LIKE '%{$value}%' OR\r\n\t\t\t\"Phone\" LIKE '%{$value}%'\r\n\t\t"); if ($billingAddresses->count()) { $billingAddressesIDs = $billingAddresses->map("ID", "ID")->toArray(); } $where[] = "\"BillingAddressID\" IN (" . implode(",", $billingAddressesIDs) . ")"; $shippingAddressesIDs = array(-1 => -1); $shippingAddresses = ShippingAddress::get()->where("\r\n\t\t\t\"ShippingFirstName\" LIKE '%{$value}%' OR\r\n\t\t\t\"ShippingSurname\" LIKE '%{$value}%' OR\r\n\t\t\t\"ShippingAddress\" LIKE '%{$value}%' OR\r\n\t\t\t\"ShippingAddress2\" LIKE '%{$value}%' OR\r\n\t\t\t\"ShippingCity\" LIKE '%{$value}%' OR\r\n\t\t\t\"ShippingPostalCode\" LIKE '%{$value}%' OR\r\n\t\t\t\"ShippingPhone\" LIKE '%{$value}%'\r\n\t\t"); if ($shippingAddresses->count()) { $shippingAddressesIDs = $shippingAddresses->map("ID", "ID")->toArray(); } $where[] = "\"ShippingAddressID\" IN (" . implode(",", $shippingAddressesIDs) . ")"; $memberIDs = array(-1 => -1); $members = Member::get()->where("\r\n\t\t\t\"FirstName\" LIKE '%{$value}%' OR\r\n\t\t\t\"Surname\" LIKE '%{$value}%' OR\r\n\t\t\t\"Email\" LIKE '%{$value}%'\r\n\t\t"); if ($members->count()) { $memberIDs = $members->map("ID", "ID")->toArray(); } $where[] = "\"MemberID\" IN (" . implode(",", $memberIDs) . ")"; $query = $query->where("(" . implode(") OR (", $where) . ")"); return $query; }
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; }
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 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'); }
/** * Delivers customer export files to the browser * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function export_customers() { if (!current_user_can('shopp_export_customers')) { exit; } if (!isset($_POST['settings']['customerexport_columns'])) { $Customer = ShoppCustomer::exportcolumns(); $Billing = BillingAddress::exportcolumns(); $Shipping = ShippingAddress::exportcolumns(); $_POST['settings']['customerexport_columns'] = array_keys(array_merge($Customer, $Billing, $Shipping)); $_POST['settings']['customerexport_headers'] = 'on'; } shopp_set_formsettings(); // Save workflow setting $format = shopp_setting('customerexport_format'); if (empty($format)) { $format = 'tab'; } switch ($format) { case 'csv': new CustomersCSVExport(); break; default: new CustomersTabExport(); } exit; }
/** * @role login */ public function saveShippingAddress() { try { $address = ShippingAddress::getUserAddress($this->request->get('id'), $this->user); } catch (ARNotFoundException $e) { return new ActionRedirectResponse('user', 'index'); } return $this->doSaveAddress($address, new ActionRedirectResponse('user', 'editShippingAddress', array('id' => $this->request->get('id'), 'query' => array('return' => $this->request->get('return'))))); }
public function __construct() { $this->customer_cols = ShoppCustomer::exportcolumns(); $this->billing_cols = BillingAddress::exportcolumns(); $this->shipping_cols = ShippingAddress::exportcolumns(); $this->defined = array_merge($this->customer_cols, $this->billing_cols, $this->shipping_cols); $this->sitename = get_bloginfo('name'); $this->headings = shopp_setting('customerexport_headers') == "on"; $this->selected = shopp_setting('customerexport_columns'); shopp_set_setting('customerexport_lastexport', current_time('timestamp')); }
/** * *@return GridField **/ protected function getShippingAddressField() { $this->CreateOrReturnExistingAddress("ShippingAddress"); $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(10), new GridFieldEditButton(), new GridFieldDetailForm()); //$source = $this->ShippingAddress(); $source = ShippingAddress::get()->filter(array("OrderID" => $this->ID)); return new GridField("ShippingAddress", _t("BillingAddress.SINGULARNAME", "Shipping Address"), $source, $gridFieldConfig); }
public function shipaddress() { $ShippingAddress = ShoppOrder()->Shipping; $BillingAddress = ShoppOrder()->Billing; if (empty($ShippingAddress)) { $ShippingAddress = new ShippingAddress(); } $form = $this->form('shipping'); if (!empty($form)) { $ShippingAddress->updates($form); } // Handle same address copying ShoppOrder()->sameaddress = strtolower($this->form('sameaddress')); if ('billing' == ShoppOrder()->sameaddress) { $BillingAddress->updates($form); } }
public function validSend($data) { require_once DIR_SYSTEM . 'library/stelo/Stelo.php'; $this->load->model('account/customer'); $this->load->model('checkout/order'); $customer = $this->model_account_customer->getCustomer($data['customer_id']); $order_total = $this->model_checkout_order->getOrderTotal($this->session->data['order_id'], 'shipping'); $params = array(); $converter = new Converter(); //OrderData $orderData = new OrderData(); $orderData->setOrderId((string) $this->session->data['order_id']); $params['orderData'] = $converter->convertOrderData($orderData); //PaymentData $paymentData = new PaymentData(); $paymentData->setAmount((double) number_format($data['total'], 2, '.', '')); $paymentData->setDiscountAmount(''); $paymentData->setFreight((double) number_format($order_total['value'], 2, '.', '')); $paymentData->setMaxInstallment('4'); // CartData if ($this->cart->getProducts()) { foreach ($this->cart->getProducts() as $product) { $cartData = new CartDataCollection(); $cartData->setProductName($product['name']); $cartData->setProductPrice((double) number_format($product['price'], 2, '.', '')); $cartData->setProductQuantity($product['quantity']); $cartData->setProductSku(substr($product['model'], 0, 19)); $paymentData->setCartData($cartData); } } $params['paymentData'] = $converter->convertPaymentData($paymentData); //CustomerData $customerData = new CustomerData(); $customerData->setCustomerIdentity(str_replace('/', '', str_replace('-', '', str_replace('.', '', $data['cpf_cnpj'])))); $customerData->setCustomerName($data['firstname'] . ' ' . $data['lastname']); $customerData->setCustomerEmail($data['email']); $customerData->setBirthDay($customer['birthday']); $customerData->setGender($customer['sex']); // Billing Address $billingAddress = new BillingAddress(); $billingAddress->setStreet($data['payment_address_1']); $billingAddress->setNumber($data['payment_number_home']); $billingAddress->setComplement($data['payment_address_2']); $billingAddress->setNeighborhood($data['payment_neighborhood']); $billingAddress->setZipcode($data['payment_postcode']); $billingAddress->setCity($data['payment_city']); $billingAddress->setState($data['payment_zone_code']); $customerData->setBillingAddress($billingAddress); // Shipping Address $shippingAddress = new ShippingAddress(); $shippingAddress->setStreet($data['shipping_address_1']); $shippingAddress->setNumber($data['shipping_number_home']); $shippingAddress->setComplement($data['shipping_address_2']); $shippingAddress->setNeighborhood($data['shipping_neighborhood']); $shippingAddress->setZipcode($data['shipping_postcode']); $shippingAddress->setCity($data['shipping_city']); $shippingAddress->setState($data['shipping_zone_code']); $customerData->setShippingAddress($shippingAddress); // Phone Data $phoneData = new PhoneDataCollection(); $phoneData->setPhoneType("CELL"); $phoneData->setNumber(str_replace('(', '', str_replace(')', '', str_replace('-', '', str_replace(' ', '', $data['cellphone']))))); $customerData->setPhoneData($phoneData); $params['customerData'] = $converter->convertCustomerData($customerData); $params['changeShipment'] = false; //$url = 'http://200.142.203.223/ec/V1/wallet/transactions'; //Homologação $url = 'http://api.stelo.com.br/ec/V1/wallet/transactions'; $stelo = new Stelo(); $response = $stelo->sendRequest($url, $this->config->get('stelo_client_id'), $this->config->get('stelo_client_secret'), $params); $insert = "INSERT INTO " . DB_PREFIX . "transaction_stelo SET order_id = '" . $this->session->data['order_id'] . "', json_encode = '" . json_encode($params) . "', "; if ($response) { $insert .= "link_confirm = '" . $response['link'][0]['@href'] . "', link_cancel = '" . $response['link'][1]['@href'] . "', link_wallet = '" . $response['link'][2]['@href'] . "', order_stelo_id = '" . $response['orderData']['orderId'] . "', "; } $insert .= "date_added = NOW()"; $this->db->query($insert); return true; }
public function add() { if ('new-customer' != $this->form('order-action')) { return; } if (!($updates = $this->form('customer'))) { return; } if (!is_array($updates)) { return; } extract($this->references, EXTR_SKIP); // Create the new customer record $Customer = new ShoppCustomer(); $Customer->updates($updates); $Customer->password = wp_generate_password(12, true); if ('wordpress' == shopp_setting('account_system')) { $Customer->create_wpuser(); } else { unset($this->form['loginname']); } $Customer->save(); if (!$Customer->exists()) { return $this->notice(Shopp::__('An unknown error occured. The customer could not be created.'), 'error'); } $Purchase->customer = $Customer->id; $Purchase->copydata($Customer); $Purchase->save(); // Create a new billing address record for the new customer if ($billing = $this->form('billing') && is_array($billing) && empty($billing['id'])) { $Billing = new BillingAddress($billing); $Billing->customer = $Customer->id; $Billing->save(); } // Create a new shipping address record for the new customer if ($shipping = $this->form('shipping') && is_array($shipping) && empty($shipping['id'])) { $Shipping = new ShippingAddress($shipping); $Shipping->customer = $Customer->id; $Shipping->save(); } }
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 createorder() { $order = new Order(); $order->UseShippingAddress = true; $order->CustomerOrderNote = "THIS IS AN AUTO-GENERATED ORDER"; $order->write(); $member = new Member(); $member->FirstName = 'Tom'; $member->Surname = 'Cruize'; $member->Email = '*****@*****.**'; $member->Password = '******'; $member->write(); $order->MemberID = $member->ID; $billingAddress = new BillingAddress(); $billingAddress->Prefix = "Dr"; $billingAddress->FirstName = "Tom"; $billingAddress->Surname = "Cruize"; $billingAddress->Address = "Lamp Drive"; $billingAddress->Address2 = "Linux Mountain"; $billingAddress->City = "Apache Town"; $billingAddress->PostalCode = "555"; $billingAddress->Country = "NZ"; $billingAddress->Phone = "555 5555555"; $billingAddress->Email = "*****@*****.**"; $billingAddress->write(); $order->BillingAddressID = $billingAddress->ID; $shippingAddress = new ShippingAddress(); $shippingAddress->ShippingPrefix = "Dr"; $shippingAddress->ShippingFirstName = "Tom"; $shippingAddress->ShippingSurname = "Cruize"; $shippingAddress->ShippingAddress = "Lamp Drive"; $shippingAddress->ShippingAddress2 = "Linux Mountain"; $shippingAddress->ShippingCity = "Apache Town"; $shippingAddress->ShippingPostalCode = "555"; $shippingAddress->ShippingCountry = "NZ"; $shippingAddress->ShippingPhone = "555 5555555"; $shippingAddress->write(); $order->ShippingAddressID = $shippingAddress->ID; //get a random product $extension = ""; if (Versioned::current_stage() == "Live") { $extension = "_Live"; } $count = 0; $noProductYet = true; $triedArray = array(0 => 0); while ($noProductYet && $count < 50) { $product = Product::get()->where("\"ClassName\" = 'Product' AND \"Product{$extension}\".\"ID\" NOT IN (" . implode(",", $triedArray) . ") AND Price > 0")->First(); if ($product) { if ($product->canPurchase()) { $noProductYet = false; } else { $triedArray[] = $product->ID; } } $count++; } //adding product order item $item = new Product_OrderItem(); $item->addBuyableToOrderItem($product, 7); $item->OrderID = $order->ID; $item->write(); //final save $order->write(); $order->tryToFinaliseOrder(); }
/** * Remove a customer, and data associated with the customer * * @api * @since 1.2 * * @param int $customer (required) id of the customer to remove * @return bool true on success, false on failure **/ function shopp_rmv_customer($customer = false) { if (!$customer) { shopp_debug(__FUNCTION__ . " failed: Customer id required."); return false; } $Customer = new ShoppCustomer($customer); if (empty($Customer->id)) { shopp_debug("shopp_rmv_customer notice: No such customer with id {$customer}"); return false; } // Remove Addresses $Billing = new BillingAddress($customer, 'customer'); $Shipping = new ShippingAddress($customer, 'customer'); if (!empty($Billing->id)) { $Billing->delete(); } if (!empty($Shipping->id)) { $Shipping->delete(); } // Remove Meta records $metas = shopp_meta($customer, 'customer'); foreach ($metas as $meta) { shopp_rmv_meta($meta->id); } // Remove Customer record $Customer->delete(); return true; }
protected function orderShippingAddress_50() { $explanation = "\r\n\t\t\t<h1>50. Order Shipping Address</h1>\r\n\t\t\t<p>Move a shipping address from within Order to its own class.</p>\r\n\t\t"; if ($this->retrieveInfoOnly) { return $explanation; } else { echo $explanation; } if ($this->hasTableAndField("Order", "ShippingAddress")) { if ($this->hasTableAndField("Order", "UseShippingAddress")) { $orders = Order::get()->where("\"UseShippingAddress\" = 1 AND \"ShippingAddress\".\"ID\" IS NULL")->leftJoin("ShippingAddress", "\"Order\".\"ShippingAddressID\" = \"ShippingAddress\".\"ID\"")->limit($this->limit, $this->start); if ($orders->count()) { foreach ($orders as $order) { if (!$order->ShippingAddressID) { $obj = ShippingAddress::create(); if (isset($order->ShippingName)) { $obj->ShippingName = $order->ShippingName; } if (isset($order->ShippingAddress)) { $obj->ShippingAddress = $order->ShippingAddress; } if (isset($order->ShippingAddress2)) { $obj->ShippingAddress2 = $order->ShippingAddress2; } if (isset($order->ShippingCity)) { $obj->ShippingCity = $order->ShippingCity; } if (isset($order->ShippingPostalCode)) { $obj->ShippingPostalCode = $order->ShippingPostalCode; } if (isset($order->ShippingState)) { $obj->ShippingState = $order->ShippingState; } if (isset($order->ShippingCountry)) { $obj->ShippingCountry = $order->ShippingCountry; } if (isset($order->ShippingPhone)) { $obj->ShippingPhone = $order->ShippingPhone; } if (isset($order->ShippingHomePhone)) { $obj->ShippingPhone .= $order->ShippingHomePhone; } if (isset($order->ShippingMobilePhone)) { $obj->ShippingMobilePhone = $order->ShippingMobilePhone; } $obj->OrderID = $order->ID; $obj->write(); $order->ShippingAddressID = $obj->ID; $order->write(); } else { $this->DBAlterationMessageNow("Strange contradiction occurred in Order with ID" . $order->ID, "deleted"); } } return $this->start + $this->limit; } else { $this->DBAlterationMessageNow("No orders need adjusting even though they followed the old pattern."); } $this->makeFieldObsolete("Order", "ShippingName"); $this->makeFieldObsolete("Order", "ShippingAddress"); $this->makeFieldObsolete("Order", "ShippingAddress2"); $this->makeFieldObsolete("Order", "ShippingCity"); $this->makeFieldObsolete("Order", "ShippingPostalCode"); $this->makeFieldObsolete("Order", "ShippingState"); $this->makeFieldObsolete("Order", "ShippingCountry"); $this->makeFieldObsolete("Order", "ShippingPhone"); $this->makeFieldObsolete("Order", "ShippingHomePhone"); $this->makeFieldObsolete("Order", "ShippingMobilePhone"); } else { $this->DBAlterationMessageNow("There is no UseShippingAddress field even though there is a ShippingAddress Field - this is an issue.", "deleted"); } } else { $this->DBAlterationMessageNow("Orders do not have the shipping address to migrate."); } return 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); }
protected function orderShippingAddress_50() { DB::alteration_message("\r\n\t\t\t<h1>50. Order Shipping Address</h1>\r\n\t\t\t<p>Move a shipping address from within Order to its own class.</p>\r\n\t\t"); if ($this->hasTableAndField("Order", "ShippingAddress")) { if ($this->hasTableAndField("Order", "UseShippingAddress")) { $orders = DataObject::get('Order', "\"UseShippingAddress\" = 1 AND \"ShippingAddress\".\"ID\" IS NULL", "", " LEFT JOIN \"ShippingAddress\" ON \"Order\".\"ShippingAddressID\" = \"ShippingAddress\".\"ID\"", $this->start . "," . $this->limit); if ($orders) { foreach ($orders as $order) { if (!$order->ShippingAddressID) { $obj = new ShippingAddress(); if (isset($order->ShippingName)) { $obj->ShippingName = $order->ShippingName; } if (isset($order->ShippingAddress)) { $obj->ShippingAddress = $order->ShippingAddress; } if (isset($order->ShippingAddress2)) { $obj->ShippingAddress2 = $order->ShippingAddress2; } if (isset($order->ShippingCity)) { $obj->ShippingCity = $order->ShippingCity; } if (isset($order->ShippingPostalCode)) { $obj->ShippingPostalCode = $order->ShippingPostalCode; } if (isset($order->ShippingState)) { $obj->ShippingState = $order->ShippingState; } if (isset($order->ShippingCountry)) { $obj->ShippingCountry = $order->ShippingCountry; } if (isset($order->ShippingPhone)) { $obj->ShippingPhone = $order->ShippingPhone; } if (isset($order->ShippingHomePhone)) { $obj->ShippingPhone .= $order->ShippingHomePhone; } if (isset($order->ShippingMobilePhone)) { $obj->ShippingMobilePhone = $order->ShippingMobilePhone; } $obj->OrderID = $order->ID; $obj->write(); $order->ShippingAddressID = $obj->ID; $order->write(); } else { DB::alteration_message("Strange contradiction occurred in Order with ID" . $order->ID, "deleted"); } } return $this->start + $this->limit; } else { DB::alteration_message("No orders need adjusting even though they followed the old pattern."); } $this->makeFieldObsolete("Order", "ShippingName"); $this->makeFieldObsolete("Order", "ShippingAddress"); $this->makeFieldObsolete("Order", "ShippingAddress2"); $this->makeFieldObsolete("Order", "ShippingCity"); $this->makeFieldObsolete("Order", "ShippingPostalCode"); $this->makeFieldObsolete("Order", "ShippingState"); $this->makeFieldObsolete("Order", "ShippingCountry"); $this->makeFieldObsolete("Order", "ShippingPhone"); $this->makeFieldObsolete("Order", "ShippingHomePhone"); $this->makeFieldObsolete("Order", "ShippingMobilePhone"); } else { DB::alteration_message("There is no UseShippingAddress field even though there is a ShippingAddress Field - this is an issue.", "deleted"); } } else { DB::alteration_message("Orders do not have the shipping address to migrate."); } return 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; }
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(); } }
public function screen() { global $wpdb; $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'paged' => false, 'per_page' => 20, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); if ($page == ShoppAdmin::pagename('customers') && !empty($deleting) && !empty($selected) && is_array($selected) && current_user_can('shopp_delete_customers')) { foreach ($selected as $deletion) { $Customer = new ShoppCustomer($deletion); $Billing = new BillingAddress($Customer->id, 'customer'); $Billing->delete(); $Shipping = new ShippingAddress($Customer->id, 'customer'); $Shipping->delete(); $Customer->delete(); } } $updated = false; // if (!empty($_POST['save'])) { // check_admin_referer('shopp-save-customer'); // $wp_integration = ('wordpress' === shopp_setting( 'account_system' )); // // if ($_POST['id'] !== 'new') { // $Customer = new ShoppCustomer($_POST['id']); // $Billing = new BillingAddress($Customer->id, 'customer'); // $Shipping = new ShippingAddress($Customer->id, 'customer'); // } else $Customer = new ShoppCustomer(); // // if (!empty($Customer->wpuser)) $user = get_user_by('id',$Customer->wpuser); // $new_customer = empty( $Customer->id ); // // $Customer->updates($_POST); // // // Reassign WordPress login // if ($wp_integration && isset($_POST['userlogin']) && $_POST['userlogin'] != $user->user_login) { // $newlogin = get_user_by('login', $_POST['userlogin']); // if ( ! empty($newlogin->ID) ) { // if (sDB::query("SELECT count(*) AS used FROM $Customer->_table WHERE wpuser=$newlogin->ID",'auto','col','used') == 0) { // $Customer->wpuser = $newlogin->ID; // $updated = sprintf(__('Updated customer login to %s.','Shopp'),"<strong>$newlogin->user_login</strong>"); // } else $updated = sprintf(__('Could not update customer login to "%s" because that user is already assigned to another customer.','Shopp'),'<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // // } else $updated = sprintf(__('Could not update customer login to "%s" because the user does not exist in WordPress.','Shopp'),'<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // if ( empty($_POST['userlogin']) ) $Customer->wpuser = 0; // } // // if ( ! empty($_POST['new-password']) && !empty($_POST['confirm-password']) // && $_POST['new-password'] == $_POST['confirm-password']) { // $Customer->password = wp_hash_password($_POST['new-password']); // if (!empty($Customer->wpuser)) wp_set_password($_POST['new-password'], $Customer->wpuser); // } // // $valid_email = filter_var( $_POST['email'], FILTER_VALIDATE_EMAIL ); // $password = !empty( $_POST['new_password'] ); // // if ($wp_integration && $new_customer && $valid_email && $password) { // $Customer->loginname = $_POST['userlogin']; // $Customer->email = $_POST['email']; // $Customer->firstname = $_POST['firstname']; // $Customer->lastname = $_POST['lastname']; // // $return = $Customer->create_wpuser(); // // if ( $return ) { // $updated = sprintf( __( 'The Shopp and WordPress accounts have been created with the username "%s".', 'Shopp'), '<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // } else { // $updated = sprintf( __( 'Could not create a WordPress account for customer "%s".','Shopp'), '<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // } // } // elseif ($new_customer && ( !$valid_email || !$password ) ) { // $updated = __( 'Could not create new user. You must enter a valid email address and a password first.', 'Shopp' ); // $no_save = true; // } // // if ( !isset( $new_save ) ) { // $Customer->info = false; // No longer used from DB // $Customer->save(); // } // // // if (isset($_POST['info']) && !empty($_POST['info'])) { // foreach ((array)$_POST['info'] as $id => $info) { // $Meta = new ShoppMetaObject($id); // $Meta->value = $info; // $Meta->save(); // } // } // // if (isset($Customer->id)) $Billing->customer = $Customer->id; // $Billing->updates($_POST['billing']); // $Billing->save(); // // if (isset($Customer->id)) $Shipping->customer = $Customer->id; // $Shipping->updates($_POST['shipping']); // $Shipping->save(); // if (!$updated) __('Customer updated.','Shopp'); // $Customer = false; // // } $pagenum = absint($paged); if (empty($pagenum)) { $pagenum = 1; } if (!$per_page || $per_page < 0) { $per_page = 20; } $index = $per_page * ($pagenum - 1); if (!empty($start)) { $startdate = $start; list($month, $day, $year) = explode("/", $startdate); $starts = mktime(0, 0, 0, $month, $day, $year); } if (!empty($end)) { $enddate = $end; list($month, $day, $year) = explode("/", $enddate); $ends = mktime(23, 59, 59, $month, $day, $year); } $customer_table = ShoppDatabaseObject::tablename(Customer::$table); $billing_table = ShoppDatabaseObject::tablename(BillingAddress::$table); $purchase_table = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $users_table = $wpdb->users; $where = array(); if (!empty($s)) { $s = stripslashes($s); if (preg_match_all('/(\\w+?)\\:(?="(.+?)"|(.+?)\\b)/', $s, $props, PREG_SET_ORDER)) { foreach ($props as $search) { $keyword = !empty($search[2]) ? $search[2] : $search[3]; switch (strtolower($search[1])) { case "company": $where[] = "c.company LIKE '%{$keyword}%'"; break; case "login": $where[] = "u.user_login LIKE '%{$keyword}%'"; break; case "address": $where[] = "(b.address LIKE '%{$keyword}%' OR b.xaddress='%{$keyword}%')"; break; case "city": $where[] = "b.city LIKE '%{$keyword}%'"; break; case "province": case "state": $where[] = "b.state='{$keyword}'"; break; case "zip": case "zipcode": case "postcode": $where[] = "b.postcode='{$keyword}'"; break; case "country": $where[] = "b.country='{$keyword}'"; break; } } } elseif (strpos($s, '@') !== false) { $where[] = "c.email='{$s}'"; } elseif (is_numeric($s)) { $where[] = "c.id='{$s}'"; } else { $where[] = "(CONCAT(c.firstname,' ',c.lastname) LIKE '%{$s}%' OR c.company LIKE '%{$s}%')"; } } if (!empty($starts) && !empty($ends)) { $where[] = ' (UNIX_TIMESTAMP(c.created) >= ' . $starts . ' AND UNIX_TIMESTAMP(c.created) <= ' . $ends . ')'; } $select = array('columns' => 'SQL_CALC_FOUND_ROWS c.*,city,state,country,user_login', 'table' => "{$customer_table} as c", 'joins' => array($billing_table => "LEFT JOIN {$billing_table} AS b ON b.customer=c.id AND b.type='billing'", $users_table => "LEFT JOIN {$users_table} AS u ON u.ID=c.wpuser AND (c.wpuser IS NULL OR c.wpuser != 0)"), 'where' => $where, 'groupby' => "c.id", 'orderby' => "c.created DESC", 'limit' => "{$index},{$per_page}"); $query = sDB::select($select); $Customers = sDB::query($query, 'array', 'index', 'id'); $total = sDB::found(); // Add order data to customer records in this view $orders = sDB::query("SELECT customer,SUM(total) AS total,count(id) AS orders FROM {$purchase_table} WHERE customer IN (" . join(',', array_keys($Customers)) . ") GROUP BY customer", 'array', 'index', 'customer'); foreach ($Customers as &$record) { $record->total = 0; $record->orders = 0; if (!isset($orders[$record->id])) { continue; } $record->total = $orders[$record->id]->total; $record->orders = $orders[$record->id]->orders; } $num_pages = ceil($total / $per_page); $ListTable = ShoppUI::table_set_pagination(ShoppAdmin::screen(), $total, $num_pages, $per_page); $ranges = array('all' => __('Show New Customers', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft® Excel.xls', 'Shopp')); $formatPref = shopp_setting('customerexport_format'); if (!$formatPref) { $formatPref = 'tab'; } $columns = array_merge(Customer::exportcolumns(), BillingAddress::exportcolumns(), ShippingAddress::exportcolumns()); $selected = shopp_setting('customerexport_columns'); if (empty($selected)) { $selected = array_keys($columns); } $authentication = shopp_setting('account_system'); $action = add_query_arg(array('page' => ShoppAdmin::pagename('customers')), admin_url('admin.php')); include $this->ui('customers.php'); }
/** * Standard SS method * @param Member $member * @return Boolean */ function canDelete($member = null) { if (ShippingAddress::get()->filter(array("ShippingCountry" => $this->Code))->count()) { return false; } if (BillingAddress::get()->filter(array("Country" => $this->Code))->count()) { return false; } if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { return true; } return parent::canEdit($member); }