We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Development Questions, working with Simple Commerce

Development and Programming

Jacob Russell's avatar
Jacob Russell
17 posts
15 years ago
Jacob Russell's avatar Jacob Russell

I’m working on an extension that will update the status of an entry on completion of a simple commerce order. I understand using the DB class to update the status of my entry, and how to hook my extension to simple_commerce_perform_actions_end, which is where I want this to happen, but I still have one problem:

The entry I want to update is not the simple commerce item. My simple commerce product is a ‘30 day listing’ that, when purchased, should update the status of an entry in a different weblog to Open rather then Pending. The simple commerce buy loop is on an individual entry page with the weblog entry I want to change the status on, so I have access to both the entry id and a separate custom field that contains another unique identifier I created for another purpose.

My question is: how do I pass that data into simple commerce so I have access to it in my extension? I’m not sure if I can populate a custom field in the simple commerce order or attach it to the POST data somehow, but I know there has to be some way.

       
Low's avatar
Low
407 posts
15 years ago
Low's avatar Low
My question is: how do I pass that data into simple commerce so I have access to it in my extension? I’m not sure if I can populate a custom field in the simple commerce order or attach it to the POST data somehow, but I know there has to be some way.

It’s not you who needs to pass the data, it’s PayPal. PP is sending the POST request to your site with – I think – a fixed number of variables. If you need PP to send you more info based on the page where the original request came from (the page with the Buy Now link), then you need to send that data to PP first. If that’s possible at all; it’s not mentioned in the docs.

I’d check out if it is possible to send more data to PP than normal first. If it’s not, you might have to rethink your strategy.

       
Jacob Russell's avatar
Jacob Russell
17 posts
15 years ago
Jacob Russell's avatar Jacob Russell

I’ve gotten it into paypal, thanks for that Low. I’m passing it (currently) as both the item number and as a custom variable, I’ll verify later if that second method works. The question is how do I look at the POST I’m getting back from Paypal?

       
Jacob Russell's avatar
Jacob Russell
17 posts
15 years ago
Jacob Russell's avatar Jacob Russell

Alright, so I’ve got another problem. My extension isn’t doing it’s thing at all. I’ve taken most of the code from the sample extension in the docs, with a little more taken from the Paid Members extension (it uses the hook I’m using). All it does is take in a variable from Post and run a MySQL update based on that, the problem is that doesn’t happen. It doesn’t even work when I remove the post part and manually put a number in place of $entryID. The query is good, I can run it directly in phpmyadmin without trouble, so I think I’m missing something about the extension itself, I just have no idea what. If someone could give this a once-over and tell me if it looks like I’m missing anything, I would appreciate it. The entirety of the extensions code is included below:

<?php
/*-------------------------------------------------------------
    Simple Commerce Status
        Changes the status on an entry on completion of a
        Simple Commerce order.
    
    Jacob Russell
    http://www.jacobrussell.net
    March 2010
-------------------------------------------------------------*/

class Simple_commerce_status
{
    var $settings        = array();

    var $name      =  'Simple Commerce Status';
    var $version    =  '0.1';
    var $description  =  'Extension for the Simple Commerce Module that changes the status of an entry.';
    var $settings_exist  =  'n';
    var $docs_url    =  'http://www.jacobrussell.net';
    
    // -------------------------------
    //   Constructor - Extensions use this for settings
    // -------------------------------
    
    function Simple_commerce_status($settings='')
    {
        $this->__construct($settings);
    }
    // END
    
    // --------------------------------
    //  PHP 5 Constructor
    // --------------------------------
      function __construct($settings='')
      {
          $this->settings = $settings;
      }
    // END
    
    // --------------------------------
    //  Activate Extension
    // --------------------------------

    function activate_extension()
    {
        global $DB;
        
        $DB->query($DB->insert_string('exp_extensions',
            array(
                'extension_id' => '',
                'class'        => "Simple_commerce_status",
                'method'       => "change_status",
                'hook'         => "simple_commerce_perform_actions_end",
                'settings'     => "",
                'priority'     => 10,
                'version'      => $this->version,
                'enabled'      => "y"
            )
        ));
    }
    // END
    
    // --------------------------------
    //  Update Extension
    // --------------------------------  

    function update_extension($current='')
    {
        global $DB;
        
        if ($current == '' OR $current == $this->version)
        {
            return FALSE;
        }
        
        $DB->query("UPDATE exp_extensions 
                    SET version = '".$DB->escape_str($this->version)."' 
                    WHERE class = 'Simple_commerce_status'");
    }
    // END
    
    // --------------------------------
    //  Change Status
    // --------------------------------
    function change_status()
    {
        global $DB;
        
        $entryID = $_POST['item_number']; //Entry ID of the listing we want to change.
        
        $DB->query("UPDATE exp_weblog_titles 
                    SET status='open'
                    WHERE entry_id='".$entryID."'");

    }
    // END

}
// END CLASS




?>
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.