/** * *@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; }
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 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(); } }
/** * 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 saveBillingAddress() { try { $address = BillingAddress::getUserAddress($this->request->get('id'), $this->user); } catch (ARNotFoundException $e) { return new ActionRedirectResponse('user', 'index'); } return $this->doSaveAddress($address, new ActionRedirectResponse('user', 'editBillingAddress', 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')); }
public function getCountry() { $countryCodes = array("Billing" => "", "Shipping" => ""); if ($this->BillingAddressID) { $billingAddress = BillingAddress::get()->byID($this->BillingAddressID); if ($billingAddress) { if ($billingAddress->Country) { $countryCodes["Billing"] = $billingAddress->Country; } } } if ($this->ShippingAddressID && $this->UseShippingAddress) { $shippingAddress = BillingAddress::get()->byID($this->ShippingAddressID); if ($shippingAddress) { if ($shippingAddress->ShippingCountry) { $countryCodes["Shipping"] = $shippingAddress->ShippingCountry; } } } if (EcommerceConfig::get("OrderAddress", "use_shipping_address_for_main_region_and_country") && $countryCodes["Shipping"] || !$countryCodes["Billing"] && $countryCodes["Shipping"]) { return $countryCodes["Shipping"]; } elseif ($countryCodes["Billing"]) { return $countryCodes["Billing"]; } else { return EcommerceCountry::get_country_from_ip(); } }
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; }
/** * 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); }
protected function memberBillingAddress_52() { DB::alteration_message("\r\n\t\t\t<h1>52. Member Billing Address</h1>\r\n\t\t\t<p>Move address details in the member table to its own class (billingaddress)</p>\r\n\t\t"); if ($this->hasTableAndField("Member", "Address")) { if ($this->hasTableAndField("Member", "City")) { $orders = DataObject::get('Order', "\"MemberID\" > 0 AND \"BillingAddress\".\"ID\" IS NULL AND \"BillingAddressID\" = 0", "", " LEFT JOIN \"BillingAddress\" ON \"Order\".\"BillingAddressID\" = \"BillingAddress\".\"ID\"", $this->start . "," . $this->limit); if ($orders) { foreach ($orders as $order) { if (!$order->BillingAddressID) { $member = DataObject::get_by_id("Member", $order->MemberID); if ($member) { $obj = new BillingAddress(); if (isset($member->Email)) { $obj->BillingEmail = $member->Email; } if (isset($member->FirstName)) { $obj->BillingFirstName = $member->FirstName; } if (isset($member->Surname)) { $obj->BillingSurname = $member->Surname; } if (isset($member->Address)) { $obj->BillingAddress = $member->Address; } if (isset($member->AddressLine2)) { $obj->BillingAddress2 = $member->AddressLine2; } if (isset($member->City)) { $obj->BillingCity = $member->City; } if (isset($member->PostalCode)) { $obj->BillingPostalCode = $member->PostalCode; } if (isset($member->State)) { $obj->BillingState = $member->State; } if (isset($member->Country)) { $obj->BillingCountry = $member->Country; } if (isset($member->Phone)) { $obj->BillingPhone = $member->Phone; } if (isset($member->HomePhone)) { $obj->BillingPhone .= $member->HomePhone; } if (isset($member->MobilePhone)) { $obj->MobilePhone = $member->MobilePhone; } $obj->OrderID = $order->ID; $obj->write(); $order->BillingAddressID = $obj->ID; $order->write(); } else { DB::alteration_message("There is no memmber associated with this order " . $order->ID, "deleted"); } } else { DB::alteration_message("Strange contraduction occurred!", "deleted"); } } $this->start + $this->limit; } else { DB::alteration_message("No orders need adjusting even though they followed the old pattern."); } } else { DB::alteration_message("There is no Address2 field, but there is an Address field in Member - this might be an issue.", "deleted"); } } else { DB::alteration_message("Members do not have a billing address to migrate."); } return 0; }
public function billaddress() { $BillingAddress = ShoppOrder()->Billing; $ShippingAddress = ShoppOrder()->Shipping; if (empty($BillingAddress)) { $BillingAddress = new BillingAddress(); } $form = $this->form('billing'); // Prevent overwriting the card data when updating the BillingAddress $ignore = array(); if (!empty($form['card']) && preg_replace('/[^\\d]/', '', $form['card']) == substr($BillingAddress->card, -4)) { $ignore[] = 'card'; } $BillingAddress->updates($form, $ignore); // Handle same address copying ShoppOrder()->sameaddress = strtolower($this->form('sameaddress')); if ('shipping' == ShoppOrder()->sameaddress) { $ShippingAddress->updates($form); } }
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 saveBillingAddress(BillingAddress $address) { $address->userAddress->get()->save(); return $address->save(); }
public function execute() { $this->bypassElement($this->theme->getBillingEmailAddressXpath()); return parent::execute(); }
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 memberBillingAddress_52() { $explanation = "\r\n\t\t\t<h1>52. Member Billing Address</h1>\r\n\t\t\t<p>Move address details in the member table to its own class (billingaddress)</p>\r\n\t\t"; if ($this->retrieveInfoOnly) { return $explanation; } else { echo $explanation; } if ($this->hasTableAndField("Member", "Address")) { if ($this->hasTableAndField("Member", "City")) { $orders = Order::get()->where("\"MemberID\" > 0")->leftJoin("BillingAddress", "\"Order\".\"BillingAddressID\" = \"BillingAddress\".\"ID\"")->limit($this->limit, $this->start); if ($orders->count()) { foreach ($orders as $order) { $member = Member::get()->byID($order->MemberID); if ($member) { if ($obj = $order->BillingAddress()) { $this->DBAlterationMessageNow("Order (id = " . $order->ID . ") already has a billing address"); //do nothing } else { $this->DBAlterationMessageNow("Order (id = " . $order->ID . ") now gets its own billing address..."); $obj = BillingAddress::create(); } if (isset($member->Email) && !$obj->Email) { $obj->Email = $member->Email; } if (isset($member->FirstName) && !$obj->FirstName) { $obj->FirstName = $member->FirstName; } if (isset($member->Surname) && !$obj->Surname) { $obj->Surname = $member->Surname; } if (isset($member->Address) && !$obj->Address) { $obj->Address = $member->Address; } if (isset($member->AddressLine2) && !$obj->Address2) { $obj->Address2 = $member->AddressLine2; } if (isset($member->City) && !$obj->City) { $obj->City = $member->City; } if (isset($member->PostalCode) && !$obj->PostalCode) { $obj->PostalCode = $member->PostalCode; } if (isset($member->State) && !$obj->State) { $obj->State = $member->State; } if (isset($member->Country) && !$obj->Country) { $obj->Country = $member->Country; } if (isset($member->Phone) && !$obj->Phone) { $obj->Phone = $member->Phone; } if (isset($member->HomePhone) && !$obj->HomePhone) { $obj->HomePhone .= $member->HomePhone; } if (isset($member->MobilePhone) && !$obj->MobilePhone) { $obj->MobilePhone = $member->MobilePhone; } $obj->OrderID = $order->ID; $obj->write(); $this->DBAlterationMessageNow("Updated Order #" . $order->ID . " with Member details", "created"); DB::query("Update \"Order\" SET \"BillingAddressID\" = " . $obj->ID . " WHERE \"Order\".ID = " . $order->ID); } else { $this->DBAlterationMessageNow("There is no member associated with this order " . $order->ID, "deleted"); } } return $this->start + $this->limit; } else { $this->DBAlterationMessageNow("No orders need adjusting even though they followed the old pattern."); } } else { $this->DBAlterationMessageNow("There is no Address2 field, but there is an Address field in Member - this might be an issue.", "deleted"); } } else { $this->DBAlterationMessageNow("Members do not have a billing 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); }
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 actionConfirm() { Yii::app()->user->setState('order_comment', @$_POST['Order']['Comment']); if (isset($_POST['accept_terms']) && $_POST['accept_terms'] == 1) { $order = new Order(); $customer = Shop::getCustomer(); $cart = Shop::getCartContent(); $order->customer_id = $customer->customer_id; $address = new DeliveryAddress(); if ($customer->deliveryAddress) { $address->attributes = $customer->deliveryAddress->attributes; } else { $address->attributes = $customer->address->attributes; } $address->save(); $order->delivery_address_id = $address->id; $address = new BillingAddress(); if ($customer->billingAddress) { $address->attributes = $customer->billingAddress->attributes; } else { $address->attributes = $customer->address->attributes; } $address->save(); $order->billing_address_id = $address->id; $order->ordering_date = time(); $order->payment_method = Yii::app()->user->getState('payment_method'); $order->shipping_method = Yii::app()->user->getState('shipping_method'); $order->comment = Yii::app()->user->getState('order_comment'); $order->status = 'new'; if ($order->save()) { foreach ($cart as $position => $product) { $position = new OrderPosition(); $position->order_id = $order->order_id; $position->product_id = $product['product_id']; $position->amount = $product['amount']; $position->specifications = json_encode($product['Variations']); $position->save(); } Shop::mailNotification($order); Shop::flushCart(true); if (Shop::module()->payPalMethod !== false && $order->payment_method == Shop::module()->payPalMethod) { $this->redirect(array(Shop::module()->payPalUrl, 'order_id' => $order->order_id)); } else { $this->redirect(Shop::module()->successAction); } } $this->redirect(Shop::module()->failureAction); } else { Shop::setFlash(Shop::t('Please accept our Terms and Conditions to continue')); $this->redirect(array('//shop/order/create')); } }
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 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 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'); }
/** * Ensures member unique id stays unique and other basic stuff... * @param array $data = Form Data * @return Boolean */ function php($data) { $valid = parent::php($data); $checkoutPage = CheckoutPage::get()->First(); if ($checkoutPage && $checkoutPage->TermsAndConditionsMessage) { if (isset($data["ReadTermsAndConditions"])) { if (!$data["ReadTermsAndConditions"]) { $this->validationError("ReadTermsAndConditions", $checkoutPage->TermsAndConditionsMessage, "required"); $valid = false; } } } $order = ShoppingCart::current_order(); if (!$order) { $this->validationError("Order", _t("OrderForm.ORDERNOTFOUND", "There was an error in processing your order, please try again or contact the administrator."), "required"); $valid = false; } $billingAddress = BillingAddress::get()->byID($order->BillingAddressID); if (!$billingAddress) { $this->validationError("BillingAddress", _t("OrderForm.MUSTHAVEBILLINGADDRESS", "All orders must have a billing address, please go back and add your details."), "required"); $valid = false; } return $valid; }