示例#1
0
 /**
  * Place order and clear cart
  * @throws \Simplon\Mysql\MysqlException
  */
 public function placeOrder($billingStreet, $billingCity, $billingState, $billingZip, $shippingStreet, $shippingCity, $shippingState, $shippingZip, $email)
 {
     $query = '
         SELECT
           *
         FROM
           aca_cart_product
         WHERE
           cart_id= :cartId';
     // Get all user orders that are in the cart
     $data = $this->cart->getCart();
     // If there are products in the order
     if (!empty($data)) {
         // Add order to order table
         $orderId = $this->db->insert('aca_order', array('user_id' => $this->session->get('user_id'), 'billing_street' => $billingStreet, 'billing_city' => $billingCity, 'billing_state' => $billingState, 'billing_zip' => $billingZip, 'shipping_street' => $shippingStreet, 'shipping_city' => $shippingCity, 'shipping_state' => $shippingState, 'shipping_zip' => $shippingZip, 'email' => $email));
         // Iterate through products and add to order product table
         foreach ($data as $product) {
             $this->db->insert('aca_order_product', array('order_id' => $orderId, 'product_id' => $product['cp_product_id'], 'quantity' => $product['cp_quantity'], 'price' => $product['cp_price']));
         }
         // Delete order from cart
         $this->cart->removeCart();
         // Add orderId to session
         $this->session->set('order_id', $orderId);
     }
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * Place an order
  * @return void
  * @todo: lets send a receipt email here
  */
 public function placeOrder()
 {
     $cartProducts = $this->cart->getAllCartProducts();
     $orderId = $this->createOrderRecord();
     foreach ($cartProducts as $cartProduct) {
         $this->db->insert('aca_order_product', array('order_id' => $orderId, 'product_id' => $cartProduct['product_id'], 'quantity' => $cartProduct['qty'], 'price' => $cartProduct['price']));
     }
     // Clear the existing cart
     $this->cart->nixCart();
     $this->session->set('completed_order_id', $orderId);
 }
示例#4
0
 /**
  * Place an order
  * @return void
  */
 public function placeOrder()
 {
     $orderProducts = $this->cart->getAllCartProducts();
     $orderId = $this->createOrderRecord();
     //$orderId = $this->cart->getCartId();
     //use aca_order_product and aca_order tables in DB
     foreach ($orderProducts as $orderProduct) {
         $this->db->insert('aca_order_product', array('order_id' => $orderId, 'product_id' => $orderProduct['product_id'], 'quantity' => $orderProduct['qty'], 'price' => $orderProduct['unit_price']));
     }
     $this->cart->nixCart();
     $this->session->set('completed_order_id', $orderId);
     $this->session->save();
 }
示例#5
0
 /**
  * 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;
     }
 }
示例#6
0
 /**
  * Determine if a new proposed user profile can be created, provide status message, and if info is valid create new user
  * @param $username
  * @param $password
  * @param $passwordCheck
  * @param $name
  * @return null|string
  * @throws \Simplon\Mysql\MysqlException
  */
 public function checkRegistration($username, $password, $passwordCheck, $name)
 {
     $msg = null;
     // If some fields are left empty tell user
     if (empty($username) || empty($password) || empty($passwordCheck) || empty($name)) {
         $msg = 'Please make sure you have entered information in all fields';
         // Prevent MySQL injection - if anything uses illegal characters, tell user
     } else {
         if (!preg_match("#^[a-zA-Z0-9]+\$#", $username) || !preg_match("#^[a-zA-Z0-9]+\$#", $password) || !preg_match("#^[a-zA-Z0-9]+\$#", $passwordCheck) || !preg_match("#^[a-zA-Z0-9]+\$#", $name)) {
             $msg = 'Make sure everything contains only numbers and letters';
             // Now that we know there is no MySQL injection, query DB to make sure login doesn't already exist
         } else {
             if (!$this->registrationIsNew($username)) {
                 $msg = 'That username already exists - please try another';
                 // Login does not exist but password was entered improperly
             } else {
                 if ($password != $passwordCheck) {
                     $msg = 'Please make sure you properly entered your password in both fields';
                     // Login does not exist and password was entered properly
                 } else {
                     // Create new user
                     $userId = $this->db->insert('aca_user', array('name' => $name, 'username' => $username, 'password' => $password));
                     // Set render array variable now that user credentials have been created
                     $loggedIn = true;
                     // Set and save session values
                     $this->setSession($loggedIn, $name, $username, $password, $userId);
                 }
             }
         }
     }
     return $msg;
 }
示例#7
0
 /**
  * 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();
     }
 }
示例#8
0
 /**
  * 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();
 }
示例#9
0
 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;
 }
示例#10
0
 /**
  * Add billing address to user profile
  * @param string $street
  * @param string $city
  * @param string $state
  * @param int $zip
  * @throws \Simplon\Mysql\MysqlException
  */
 public function setBillingAddress($street, $city, $state, $zip)
 {
     // Get original billing address id so that if we update the address, we can check for if the address is still being used elsewhere after updating
     $data = $this->getUserInfo();
     $originalAddressId = $data['billing_address_id'];
     // If billing address already exists, pair user id to it
     if ($addressId = $this->getAddressId($street, $city, $state, $zip)) {
         $this->db->update('aca_user', array('id' => $this->session->get('user_id')), array('billing_address_id' => $addressId));
         // If billing address doesn't already exist add it to database then pair user ID to it
     } else {
         // Insert statement returns id of newly-inserted row
         $addressId = $this->db->insert('aca_address', array('street' => $street, 'city' => $city, 'state' => $state, 'zip' => $zip));
         $this->db->update('aca_user', array('id' => $this->session->get('user_id')), array('billing_address_id' => $addressId));
     }
     // Now that address has been updated, make sure original address isn't used elsewhere. If it isn't remove it from database
     $this->checkIfAddressUsed($originalAddressId);
 }
    $fetched = 0;
    foreach ($feed->items as $item) {
        // log the date
        echo date(' -Y-m-d H:i:s- ');
        $data = array('uid' => $item->id, 'title' => $item->title, 'source_id' => $source_id, 'url' => $item->url, 'date' => $item->date->format('c'), 'content' => $item->content, 'post_id' => 0, 'fetched_at' => date('Y-m-d H:i:s'), 'featured_img' => '');
        // Skip already added articles
        if (strtotime($data['date']) <= strtotime($latest_date)) {
            continue;
        }
        //
        // Filtering article content
        //
        $filtered = filter_article($data['content'], $data['source_id']);
        $data['content'] = $filtered['content'];
        $data['featured_img'] = $filtered['featured_img'];
        echo "Filtered... OK. ";
        //
        // Insert in database
        //
        $id = $db->insert('jobarticles', $data);
        $fetched += 1;
        // log
        echo sprintf("Added %d<br>", $id);
    }
    // Done. Final log
    if ($fetched) {
        echo sprintf("<br>New %d articles fetched<br>", $fetched);
    } else {
        echo "<br>No new articles to fetch</br>";
    }
}