Plugin Directory

Changeset 1842232


Ignore:
Timestamp:
03/18/2018 03:49:11 PM (8 years ago)
Author:
mjfreeway
Message:

in stock filter

Location:
mjfreeway-orders/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mjfreeway-orders/trunk/index.php

    r1730219 r1842232  
    33  Plugin Name: MJFreeway Orders
    44  Description: Creates an order reservation experience using MJ Freeway's API
    5   Version: 1.0.1
     5  Version: 1.0.2
    66  Author: MJ Freeway
    77  Author URI: https://mjfreeway.com
  • mjfreeway-orders/trunk/mjfreeway-plugin.php

    r1730196 r1842232  
    150150    if ( count( $wholeCart ) > 0 ) {
    151151      $ch = curl_init();
    152       curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
     152      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    153153      curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    154154      curl_setopt( $ch, CURLOPT_HTTPHEADER, $this->get_api_headers() );
    155155      curl_setopt( $ch, CURLOPT_URL, MJFREEWAY_API_ROOT . "orders" );
    156156      curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
     157      curl_setopt( $ch, CURLOPT_POST, 1 );
    157158
    158159      $fields = array(
    159160        "order_source" => "online",
    160         "consumer_id"  => $_POST['accountNumber'],  //note:account number is not working on the api...
    161         "order_type"   => "sale"
     161        "consumer_id"  => $_POST['accountNumber'],
     162        "order_type"   => "sale",
    162163      );
    163164
    164165      curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $fields ) );
    165       curl_setopt( $ch, CURLOPT_POST, 1 );
    166 
    167166      $result = curl_exec( $ch );
    168167      $order  = json_decode( $result, true );
     
    170169      $mhResult = $this->multiRequest( $wholeCart, $order );
    171170
     171      if ($_POST['fulfillment_method'] && $_POST['fulfillment_method'] === 'delivery') {
     172        curl_setopt( $ch, CURLOPT_URL, MJFREEWAY_API_ROOT . "orders/" . $order["id"] );
     173        curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT" );
     174        $orderUpdate = array(
     175          "fulfillment_method" => $_POST['fulfillment_method'],
     176          "delivery_address_id" => (int)$_POST["delivery_address_id"],
     177        );
     178        curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $orderUpdate ) );
     179        $result         = curl_exec( $ch );
     180      }
     181
    172182      curl_setopt( $ch, CURLOPT_URL, MJFREEWAY_API_ROOT . "orders/" . $order["id"] . "/submit" );
    173183      curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
    174       curl_setopt( $ch, CURLOPT_POST, 1 );
     184      curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $fields ) );
    175185
    176186      $result         = curl_exec( $ch );
     
    185195  }
    186196
     197  public function get_consumer_info() {
     198
     199    $ch = curl_init();
     200    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
     201    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
     202    curl_setopt( $ch, CURLOPT_HTTPHEADER, $this->get_api_headers() );
     203    curl_setopt( $ch, CURLOPT_URL, MJFREEWAY_API_ROOT . "consumers/" . get_the_author_meta('mjfreeway_customer_id', get_current_user_id()) );
     204    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "GET" );
     205
     206    $result = curl_exec( $ch );
     207    $consumer  = json_decode( $result, true );
     208    return $consumer;
     209  }
     210
    187211  public function add_admin_menu() {
    188     add_options_page( 'MJ Freeway', 'MJ Freeway', 'manage_options', 'mjfreeway', array(
    189       $this,
    190       'options_page'
    191     ) );
     212    add_menu_page( 'MJ Freeway General Settings', 'MJ Freeway', 'manage_options', 'mjfreeway', array($this, 'options_page' ), plugin_dir_url( __FILE__ ).'images/mjf-admin-logo.png');
    192213  }
    193214
    194215  public function product_detail_rewrite_init() {
    195216    add_rewrite_rule(
    196       '^mjfreeway-products/([0-9]*$)/?',
    197       'index.php?pagename=mjfreeway-product-detail&product=$matches[1]',
     217      '^mjfreeway-products/([0-9]+)',
     218      'index.php?pagename=mjfreeway-product-detail',
    198219      'top' );
    199220    flush_rewrite_rules();
     
    247268  }
    248269
     270  public function get_fulfillment() {
     271    return isset( $_COOKIE['mjfreewayfulfillment'] ) ? $_COOKIE['mjfreewayfulfillment'] : 'in_store';
     272  }
     273
    249274  public function get_cart() {
    250275    $cookieCart = $this->get_cookie_cart();
     
    263288      $pricingID         = (int) $cartItem[2];
    264289      $pricing           = 0;
     290      $pricingName       = '';
    265291
    266292      foreach ( $allProducts as $i ) {
     
    271297              if ( $weightPrice["pricing_weight_id"] === $pricingID ) {
    272298                $pricing = $weightPrice["default_price"];
     299                $pricingName = $weightPrice["name"];
    273300              }
    274301            }
     
    276303            $pricing = $i->pricing;
    277304          }
    278           $c = new MJFreeway_CartItem( $name, $quantity, $pricing );
     305          $c = new MJFreeway_CartItem( $name, $quantity, $pricing, $pricingName );
    279306          array_push( $cartItems, $c );
    280307        }
     
    293320
    294321    $ch = curl_init();
    295     curl_setopt( $ch, CURLOPT_URL, MJFREEWAY_API_ROOT . "catalog" );
     322    curl_setopt( $ch, CURLOPT_URL, MJFREEWAY_API_ROOT . "catalog?available_online=1&in_stock=1" );
    296323    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    297324    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "GET" );
     
    309336    $items = json_decode( $result, true );
    310337
    311     function compareByName($a, $b) {
     338    $items = $items ? $items : [];
     339
     340    usort($items, function($a, $b) {
    312341      return strcmp($a['name'], $b['name']);
    313     }
    314     usort($items, 'compareByName');
     342    });
    315343
    316344    foreach ( $items as $item ) {
    317 
    318       $price       = null;
    319       $pricingType = $item["pricing_type"];
    320       if ( $pricingType === 'weight' ) {
    321         $price = $item["pricing"]["weight_prices"];
    322       } else {
    323         $price = $item["pricing"]["default_price"];
    324       }
    325 
    326       $p = new MJFreeway_Product(
    327         $item['id'],
    328         $item['description'] ? $item['description'] : 'No product description.',
    329         $price,
    330         $item["name"],
    331         $item['primary_image_urls'][0]['url'],
    332         new MJFreeway_ProductCategory( $item['category_name'], $item['category_id'] ) );
    333       array_push( $this->allProducts, $p );
     345      if ($item["in_stock"]) {
     346        $price       = null;
     347        $pricingType = $item["pricing_type"];
     348        if ( $pricingType === 'weight' ) {
     349          $price = $item["pricing"]["weight_prices"];
     350        } else {
     351          $price = $item["pricing"]["default_price"];
     352        }
     353
     354        $p = new MJFreeway_Product(
     355          $item['id'],
     356          $item['description'] ? $item['description'] : 'No product description.',
     357          $price,
     358          $item["name"],
     359          $item['primary_image_urls'][0]['url'],
     360          new MJFreeway_ProductCategory( $item['category_name'], $item['category_id'] ) );
     361        array_push( $this->allProducts, $p );
     362      }
    334363    }
    335364
     
    396425      'mjfreeway_display_registration_link'
    397426    ), 'mjfreeway_plugin', 'mjfreeway_main' );
     427    add_settings_field( 'mjfreeway_toggle_delivery', 'Enable delivery features (beta)', array(
     428      $this,
     429      'mjfreeway_toggle_delivery'
     430    ), 'mjfreeway_plugin', 'mjfreeway_main' );
     431    add_settings_field( 'mjfreeway_toggle_express', 'Enable express checkout features', array(
     432      $this,
     433      'mjfreeway_toggle_express'
     434    ), 'mjfreeway_plugin', 'mjfreeway_main' );
    398435  }
    399436
     
    435472  public function mjfreeway_setting_textarea() {
    436473    $options = get_option( 'mjfreeway_options' );
    437     echo "<textarea id='mjfreeway_css_string' name='mjfreeway_options[css_string]' rows='8' cols='40'>{$options['css_string']}</textarea><p>Applied site-wide. Use .mjfreeway as the parent selector.</p>";
     474    echo "<textarea id='mjfreeway_css_string' name='mjfreeway_options[css_string]' rows='8' cols='40'>{$options['css_string']}</textarea><p>Applied site-wide. Use .mjfreeway as the parent selector to target plugin elements.</p>";
    438475  }
    439476
     
    452489    echo "<input type='checkbox' id='mjfreeway_display_registration_link' name='mjfreeway_options[mjfreeway_display_registration_link]' value='1'";
    453490    checked( $options['mjfreeway_display_registration_link'] );
     491    echo " />";
     492  }
     493  public function mjfreeway_toggle_delivery() {
     494    $options = get_option( 'mjfreeway_options' );
     495    echo "<input type='checkbox' id='mjfreeway_toggle_delivery' name='mjfreeway_options[mjfreeway_toggle_delivery]' value='1'";
     496    checked( $options['mjfreeway_toggle_delivery'] );
     497    echo " />";
     498  }
     499  public function mjfreeway_toggle_express() {
     500    $options = get_option( 'mjfreeway_options' );
     501    echo "<input type='checkbox' id='mjfreeway_toggle_express' name='mjfreeway_options[mjfreeway_toggle_express]' value='1'";
     502    checked( $options['mjfreeway_toggle_express'] );
    454503    echo " />";
    455504  }
  • mjfreeway-orders/trunk/readme.txt

    r1730221 r1842232  
    22Contributors: mjfreeway, skylarq
    33Requires at least: 4.7
    4 Tested up to: 4.8.1
     4Tested up to: 4.9.2
    55Requires PHP: 5.3
    6 Stable tag: 1.0.1
     6Stable Tag: 1.0.2
    77
    88This plugin creates a shopping cart experience for MJ Freeway customers using MJ Freeway's API.
     
    2626Under Settings->MJ Freeway, place additional text in the `Confirmation Message` textarea. This text appears on the confirmation screen after a successful order is placed.
    2727
    28 = Where can I put additional instructions for logged in users without an MJ Freeway Customer ID? =
     28= Where can I put additional instructions for successful orders? =
    2929
    3030Under Settings->MJ Freeway, place additional text in the `Unverified User Message` textarea. This text appears on the product detail page when a user is signed in but the user profile does not have an MJ Freeway Customer ID.
     
    4343
    4444== Changelog ==
     45= 1.02 =
     46* Added in-stock filter
     47= 1.01 =
     48* Unverified user message content managed
     49* Improved admin labels
    4550= 1.0 =
    4651* Initial rollout
Note: See TracChangeset for help on using the changeset viewer.