We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20178
    • 82 Posts
    hi, im using simplecart with revolution initially it was really easy to set the whole thing up took no time at all - i can check out using paypal no problem, however im using it slightly differently, more for a grocery list where people can select items and then the client and the user then get an email, the only thing is i cannot get it to send the email checkout.

    i can get it going in a plain html site but cannot get it working in modx revolution. - i assume it’s not commnuicating with the php file but this is beyond my capabilities and now im very stuck.....

    the file email.php which the simplecart js calls is;
    i have tried placing this in both the route and alongside the folde in which the js file resides but to no avail. help desperately needed slowly going made here!

    <?PHP 
    
    $ADMIN_EMAIL 	= "[email protected]"; // Email address that the cart info will be sent to
    $EMAIL_SUBJECT 	= "simpleCart(js) has been submitted";
    
    
    if( !isset($_POST['div']) ){
    	echo "no data provided";
    	return;
    }
    	
    	
    $div = $_POST['div'];
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    // Additional headers
    $headers .= 'To: <' . $ADMIN_EMAIL . ">\r\n";
    $headers .= "From: \"simpleCart(js)\" <[email protected]> \r\n";
    
    $body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
    	\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
    
    <html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-US\">
    
    <head>
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><title>" . $EMAIL_SUBJECT . "</title></head><body>" . $div . "</body></html>";
    $subject = $EMAIL_SUBJECT;
    
    mail( $ADMIN_EMAIL, $subject, $body, $headers);
    
    echo "success!";
    
    ?>
    


    the function that calls the email.php is ;

    me.emailCheckout = function() {
    var div = me.updateCartView( document.createElement("div") );
    div = "<div class=’simpleCart_items’>" + div.innerHTML + "</div>";
    $.post("email.php" , {div:div} , function(data) {
    alert( data );
    });
    };



    • I downloaded simplecart, and there is no mention of any php files. What does your javascript file look like?

      In Revolution, you may want to create a snippet instead of a standalone php file.
        WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
        • 20178
        • 82 Posts
        hi yes you’re right on the simple cart site there is no mention of the email.php file you have to the github page and the email branch;;

        https://github.com/thewojogroup/simplecart-js/tree/email

        this contains all the stuff to do with the email - unfortuneately im no coder - so find delving into code very hard - im trying to quickly learn the basics of php as i know it’s really holding me back with regrards to what i can achieve with modx.

        • Here you go:

          • Post the code below into a snippet called SimpleCart
          • Create a new page in MODx with a BLANK template and the following call: [[!SimpleCart]] OR (with options) [[!SimpleCart? &emailto=`` &emailfrom=`` &subject=`` &successMsg=`` &errorMsg=``]]
          • Change the simpleCart.js file as follows: change line 306 from
            [tt]$.post("email.php" , {div:div} , function(data) {[/tt]
            to
            [tt]$.post("/test-shop.html" , {div:div} , function(data) {[/tt]
            (where "/test-shop.html" is the URL of the MODx document that you just created)

          I tested it and it worked for me, but let me know if you have issues. Default emailto and emailfrom is the MODx emailsender setting.

          The SimpleCart snippet code (paste into a snippet called SimpleCart):
          <?php
          /* SimpleCart email processor */
          /* Call with [[!SimpleCart]] */
          /* Configuration: [[!SimpleCart? &emailto=`` &emailfrom=`` &subject=`` &successMsg=`` &errorMsg=``]] */
          
          $output='';
          
          if( !isset($_POST['div']) ){
            $output = "no data provided";
            return $output;
          }
          
          /* set options */
          $emailto = $modx->getOption('emailto',null,$modx->getOption('emailsender'));
          $emailfrom = $modx->getOption('emailfrom',null,$modx->getOption('emailsender'));
          $subject = $modx->getOption('subject', $scriptProperties, 'simpleCart(js) has been submitted');
          $successMsg = $modx->getOption('successMsg', $scriptProperties, "Success! Message sent: <br /><br />");
          $errorMsg = $modx->getOption('errorMsg', $scriptProperties, 'An error occurred while trying to send the email');
          $message = $_POST['div'];
          
          
          /* send email */
          $modx->getService('mail', 'mail.modPHPMailer');  
          $modx->mail->set(modMail::MAIL_BODY,$message);  
          $modx->mail->set(modMail::MAIL_FROM,$emailfrom);  
          $modx->mail->set(modMail::MAIL_FROM_NAME,$modx->getOption('site_name'));  
          $modx->mail->set(modMail::MAIL_SENDER,$modx->getOption('site_name'));  
          $modx->mail->set(modMail::MAIL_SUBJECT,$subject);  
          $modx->mail->address('to',$emailto);
          $modx->mail->setHTML(true);
          if (!$modx->mail->send()) {
            $modx->log(modX::LOG_LEVEL_ERROR,'[SimpleCart] '.$errorMsg.": ".$err);
            $output = $errorMsg;
          } else {
            $output = $successMsg.htmlspecialchars($message);
          }
          $modx->mail->reset();
          return $output;
          
            WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
            • 20178
            • 82 Posts
            wow thanks oleg great work cant wait to try this in the morning you certainly seem to know your stuff - perhaps you could release this as an add on for the whole modx community to use ? - i know a quick simple cart could come in handy for a lot of people that have clients that just want to sell the odd item.

            You seem to really know your stuff, perhaps you could help with something else however im aware it’s in the wrong topic,

            i want to have a page on a site where the admin can perform searches on the registered fields, so for instance when a user updates their profile they enter various data for instance

            1. do you like chips y / n ?

            2.do you like cake? y /n ?

            3. do you like tea? y /n

            i would like to have a page on the site where the admin only can perform a search with a form and search for users that say;

            like chips and tea but not cake.

            and this would then bring up all those users & their profile data in a tpl

            what and how is the best way to tackle this...

            thanks in advance, t.
              • 20178
              • 82 Posts
              Hi Oleg thanks for the simplecart inegration but i cant get it to work, it’s just displaying no data provided, do you think you could provide an example link to the page you have it running or a zip of the html page you have it running on,

              thanks, t.
              • Don’t go to the page directly. Instead, use the sample HTML file they provided and click "checkout". You can see it in action here:

                http://flamebird.com/assets/components/simplecart-email/

                I didn’t modify the javascript other than to change the PHP file it uses, so it is still doing a simple "alert". If you don’t want all the HTML tags to appear in the alert, just change the following in the SimpleCart snippet: $successMsg.htmlspecialchars($message) to $successMsg.strip_tags($message) or even simple $successMsg.

                Once you have their sample HTML file working, migrate it to a MODx document. If you have problems after you migrate the HTML and JS, send me the link and I can see what you are doing wrong.

                Regarding your other question:

                1. To limit the search form and results to certain users, just use MODx resource groups and give the admin group permissions to view them. See the security tutorials: http://rtfm.modx.com/display/revolution20/Security+Tutorials

                2. Make a search form that uses GET to submit the results in the form of: /?chips=1&cake=1&tea=0.

                3. Then, copy the Peoples snippet into another snippet called PeopleSearch and modify it to filter using the search terms. The easiest way to gather the search term from the URL is to use the getUrlParam snippet: [[!PeopleSearch? &tpl=`pplUser` &cake=`[[!getUrlParam? &name=`cake` &int=`1`]]` &amp;tea=`[[!getUrlParam? &name=`tea` &int=`1`]]`]].

                I don’t have time right now to do a custom PeopleSearch, but here are some pointers:

                • To add a parameter into the PeopleSearch snippet, add $cake = $modx->getOption(’cake’,$scriptProperties, ’’);
                • The extended fields for users are stored in a single database column, so using the usual $c->where(array()) filter is not going to work. Here is a forum post that gives sample code for searching inside of the extended fields: http://modxcms.com/forums/index.php?topic=51494.0

                I haven’t tried this myself, but it may be even easier to just add a filter based on the JSON-storage format of the extended fields. Use phpMyAdmin to verify that your extended fields are in this format, and just add the following andCondition or where filter:

                if (!empty($cake)) {
                  $c->where(array(
                     'extended:LIKE' => '%"cake","'.$cake.'"%',
                  ));
                }
                
                  WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
                • One more thing: if you have trouble with PHP coding in MODx Revolution and don’t understand where the where or andCondition are coming from, check out the xPDO reference, especially the xPDOQuery: http://rtfm.modx.com/display/xPDO20/xPDOQuery. Just change $xpdo-> to $modx-> in the MODx snippets.
                    WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
                    • 20178
                    • 82 Posts
                    hey oleg thanks for all your help so far, im trying to add a photo to the user profile, what i understand it cannot be done in the update profile snippet - and have read in a couple of threads about doing it by once the user logins in and then goes to update their profile having a formit call and uploading the file that way - i have done this and it works fine however im a little stuck with naming the file and the folder.


                    http://modxcms.com/forums/index.php/topic,57256.msg327787.html#msg327787

                    http://modxcms.com/forums/index.php?topic=61227.0

                    in the formit2file resource in the last post of the thread above there is a comment about changing the folder name created on the server - really i would like that folder to be the name of the username and the photo to also be the name of the username+pic so it can be referenced in the user search in previous posts.

                    i have tried using the code below but this doesnt work;


                    $namefile = $modx->getLoginUserID()

                    // create unique path for this form submission
                    $uploadpath = ’assets/uploads/.($namefile)’


                    thanks in advance,