We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31211
    • 25 Posts
    I tryed to integrate nopcart modx - nopcart is a free JavaScript shopping cart.

    I was able to put it to work fine (create products with TV´s, add , delete, send confirmation email to the buyer and seller, etc - I removed shipping and taxes for simplicity), the structure I did is kind of similar to shopX: each product would be in a page, but I think it can be configured in more creative ways.

    In the end I got 2 issues that i couldn’t solve.
    I would like some opinions or help fixing them :

    - I dont know how to create and put to work the payment processors. (ex. paypal, credit card, special email with instructions to peopl who pays with money orders, personal checks or tranfers - much as I couldnt in shopX)

    - And i dont know how to make the script write the data  it usualy writes to a .csv file into the modx database so it can be retrieved and shown in an internal modx page with ditto or something else.

    I´ll attached the files if someone thinks this  is something interesting to look at, I made a draft readme.txt about how I set it up.

    The chunks, snippet and .js file I  used are attached, if someone would like to test them and give me some help would be nice.

    Regards.
      • 7923
      • 4,213 Posts
      Thanks alot for contributing! It’s great to have more solutions for e-commerce sites, so thanks again! smiley About your issues..

      Quote from: Vadko at Dec 28, 2006, 02:16 PM

      - I dont know how to create and put to work the payment processors. (ex. paypal, credit card, special email with instructions to peopl who pays with money orders, personal checks or tranfers - much as I couldnt in shopX)
      Could you elaborate little bit more on the problems you are having? Do you have some code that is not working or is the problem in writing the code in the first place?
      Quote from: Vadko at Dec 28, 2006, 02:16 PM

      - And i dont know how to make the script write the data it usualy writes to a .csv file into the modx database so it can be retrieved and shown in an internal modx page with ditto or something else.
      You mean that you want the orders to be saved in the database, right? You just need to change that checkout snippet to save the orders as new documents in MODx db. You could use Docmanager for example to create the new documents from the post data. You could make a template for the order documents to have TV’s for the user detail fields and then get the values from POST data in checkout and save to the TV’s.. Then you can use Ditto to list the orders.


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 31211
        • 25 Posts
        Quote from: doze at Dec 30, 2006, 01:46 PM

        Could you elaborate little bit more on the problems you are having? Do you have some code that is not working or is the problem in writing the code in the first place?

        My problem is writing the code in the first place...

        Quote from: doze at Dec 30, 2006, 01:46 PM

        You mean that you want the orders to be saved in the database, right? You just need to change that checkout snippet to save the orders as new documents in MODx db. You could use Docmanager for example to create the new documents from the post data. You could make a template for the order documents to have TV’s for the user detail fields and then get the values from POST data in checkout and save to the TV’s.. Then you can use Ditto to list the orders.

        I got the theory, lets see if i can do it...
          • 31211
          • 25 Posts
          Quote from: Vadko at Jan 01, 2007, 07:49 PM

          Quote from: doze at Dec 30, 2006, 01:46 PM

          Could you elaborate little bit more on the problems you are having? Do you have some code that is not working or is the problem in writing the code in the first place?

          My problem is writing the code in the first place...

          Quote from: doze at Dec 30, 2006, 01:46 PM

          You mean that you want the orders to be saved in the database, right? You just need to change that checkout snippet to save the orders as new documents in MODx db. You could use Docmanager for example to create the new documents from the post data. You could make a template for the order documents to have TV’s for the user detail fields and then get the values from POST data in checkout and save to the TV’s.. Then you can use Ditto to list the orders.

          I got the theory, lets see if i can do it...

          I´ve managed the PayPal issue, and I’ll post it later.

          For now I only have the insert the data that is going to the .csv file into the modx database.

          I was thinking in inserting the following code into the checkout snippet:
          $table = $modx->getFullTableName("nopXorders");
          $sql = "INSERT INTO $table
          VALUES('$oid','$today','$$b_first','$b_last','$b_addr','$b_addr2','$b_city','$b_state','$b_zip','$b_phone','$b_email','$$s_first','$s_last','$s_addr','$s_addr2','$s_city','$s_state','$s_state','$s_state','$s_zip','$s_phone','$s_email','$QUANTITY_1','$PRICE_1','$ID_1','$NAME_1','$ADDTLINFO_1','$QUANTITY_2','$PRICE_2','$ID_2','$NAME_2','$ADDTLINFO_2','$QUANTITY_3','$PRICE_3','$ID_3','$NAME_3','$ADDTLINFO_3','$QUANTITY_4','$PRICE_4','$ID_4','$NAME_4','$ADDTLINFO_4','$QUANTITY_5','$PRICE_5','$ID_5','$NAME_5','$ADDTLINFO_5','$QUANTITY_6','$PRICE_6','$ID_6','$NAME_6','$ADDTLINFO_6','$QUANTITY_7','$PRICE_7','$ID_7','$NAME_7','$ADDTLINFO_7','$QUANTITY_8','$PRICE_8','$ID_8','$NAME_8','$ADDTLINFO_8','$QUANTITY_9','$PRICE_9','$ID_9','$NAME_9','$ADDTLINFO_9','$QUANTITY_10','$PRICE_10','$ID_10','$NAME_10','$ADDTLINFO_10','$QUANTITY_11','$PRICE_11','$ID_11','$NAME_11','$ADDTLINFO_11','$QUANTITY_12','$PRICE_12','$ID_12','$NAME_12','$ADDTLINFO_12','$QUANTITY_13','$PRICE_13','$ID_13','$NAME_13','$ADDTLINFO_13')";
          $modx->db->query($sql);


          and to create the table, maybe:
          $sql = "CREATE TABLE 'nopXorders' ('Order ID','Date','First Name','Last Name','Address1','Address2','City','State','Zip','Phone','Email','sFirst Name','sLast Name','sAddress1','sAddress2','sCity','sState','sZip','sPhone','sEmail','Quant1','Price1','ID1','Name1','AddtlInfo1','Quant2','Price2','ID2','Name2','AddtlInfo2','Quant3','Price3','ID3','Name3','AddtlInfo3','Quant4','Price4','ID4','Name4','AddtlInfo4','Quant5','Price5','ID5','Name5','AddtlInfo5','Quant6','Price6','ID6','Name6','AddtlInfo6','Quant7','Price7','ID7','Name7','AddtlInfo7','Quant8','Price8','ID8','Name8','AddtlInfo8','Quant9','Price9','ID9','Name9','AddtlInfo9','Quant10','Price10','ID10','Name10','AddtlInfo10','Quant11','Price11','ID11','Name11','AddtlInfo11','Quant12','Price12','ID12','Name12','AddtlInfo12','Quant13','Price13','ID13','Name13','AddtlInfo13')";
          $modx->db->query($sql);


            • 7923
            • 4,213 Posts
            if you want that the orders can be listed by ditto, they must be documents in modx


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 31211
              • 25 Posts
              Quote from: doze at Jan 05, 2007, 02:36 PM

              if you want that the orders can be listed by ditto, they must be documents in modx

              My idea was to create a module to get the table data from the DB and show it in the module window. I want to avoid too many modx pages in the tree
                • 7923
                • 4,213 Posts
                yep, own module sounds good to me.. I was just remembering that you wanted to use Ditto and that’s why I suggested that Docmanager.. but own dbtable and a module to go with it sounds better IMO.


                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                  • 31211
                  • 25 Posts
                  Quote from: doze at Jan 05, 2007, 02:47 PM

                  yep, own module sounds good to me.. I was just remembering that you wanted to use Ditto and that’s why I suggested that Docmanager.. but own dbtable and a module to go with it sounds better IMO.

                  Ditto, was for product listing, and etc.

                  About the DB code above...will it work?
                  Maybe I could insert the code for creating the table into the module? - I still dont have any idea of how to do the module or create the table only once! (Its my fisrt contact to PHP, I still have lots to learn!)
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    I’ve got a three-part tutorial on creating a database management module on my sottwell.com site.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 7923
                      • 4,213 Posts
                      You can create the table in any snippet that you feel is a suitable place for it. Do it something like this:
                      <?php
                      $tblNameOrders = "nopXorders";
                      $tblNameItems = "nopXitems";
                      
                      function createTable($tblNameOrders, $tblNameItems, $tblType) {
                      	global $modx;
                      	if ($tblType == 'orders') {
                      		$sql="CREATE TABLE $tblNameOrders (
                      			`order_id` int(10) unsigned NOT NULL,
                      			`date` datetime NOT NULL,
                      			`firstname` varchar(100) NOT NULL,
                      			`lastname` varchar(100) NOT NULL,
                      			`address1` varchar(100) NOT NULL,
                      			`address2` varchar(100) default NULL,
                      			`city` varchar(100) NOT NULL,
                      			`state` varchar(100) default NULL,
                      			`zip` int(10) NOT NULL,
                      			`phone` varchar(100) NOT NULL,
                      			`email` varchar(100) NOT NULL,
                      			`secondary_firstname` varchar(100) default NULL,
                      			`secondary_lastname` varchar(100) default NULL,
                      			`secondary_address1` varchar(100) default NULL,
                      			`secondary_address2` varchar(100) default NULL,
                      			`secondary_city` varchar(100) default NULL,
                      			`secondary_state` varchar(100) default NULL,
                      			`secondary_zip` int(10) default NULL,
                      			`secondary_phone` varchar(100) default NULL,
                      			`secondary_email` varchar(100) default NULL,
                      			PRIMARY KEY  (`order_id`)
                      			) TYPE=InnoDB;";
                      	} else if ($tblType == 'items') {
                      		$sql="CREATE TABLE $tblNameItems (
                      			`item_id` int(10) unsigned NOT NULL auto_increment,
                      			`quantity` int(10) unsigned NOT NULL,
                      			`price` int(10) unsigned NOT NULL,
                      			`product_id` int(10) unsigned NOT NULL,
                      			`product_name` varchar(255) NOT NULL,
                      			`product_info` text default NULL,
                      			`order_id` int(10) unsigned NOT NULL,
                      			PRIMARY KEY  (`item_id`)
                      			FOREIGN KEY (`order_id`) REFERENCES $tblNameOrders (`order_id`) on delete cascade
                      			) TYPE=InnoDB AUTO_INCREMENT=1;";
                      	} else {
                      		return false;
                      	}
                      	$query=$modx->db->query($sql);
                      	return $query;
                      }
                      
                      $query=mysql_query("DESC $tblNameOrders");
                      if(!$query) {
                      	if(!createTable($tblNameOrders, $tblNameItems, 'orders')){
                      		return "Cannot create orders database";
                      	}
                      }
                      $query=mysql_query("DESC $tblNameItems");
                      if(!$query) {
                      	if(!createTable($tblNameOrders, $tblNameItems, 'items')){
                      		return "Cannot create order items database";
                      	}
                      }
                      ?>
                      

                      That creates the items in another table, so you aren’t limited into certain amount (like 13 in your code). You can also see that it creates the tables only if they do not exist, so they could be in the checkout snippet too.. but that creates a littlebit of unnecessary processing overhead (ie. 2 mysql querys), but I don’t think that it’s very bad in this case.. But if you want to be efficient, put the table creation in your module (to be launched by some input button) and run that above code then.. and make an else statement to the conditional to say if the tables are already created. smiley

                      Then you put the orders in to the database by using something like this:
                      <?php
                      //escape values from post data
                      $order_id = $modx->db->escape($_POST['order_id']);
                      $date = $modx->db->escape($_POST['date']);
                      $firstname = $modx->db->escape($_POST['firstname']);
                      $lastname = $modx->db->escape($_POST['lastname']);
                      $address1 = $modx->db->escape($_POST['address1']);
                      $address2 = $modx->db->escape($_POST['address2']);
                      // etc.. all of the values that come from POST data must be escaped, very important!
                      
                      $sql = "INSERT INTO $tblNameOrders (order_id, date, firstname, lastname, address1, address2, city, state, zip, phone, email, secondary_firstname, secondary_lastname, secondary_address1, secondary_address2, secondary_city, secondary_state, secondary_zip, secondary_phone, secondary_email) VALUES ($order_id, $date, $firstname, $lastname, $address1, $address2, $city, $state, $zip, $phone, $email, $secondary_firstname, $secondary_lastname, $secondary_address1, $secondary_address2, $secondary_city, $secondary_state, $secondary_zip, $secondary_phone, $secondary_email)";
                      
                      $query=$modx->db->query($sql);
                      if (!$query) {
                      	return "Error in putting order to the database";
                      }
                      ?>
                      

                      You read those $firstname etc vars from the post data. That $order_id needs to be an unique ID for each order (and that is also used for the order items below).

                      The order items you add by doing:
                      <?php
                      //Again, escape the values from post data first, IMPORTANT!
                      
                      $sql = "INSERT INTO $tblNameItems (quantity, price, product_id, product_name, product_info, order_id) VALUES ($quantity, $price, $product_id, $product_name, $product_info, $order_id)";
                      
                      $query=$modx->db->query($sql);
                      if (!$query) {
                      	return "Error in putting order item(s) to the database";
                      }
                      ?>
                      

                      And you do that item inserting in some for/while loop that gets all the items from the POST data I presume..

                      And when you have that database structure inplace, you can delete orders (and their items, because of the "on delete cascade") simply by doing:
                      <?php
                      $order_id = $_POST['order_id'];
                      $sql = "DELETE FROM $tblNameOrders where order_id = $order_id";
                      
                      $query=$modx->db->query($sql);
                      if (!$query) {
                      	return "Could not delete the order";
                      }
                      ?>
                      


                        "He can have a lollipop any time he wants to. That's what it means to be a programmer."