Changeset 1842232
- Timestamp:
- 03/18/2018 03:49:11 PM (8 years ago)
- Location:
- mjfreeway-orders/trunk
- Files:
-
- 3 edited
-
index.php (modified) (1 diff)
-
mjfreeway-plugin.php (modified) (12 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mjfreeway-orders/trunk/index.php
r1730219 r1842232 3 3 Plugin Name: MJFreeway Orders 4 4 Description: Creates an order reservation experience using MJ Freeway's API 5 Version: 1.0. 15 Version: 1.0.2 6 6 Author: MJ Freeway 7 7 Author URI: https://mjfreeway.com -
mjfreeway-orders/trunk/mjfreeway-plugin.php
r1730196 r1842232 150 150 if ( count( $wholeCart ) > 0 ) { 151 151 $ch = curl_init(); 152 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);152 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); 153 153 curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); 154 154 curl_setopt( $ch, CURLOPT_HTTPHEADER, $this->get_api_headers() ); 155 155 curl_setopt( $ch, CURLOPT_URL, MJFREEWAY_API_ROOT . "orders" ); 156 156 curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" ); 157 curl_setopt( $ch, CURLOPT_POST, 1 ); 157 158 158 159 $fields = array( 159 160 "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", 162 163 ); 163 164 164 165 curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $fields ) ); 165 curl_setopt( $ch, CURLOPT_POST, 1 );166 167 166 $result = curl_exec( $ch ); 168 167 $order = json_decode( $result, true ); … … 170 169 $mhResult = $this->multiRequest( $wholeCart, $order ); 171 170 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 172 182 curl_setopt( $ch, CURLOPT_URL, MJFREEWAY_API_ROOT . "orders/" . $order["id"] . "/submit" ); 173 183 curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" ); 174 curl_setopt( $ch, CURLOPT_POST , 1);184 curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $fields ) ); 175 185 176 186 $result = curl_exec( $ch ); … … 185 195 } 186 196 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 187 211 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'); 192 213 } 193 214 194 215 public function product_detail_rewrite_init() { 195 216 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', 198 219 'top' ); 199 220 flush_rewrite_rules(); … … 247 268 } 248 269 270 public function get_fulfillment() { 271 return isset( $_COOKIE['mjfreewayfulfillment'] ) ? $_COOKIE['mjfreewayfulfillment'] : 'in_store'; 272 } 273 249 274 public function get_cart() { 250 275 $cookieCart = $this->get_cookie_cart(); … … 263 288 $pricingID = (int) $cartItem[2]; 264 289 $pricing = 0; 290 $pricingName = ''; 265 291 266 292 foreach ( $allProducts as $i ) { … … 271 297 if ( $weightPrice["pricing_weight_id"] === $pricingID ) { 272 298 $pricing = $weightPrice["default_price"]; 299 $pricingName = $weightPrice["name"]; 273 300 } 274 301 } … … 276 303 $pricing = $i->pricing; 277 304 } 278 $c = new MJFreeway_CartItem( $name, $quantity, $pricing );305 $c = new MJFreeway_CartItem( $name, $quantity, $pricing, $pricingName ); 279 306 array_push( $cartItems, $c ); 280 307 } … … 293 320 294 321 $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" ); 296 323 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); 297 324 curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "GET" ); … … 309 336 $items = json_decode( $result, true ); 310 337 311 function compareByName($a, $b) { 338 $items = $items ? $items : []; 339 340 usort($items, function($a, $b) { 312 341 return strcmp($a['name'], $b['name']); 313 } 314 usort($items, 'compareByName'); 342 }); 315 343 316 344 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 } 334 363 } 335 364 … … 396 425 'mjfreeway_display_registration_link' 397 426 ), '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' ); 398 435 } 399 436 … … 435 472 public function mjfreeway_setting_textarea() { 436 473 $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>"; 438 475 } 439 476 … … 452 489 echo "<input type='checkbox' id='mjfreeway_display_registration_link' name='mjfreeway_options[mjfreeway_display_registration_link]' value='1'"; 453 490 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'] ); 454 503 echo " />"; 455 504 } -
mjfreeway-orders/trunk/readme.txt
r1730221 r1842232 2 2 Contributors: mjfreeway, skylarq 3 3 Requires at least: 4.7 4 Tested up to: 4. 8.14 Tested up to: 4.9.2 5 5 Requires PHP: 5.3 6 Stable tag: 1.0.16 Stable Tag: 1.0.2 7 7 8 8 This plugin creates a shopping cart experience for MJ Freeway customers using MJ Freeway's API. … … 26 26 Under Settings->MJ Freeway, place additional text in the `Confirmation Message` textarea. This text appears on the confirmation screen after a successful order is placed. 27 27 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? = 29 29 30 30 Under 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. … … 43 43 44 44 == Changelog == 45 = 1.02 = 46 * Added in-stock filter 47 = 1.01 = 48 * Unverified user message content managed 49 * Improved admin labels 45 50 = 1.0 = 46 51 * Initial rollout
Note: See TracChangeset
for help on using the changeset viewer.