MarketPress inventory

Hi, I use Square for my POS in retail and MarketPress on my website. Basically, using Squares API I would like to manipulate my MarketPress inventory every time a sale is made via Square. I was wondering what the best way to access the MarketPress inventory? Cheers Cam

    Panos

    Hi Cameron ,

    Sorry for such late reply!

    This is a very interesting request but it is not that simple to accomplish. I will try to provide guidance which you can use as your base.

    The goal is to update a product meta fields for inventory and also for soled items in the db. Specifically these meta fields are inventory and mp_sales_count.

    The preferred way is by using the WP REST API but it would require allot of reading to create the appropriate custom routes and endpoints required.

    Instead I could drive you through a different way by using a custom plugin as you basis. Please download custom plugin from: https://github.com/panoslyrakis/wpmudev-remote-mp-inventory

    You can install it as a normal plugin and activate it.

    You can then create a page on your site where you have your MarketPress installation and go to it's page attributes and select the page template MP Remote Inventory and leave the content empty.

    I don't know how you retrieve your information from your payment gateway, but you will need the products ids and the quantity for each.

    So you'll need to create a request ( eg curl or even with ajax ) where you need to provide:

    1. the url of the page you created and uses the MP Remote Inventory template

    2. in the url you will need to include the following query vars:
    username by default you can use wpmudev
    keyby default !rand0mP@5s
    and the products_quantities which will be a json string containing product ids and quantities.

    If you have a different WordPress site you can add the following in your functions.php:

    add_action( 'wp_head', function(){
    
    	$products_qts = array(
    		97 => 2,
    		33 => 4
    	);
    
    	$page_url = 'http://example.com/remote-product-inventory';
    	$username = 'wpmudev';
    	$key = 		'!rand0mP@5s';
    	$products_qts = json_encode( $products_qts );
    
    	$wp_request_url =$page_url . '?username=' . $username . '&key=' . $key . '&products_quantities=' . $products_qts;
    
    	$wp_request_post_response = wp_remote_request(
    	    $wp_request_url,
    	    array(
    	        'method'    => 'GET',
    	    )
    	);
    
    }, 10 );

    You will need to replace the product ids and quantities and replace the url and query strings explained above.

    I would strongly suggest to change the username and key used by modifying plugin file
    wpmudev-remote-mp-inventory/wpmudev-remote-mp-inventory.php
    at lines 38 and 39.

    Hope this helps!

    Cheers!