Example #1
0
function fflcommerce_product_list($attributes)
{
    $options = FFLCommerce_Base::get_options();
    $attributes = shortcode_atts(array('number' => $options->get('fflcommerce_catalog_per_page'), 'order_by' => 'date', 'order' => 'desc', 'orientation' => 'rows', 'taxonomy' => 'product_cat', 'terms' => '', 'thumbnails' => 'show', 'sku' => 'hide'), $attributes);
    $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $attributes['number'], 'orderby' => $attributes['order_by'], 'order' => $attributes['order'], 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
    if (!empty($attributes['taxonomy']) && !empty($attributes['terms'])) {
        $args['tax_query'] = array(array('taxonomy' => $attributes['taxonomy'], 'terms' => $attributes['terms'], 'field' => 'slug'));
    }
    $query = new WP_Query($args);
    remove_action('fflcommerce_before_shop_loop_item_title', 'fflcommerce_template_loop_product_thumbnail', 10);
    if ($attributes['thumbnails'] === 'show') {
        add_action('fflcommerce_before_shop_loop_item', 'fflcommerce_product_thumbnail', 10, 2);
    }
    if ($attributes['sku'] === 'show') {
        add_action('fflcommerce_after_shop_loop_item_title', 'fflcommerce_product_sku', 9, 2);
    }
    $result = fflcommerce_render_result('shortcode/product_list', array('orientation' => $attributes['orientation'], 'products' => $query->get_posts(), 'has_thumbnails' => $attributes['thumbnails'] === 'show'));
    if ($attributes['sku'] === 'show') {
        remove_action('fflcommerce_after_shop_loop_item_title', 'fflcommerce_product_sku', 9);
    }
    if ($attributes['thumbnails'] === 'show') {
        remove_action('fflcommerce_before_shop_loop_item', 'fflcommerce_product_thumbnail', 10);
    }
    add_action('fflcommerce_before_shop_loop_item_title', 'fflcommerce_template_loop_product_thumbnail', 10, 2);
    return $result;
}
Example #2
0
 /**
  * Generate the paypal button link
  *
  * @param int $order_id
  * @return string
  */
 public function generate_paypal_form($order_id)
 {
     $order = new fflcommerce_order($order_id);
     if ($this->testmode == 'yes') {
         $url = $this->testurl . '?test_ipn=1&';
     } else {
         $url = $this->liveurl . '?';
     }
     if (in_array($order->billing_country, array('US', 'CA'))) {
         $order->billing_phone = str_replace(array('(', '-', ' ', ')'), '', $order->billing_phone);
         $phone_args = array('night_phone_a' => substr($order->billing_phone, 0, 3), 'night_phone_b' => substr($order->billing_phone, 3, 3), 'night_phone_c' => substr($order->billing_phone, 6, 4), 'day_phone_a' => substr($order->billing_phone, 0, 3), 'day_phone_b' => substr($order->billing_phone, 3, 3), 'day_phone_c' => substr($order->billing_phone, 6, 4));
     } else {
         $phone_args = array('night_phone_b' => $order->billing_phone, 'day_phone_b' => $order->billing_phone);
     }
     // filter redirect page
     $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks'));
     $paypal_args = array_merge(array('cmd' => '_cart', 'business' => $this->testmode == 'yes' ? $this->testemail : $this->email, 'no_note' => 1, 'currency_code' => FFLCommerce_Base::get_options()->get('fflcommerce_currency'), 'charset' => 'UTF-8', 'rm' => 2, 'upload' => 1, 'return' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect))), 'cancel_return' => $order->get_cancel_order_url(), 'custom' => $order_id, 'notify_url' => $this->notify_url, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zip' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'invoice' => $order->get_order_number(), 'amount' => number_format((double) $order->order_total, $this->decimals), 'bn' => 'FFLCommerce_SP'), $phone_args);
     if ($this->send_shipping == 'yes') {
         $paypal_args['no_shipping'] = 1;
         $paypal_args['address_override'] = 1;
         $paypal_args['first_name'] = $order->shipping_first_name;
         $paypal_args['last_name'] = $order->shipping_last_name;
         $paypal_args['address1'] = $order->shipping_address_1;
         $paypal_args['address2'] = $order->shipping_address_2;
         $paypal_args['city'] = $order->shipping_city;
         $paypal_args['state'] = $order->shipping_state;
         $paypal_args['zip'] = $order->shipping_postcode;
         $paypal_args['country'] = $order->shipping_country;
         // PayPal counts Puerto Rico as a US Territory, won't allow payment without it
         if ($paypal_args['country'] == 'PR') {
             $paypal_args['country'] = 'US';
             $paypal_args['state'] = 'PR';
         }
     } else {
         $paypal_args['no_shipping'] = 1;
         $paypal_args['address_override'] = 0;
     }
     // If prices include tax, send the whole order as a single item
     if (FFLCommerce_Base::get_options()->get('fflcommerce_prices_include_tax') == 'yes') {
         // Discount
         $paypal_args['discount_amount_cart'] = number_format((double) $order->order_discount, $this->decimals);
         // Don't pass items - PayPal breaks tax due to catalog prices include tax.
         // PayPal has no option for tax inclusive pricing.
         // Pass 1 item for the order items overall
         $item_names = array();
         foreach ($order->items as $item) {
             $_product = $order->get_product_from_item($item);
             $title = $_product->get_title();
             //if variation, insert variation details into product title
             if ($_product instanceof fflcommerce_product_variation) {
                 $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')';
             }
             $item_names[] = $title . ' x ' . $item['qty'];
         }
         $paypal_args['item_name_1'] = sprintf(__('Order %s', 'fflcommerce'), $order->get_order_number()) . ' - ' . implode(', ', $item_names);
         $paypal_args['quantity_1'] = 1;
         $paypal_args['amount_1'] = number_format($order->order_total - $order->order_shipping - $order->order_shipping_tax + $order->order_discount, $this->decimals, '.', '');
         if ($order->order_shipping + $order->order_shipping_tax > 0) {
             $paypal_args['item_name_2'] = __('Shipping cost', 'fflcommerce');
             $paypal_args['quantity_2'] = '1';
             $paypal_args['amount_2'] = number_format($order->order_shipping + $order->order_shipping_tax, $this->decimals, '.', '');
         }
     } else {
         // Cart Contents
         $item_loop = 0;
         foreach ($order->items as $item) {
             $_product = $order->get_product_from_item($item);
             if ($_product->exists() && $item['qty']) {
                 $item_loop++;
                 $title = $_product->get_title();
                 //if variation, insert variation details into product title
                 if ($_product instanceof fflcommerce_product_variation) {
                     $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')';
                 }
                 $paypal_args['item_name_' . $item_loop] = $title;
                 $paypal_args['quantity_' . $item_loop] = $item['qty'];
                 $paypal_args['amount_' . $item_loop] = number_format(apply_filters('fflcommerce_paypal_adjust_item_price', $item['cost'], $item, 10, 2), $this->decimals);
                 //Apparently, Paypal did not like "28.4525" as the amount. Changing that to "28.45" fixed the issue.
             }
         }
         // Shipping Cost
         if (fflcommerce_shipping::is_enabled() && $order->order_shipping > 0) {
             $item_loop++;
             $paypal_args['item_name_' . $item_loop] = __('Shipping cost', 'fflcommerce');
             $paypal_args['quantity_' . $item_loop] = '1';
             $paypal_args['amount_' . $item_loop] = number_format((double) $order->order_shipping, $this->decimals);
         }
         $paypal_args['tax'] = $order->get_total_tax(false, false);
         // no currency sign or pricing options for separators
         $paypal_args['tax_cart'] = $order->get_total_tax(false, false);
         // no currency sign or pricing options for separators
         $paypal_args['discount_amount_cart'] = $order->order_discount;
         if ($this->force_payment == 'yes') {
             $sum = 0;
             for ($i = 1; $i < $item_loop; $i++) {
                 $sum += $paypal_args['amount_' . $i];
             }
             $item_loop++;
             if ($sum == 0 || $order->order_discount && $sum - $order->order_discount == 0) {
                 $paypal_args['item_name_' . $item_loop] = __('Force payment on free', 'fflcommerce');
                 $paypal_args['quantity_' . $item_loop] = '1';
                 $paypal_args['amount_' . $item_loop] = 0.01;
                 // force payment
             }
         }
     }
     $paypal_args = apply_filters('fflcommerce_paypal_args', $paypal_args);
     return fflcommerce_render_result('gateways/paypal', array('url' => $url, 'fields' => $paypal_args));
 }
Example #3
0
 /**
  * Generates WorldPay form and redirects to WordPay with Order information
  */
 public function display_worldpay_redirect_form($order_id)
 {
     $order = new fflcommerce_order($order_id);
     if ($this->testmode == 'yes') {
         $worldpay_url = "https://secure-test.worldpay.com/wcc/purchase";
         $testmode = (int) 100;
     } else {
         $worldpay_url = "https://secure.worldpay.com/wcc/purchase";
         $testmode = (int) 0;
     }
     $order_total = number_format($order->order_total, 2, '.', '');
     $worldpay_args = array('instId' => $this->installation_id, 'cartId' => $order_id, 'amount' => $order_total, 'currency' => $this->currency, 'testMode' => $testmode, 'email' => $order->billing_email, 'MC_invoice' => $order->order_key);
     // Send 'canned' name if testmode or full name if not testmode.
     if ($this->testmode == 'yes') {
         $worldpay_args['name'] = 'AUTHORISED';
     } else {
         $worldpay_args['name'] = $order->billing_first_name . ' ' . $order->billing_last_name;
     }
     // Address info
     $worldpay_args['address1'] = $order->billing_address_1;
     $worldpay_args['address2'] = $order->billing_address_2;
     $worldpay_args['town'] = $order->billing_city;
     $worldpay_args['region'] = $order->billing_state;
     $worldpay_args['postcode'] = $order->billing_postcode;
     $worldpay_args['country'] = $order->billing_country;
     $worldpay_args['fixContact'] = '';
     /* no address editing */
     // Setup the Dymanic URL properties using FFL Commerce Request API
     $worldpay_args['MC_callback'] = $this->notify_url;
     $worldpay_args['MC_cancel_return'] = $order->get_cancel_order_url();
     // Cart Contents - Generate cart description
     $desc = '';
     if (sizeof($order->items) > 0) {
         foreach ($order->items as $item) {
             $_product = $order->get_product_from_item($item);
             if ($_product->exists() && $item['qty']) {
                 $title = $_product->get_title();
                 // if variation, insert variation details into product title
                 if ($_product instanceof fflcommerce_product_variation) {
                     $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')';
                 }
                 $desc .= $item['qty'] . ' x ' . $title . '<br/>';
             }
         }
         // Add the description
         $worldpay_args['desc'] = $desc;
     }
     if ($this->fixed_currency == 'yes') {
         $worldpay_args['hideCurrency'] = '';
     }
     // MD5 hash the main parameters we are sending to WorldPay
     if ($this->md5_encrypt == 'yes' && !empty($this->secret_word)) {
         // Add the fields you are hashing
         $hash_fields = 'instId:cartId:amount:currency';
         $worldpay_args['signatureFields'] = $hash_fields;
         // Add the hash signature
         $hash_message = $this->secret_word . ':' . $this->installation_id . ':' . $order_id . ':' . $order_total . ':' . $this->currency;
         $worldpay_args['signature'] = md5($hash_message);
     }
     $worldpay_form_array = array();
     foreach ($worldpay_args as $key => $value) {
         if ($key == 'hideCurrency') {
             $worldpay_form_array[] = '<input type="hidden" name="' . $key . '" />';
             continue;
         }
         if ($key == 'fixContact') {
             $worldpay_form_array[] = '<input type="hidden" name="' . $key . '" />';
             continue;
         }
         $worldpay_form_array[] = '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
     }
     return fflcommerce_render_result('gateways/worldpay', array('url' => $worldpay_url, 'fields' => $worldpay_args));
 }