public static function checkout($customer, $cart_info, $stripeToken)
 {
     $ufstore = UFStore::instance();
     $shipping_info = array();
     //Calculate new costs, all should be in pennies
     $cart_subtotal = UFStoreCart::getCartCost();
     $cart_shipping = $cart_info['shipping_cost'];
     $cart_total = $cart_subtotal + $cart_shipping;
     //!!!Doublecheck our new calculations match the AJAX response
     //Run the amount on stripe
     if (UFStoreCartCheckout::stripePayment($cart_total, $stripeToken)) {
         $cart = UFStoreCart::getCart();
         //Send email confirmation
         ob_start();
         // start output buffer
         include dirname(__FILE__) . '/../templates/email.php';
         $template = ob_get_contents();
         // get contents of buffer
         ob_end_clean();
         UFStoreCartCheckout::sendReceipt($customer['email'], $template);
         UFStoreCartCheckout::saveOrder($customer, $cart_info, $cart, $cart_subtotal, $cart_shipping, $cart_total);
         UFStoreCart::clearCart();
         return array('cart' => $cart, 'customer' => $customer);
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 public static function instance()
 {
     if (!isset(self::$instance)) {
         $className = __CLASS__;
         self::$instance = new $className();
     }
     return self::$instance;
 }
Ejemplo n.º 3
0
 public static function setupCart()
 {
     $ufstore = UFStore::instance();
     parent::$wp_session = WP_Session::get_instance();
     if (!isset(parent::$wp_session['cart'])) {
         parent::$wp_session['cart'] = array();
     }
     parent::$shoppingCart = parent::$wp_session['cart']->toArray();
 }
 public static function getShipping($shipping_to, $country = 'United States')
 {
     $ufstore = UFStore::instance();
     $shipping_info = array();
     //Get ready to calculate for USPS
     $usps_package = array('total_cost' => 0, 'total_weight' => 0);
     $shipping_costs = array('total' => 0, 'flat' => 0, 'flat_us' => 0, 'flat_international' => 0, 'included' => 0, 'groups' => 0, 'usps' => 0);
     $groups = array();
     // Generate an array to loop through
     //Collect each cart's shipping info
     if (UFStoreCart::getCartCount() > 0) {
         foreach (UFStoreCart::getCart() as $product_id => $products) {
             foreach ($products as $product) {
                 array_push($shipping_info, array('id' => $product['unique_id'], 'price' => get_field('base_price', $product_id), 'quantity' => $product['quantity'], 'product_id' => $product_id, 'shipping_type' => get_field('shipping_type', $product_id), 'flat_rate_us' => get_field('flat_rate_us', $product_id), 'flat_rate_international' => get_field('flat_rate_international', $product_id), 'individual_weight' => get_field('product_weight', $product_id), 'total_weight' => $product['quantity'] * get_field('product_weight', $product_id), 'group_cost' => get_field('group_cost', $product_id), 'group_amount_of_product' => get_field('group_amount_of_product', $product_id), 'group_category' => get_field('group_category', $product_id)));
             }
         }
     }
     if (!empty($shipping_info)) {
         //Loop through products
         foreach ($shipping_info as $product) {
             //Total Flat Rates
             if ($product['shipping_type'] == 'flat') {
                 if ($country == 'United States') {
                     $shipping_costs['flat'] += $product['flat_rate_us'];
                     $shipping_costs['flat_us'] += $product['flat_rate_us'];
                 } else {
                     $shipping_costs['flat'] += $product['flat_rate_international'];
                     $shipping_costs['flat_international'] += $product['flat_rate_international'];
                 }
                 //Group products together
             } else {
                 if ($product['shipping_type'] == 'group') {
                     if (!array_key_exists($product['group_category'][0], $groups)) {
                         // echo $product['group_category'][0];
                         $groups[$product['group_category'][0]] = array('cost' => $product['group_cost'], 'max_amount' => $product['group_amount_of_product'], 'actual_amount' => $product['quantity']);
                     } else {
                         $groups[$product['group_category'][0]]['actual_amount'] = $groups[$product['group_category'][0]]['actual_amount'] + $product['quantity'];
                     }
                     //Total USPS Rates
                     //Don't compute this, just tally all values into a single 'package'
                 } else {
                     if ($product['shipping_type'] == 'usps') {
                         $usps_package['total_cost'] += $product['price'] * $product['quantity'];
                         $usps_package['total_weight'] += $product['total_weight'];
                     }
                 }
             }
         }
     }
     foreach ($groups as $group) {
         $shipping_costs['groups'] += (floor($group['actual_amount'] / $group['max_amount']) + 1) * $group['cost'];
         //Charge $6 for every 4 shirts
     }
     $shipping_costs['usps'] = UFStoreShippingUSPS::usps($usps_package, $country, $shipping_to);
     return $shipping_costs;
 }
function ufstoresuccess($atts)
{
    $ufstore = UFStore::instance();
    global $content;
    ob_start();
    $cart = UFStoreCart::getCart();
    $cart_total = UFStoreCart::getCartCost();
    if (file_exists(get_template_directory() . '/ufstore/success.php')) {
        include get_template_directory() . '/ufstore/success.php';
    } else {
        include dirname(__FILE__) . '/../templates/success.php';
    }
    //Empty the shopping cart
    $wp_session['cart'] = array();
    $output = ob_get_clean();
    return $output;
}
function cart_info()
{
    header('Content-Type: application/json');
    $ufstore = UFStore::instance();
    $info = array('cart_count' => UFStoreCart::getCartCount(), 'total_cost' => UFStoreCart::getCartCost());
    echo json_encode(array('cart_info' => $info));
    die;
}
Ejemplo n.º 7
0
<?php

/**
 * Plugin Name: Umbrella Fish Store
 * Plugin URI: http://umbrella-fish.com
 * Description: Super simple store plugin
 * Version: 0.2
 * Author: James Buke
 * Author URI: http://jameswburke.com
 * Network: False
 * License: IDK
 */
defined('ABSPATH') or die("No script kiddies please!");
require_once dirname(__FILE__) . '/lib/uf-store.class.php';
UFStore::instance();
register_activation_hook(__FILE__, array('UFStore', 'ufstore_activated'));