/** * Add a product to the cart * @param int $productID * @param int $qty * @return int $cartProductID */ public function addProductToCart($productID, $qty) { // fetch product information $query = "SELECT price FROM aca_product WHERE id = :id"; $result = $this->db->fetchRow($query, array('id' => $productID)); $productPrice = $result['price']; $cartID = $this->session->get('cartID'); // insert into aca_cart_product $cartProductID = $this->db->insert('aca_cart_product', array('cart_id' => $cartID, 'product_id' => $productID, 'unit_price' => $productPrice, 'quantity' => $qty)); return $cartProductID; }
/** * Add a product to the cart * @param int $productId * @param int $quantity * @return bool */ public function addProduct($productId, $quantity) { // Set query to get product info $query = "\n SELECT\n *\n FROM\n aca_product\n WHERE\n id = :productId"; // Set variables for insert statement $data = $this->db->fetchRow($query, array('productId' => $productId)); $price = $data['price']; // Insert item into aca_cart_product table try { $this->db->insert('aca_cart_product', array('cart_id' => $this->getCartId(), 'product_id' => $productId, 'price' => $price, 'quantity' => $quantity)); } catch (\Exception $e) { return $e; } }
/** * Create a cart record, and return the id if it doesn't exist * If it does exist, just return the ID * @return int * @throws Exception */ public function getCartId() { // $db = $this->get('acadb'); $user_id = $this->session->get('user_id'); $query = ' select * from aca_cart WHERE user_id = :userId'; $data = $this->db->fetchRow($query, array('userId' => $user_id)); if (empty($user_id)) { throw new Exception('Please login first'); } else { if (empty($data)) { $cartId = $this->db->insert('aca_cart', array('user_id' => $user_id)); } else { $cartId = $data['cart_id']; } $this->session->set('cart_id', $cartId); $this->session->save(); return $cartId; // return $this->getCartId(); } }
/** * Determine if the proposed username is already used * @param string $username * @return bool */ public function registrationIsNew($username) { $query = "\n SELECT\n *\n FROM\n aca_user\n WHERE\n username= :username"; $data = $this->db->fetchRow($query, array('username' => $username)); // Username doesn't exist yet if (count($data) == 0) { return true; } // Username already exists return false; }
/** * Create a cart record, and return the Id, if it doesn't exist * If it does exist, just return the Id * @throws \Exception * @return int */ public function getCartId() { $userId = $this->session->get('user_id'); if (empty($userId)) { throw new \Exception('You must be logged in'); } $query = ' select id from aca_cart where user_id = :userId'; $row = $this->db->fetchRow($query, array('userId' => $userId)); // We have a cart record if (isset($row['id']) && !empty($row)) { return $row['id']; } $this->db->insert('aca_cart', array('user_id' => $userId)); return $this->getCartId(); }
public function getCartId() { //check if user has a cart $userId = $this->session->get('user_id'); if (empty($userId)) { throw new \Exception('You must be logged in'); } $cartId = 'select id from aca_cart WHERE id = ' . $userId; $data = $this->db->fetchRow($cartId); if (empty($data)) { $cartId = $this->db->insert('aca_cart', array('user_id' => $userId)); } else { $cartId = $data['id']; } return $cartId; }
/** * Get an address based on an address ID * @param int $addressId * @return array|null */ public function getAddress($addressId) { $query = ' SELECT * FROM aca_address WHERE id= :addressId'; $data = $this->db->fetchRow($query, array('addressId' => $addressId)); // Address exists if (!empty($data)) { return $data; } return null; }
/** * Get an address based on an address ID * @param int $addressId * @return array|null */ public function getAddress($addressId) { // A request might be given for a null $addressId, which is an invalid MySQL query if (!empty($addressId)) { $query = ' SELECT * FROM aca_address WHERE id= :addressId'; $data = $this->db->fetchRow($query, array('addressId' => $addressId)); // Address exists if (!empty($data)) { return $data; } } return null; }
// // Use Dependencies // use Simplon\Mysql\Mysql as Connection; // MySql Connection use Mailgun\Mailgun; // Mailgun wrapper // // DB connect // $dbcfg = unserialize(DB_CONFIG); $db = new Connection($dbcfg['host'], $dbcfg['user'], $dbcfg['password'], $dbcfg['database'], $dbcfg['fetchMode'], $dbcfg['charset'], array('port' => $dbcfg['port'])); // // Get the newest posted article // $article = $db->fetchRow("\n SELECT \n * \n FROM \n jobarticles\n WHERE \n post_id > 0\n AND \n sent_at IS NULL\n ORDER BY \n date DESC\n LIMIT 1\n"); if (!$article) { echo "no articles to send"; exit; } // // Preparing Article for inserting in article // $letter_template = file_get_contents('letter_template.html'); $content_full = $article['content']; $cut_pos = strpos(strip_tags($content_full), ' ', 330); $content_short = substr(strip_tags($content_full), 0, $cut_pos); $article_url = get_permalink($article['post_id']); $content_short_html = sprintf('<h3>%s</h3><p>%s... <a href="%s">%s</a></p>', $article['title'], $content_short, $article_url, 'Read full article on WorkHomeToday.net'); $content_html = str_replace("%article%", $content_short_html, $letter_template); $content_text = sprintf('%s... Read full article on WorkHomeToday.net: %s', $content_short, $article_url);
// App config require 'config.php'; // // Use Dependencies // use Simplon\Mysql\Mysql as Connection; // MySql Connection // // DB connect // $dbcfg = unserialize(DB_CONFIG); $db = new Connection($dbcfg['host'], $dbcfg['user'], $dbcfg['password'], $dbcfg['database'], $dbcfg['fetchMode'], $dbcfg['charset'], array('port' => $dbcfg['port'])); // // Get the oldest unsent article // $article = $db->fetchRow("\n SELECT \n * \n FROM \n jobarticles\n WHERE \n post_id = 0\n ORDER BY \n date ASC\n LIMIT 1\n"); if (!$article) { echo "no articles to post"; exit; } // // Post this article $post_id = -1; // Setup the author, slug, and title for the post $slug = $article['source_id'] . '_' . slugify($article['title']); $title = $article['title']; // If the page doesn't already exist, then create it if (null == get_page_by_title($article['title'])) { $post_data = ['comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => POST_AUTHOR_ID, 'post_name' => $slug, 'post_title' => $title, 'post_status' => 'publish', 'post_type' => 'post', 'post_content' => $article['content']]; // Set the page ID so that we know the page was created successfully $post_id = wp_insert_post($post_data);