Skip to content

Instantly share code, notes, and snippets.

@eristoddle
Created September 19, 2012 17:45
Show Gist options
  • Save eristoddle/3751048 to your computer and use it in GitHub Desktop.
Save eristoddle/3751048 to your computer and use it in GitHub Desktop.
Python ZenCart Access
import MySQLdb
import MySQLdb.cursors
class zenMySql():
def __init__(self, host, user, password, db):
self.host = host
self.user = user
self.passwd = password
self.db = db
def __del__(self):
if self.conn: self.conn.close()
def dbConnect(self):
self.conn = MySQLdb.connect(host=self.host, user=self.user, \
passwd=self.passwd, db=self.db, cursorclass = MySQLdb.cursors.DictCursor)
self.cur = self.conn.cursor()
def executeQuery(self, query):
rowDump = []
self.cur.execute(query)
for row in self.cur:
rowDump.append(row)
return rowDump
def getBasket(self, cust_id):
return self.executeQuery("SELECT customers_basket_id, \
products_id, \
customers_basket_quantity, \
FROM customers_basket \
WHERE customers_id = '" + cust_id + "'")
def getOrderComments(self,order_id):
return self.executeQuery("SELECT comments \
FROM orders_status_history \
WHERE customer_notified = 1 \
AND orders_id = " + str(order_id))
def getNewOrderIds(self, lastorderid):
return self.executeQuery("SELECT \
orders.orders_id \
FROM orders \
WHERE orders.orders_id > " + str(lastorderid))
def getOrder(self, order_id):
return self.executeQuery("SELECT \
orders.orders_id,\
orders.customers_id,\
orders.customers_name,\
orders.customers_company,\
orders.customers_street_address,\
orders.customers_suburb,\
orders.customers_city,\
orders.customers_postcode,\
orders.customers_state,\
orders.customers_country,\
orders.customers_telephone,\
orders.customers_email_address,\
orders.customers_address_format_id,\
orders.delivery_name,\
orders.delivery_company,\
orders.delivery_street_address,\
orders.delivery_suburb,\
orders.delivery_city,\
orders.delivery_postcode,\
orders.delivery_state,\
orders.delivery_country,\
orders.delivery_address_format_id,\
orders.billing_name,\
orders.billing_company,\
orders.billing_street_address,\
orders.billing_suburb,\
orders.billing_city,\
orders.billing_postcode,\
orders.billing_state,\
orders.billing_country,\
orders.billing_address_format_id,\
orders.payment_method,\
orders.payment_module_code,\
orders.shipping_method,\
orders.shipping_module_code,\
orders.coupon_code,\
orders.cc_type,\
orders.cc_owner,\
orders.cc_number,\
orders.cc_expires,\
orders.cc_cvv,\
orders.last_modified,\
orders.date_purchased,\
orders.orders_status,\
orders.orders_date_finished,\
orders.currency,\
orders.currency_value,\
orders.order_total,\
orders.order_tax,\
orders.paypal_ipn_id,\
orders.ip_address\
FROM orders\
WHERE orders.orders_id = " + str(order_id))
def getOrderLines(self, order_id):
return self.executeQuery("SELECT orders_products.orders_products_id,\
orders_products.orders_id,\
orders_products.products_id,\
orders_products.products_model,\
orders_products.products_name,\
orders_products.products_price,\
orders_products.final_price,\
orders_products.products_tax,\
orders_products.products_quantity,\
orders_products.onetime_charges,\
orders_products.products_priced_by_attribute,\
orders_products.product_is_free,\
orders_products.products_discount_type,\
orders_products.products_discount_type_from,\
orders_products.products_prid\
FROM orders_products\
WHERE orders_products.orders_id = " + str(order_id))
def getOrderTotals(self, order_id):
return self.executeQuery("SELECT \
orders_total.orders_total_id, \
orders_total.orders_id, \
orders_total.title, \
orders_total.text, \
orders_total.`value`, \
orders_total.class, \
orders_total.sort_order \
FROM \
orders_total \
WHERE orders_total.orders_id = " + str(order_id))
def getProductById(self, product_id):
return self.executeQuery("SELECT products_model, \
products_price,\
customers_basket_quantity, \
from products \
WHERE products_id = '" + product_id + "'")
def getCustomerById(self, cust_id):
return self.executeQuery("SELECT customers_firstname, \
customers_lastname, \
customers_email_address, \
customers_default_address_id, \
customers_telephone, \
customers_id \
FROM customers \
WHERE customers_id = '" + cust_id + "'")
def getCustomerByName(self, firstname, lastname):
#TODO: This may return more than one
return self.executeQuery("SELECT customers_firstname, \
customers_lastname, \
customers_email_address, \
customers_default_address_id, \
customers_telephone, \
customers_id \
FROM customers \
WHERE customers_firstname = '" + firstname + "' \
AND customers_lastname = '" + lastname + "'")
def getCustomerAddress(self, address_id):
return self.executeQuery("SELECT customers_id, \
entry_company, \
entry_firstname, \
entry_lastname, \
entry_street_address, \
entry_postcode, \
entry_street_address, \
entry_state, \
FROM address_book \
WHERE address_book_id = '" + address_id + "'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment