We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34954
    • 12 Posts
    Hello all,

    I would like to know if people have been succesful at using Prestashop and Modx Revo together?

    I've had a look around and decided that the learning curve of magento is a bit too steep for me so I am considering Prestashop which seems nicer to use from a designer perspective.

    I suppose that I can have a modx site and a Prestashop one side by side with the Modx template mirroring the Prestashop one but if there is a way of showing the products in Modx, that would be nice as most of the templating would happen in Modx and which would be easier for me.

    Unfortunately I can't wait for Visioncart and the other Russians plugins are not really documented well enough for me to use them as my php skills are limited to very basic stuff!
      • 37009
      • 21 Posts
      Just writing really simple snippet to show in MODx all products from certain category. If anyone have done something similar please, let me know.

      Next step would be probably to make the header and/or sidepanel and/or footer or any other areas in Prestashop taking from MODx generated file.
        • 37009
        • 21 Posts
        Just a really basic but it works

        In MODx resource I add snippet call:
        [[!prestaCat? &categ=`1`]]
        where &categ is the category ID I want to get.

        Then you create chunk 'prestaTpl' - for example mine:

        <img src="http://domain.com/prestashop/img/p/[[+id]]-[[+image]]-medium.jpg" align="left" />
        <h4><a href="http://domain.com/prestashop/product.php?id_product=[[+id]]">[[+name]]</a></h4>[[+shortdesc]]<p>Available text: [[+available]]
        Price: [[+price]] €</p>


        And create snippet 'prestaCat' and change Prestashop DB details:

        $db_hostname = "localhost";
        $db_username = "dbuser";
        $db_password = "passssss";
        $db_database = "dbname";
        
        $db_server = mysql_connect($db_hostname, $db_username, $db_password);
        if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
        mysql_select_db($db_database) or die("Unable to select database: " . mysql_error());
        
        $result3 = mysql_query("SELECT * FROM ps_category_product WHERE id_category='$categ'") 
        or die(mysql_error()); if (!$result3) die ("Database access failed: " . mysql_error());
        while($row3 = mysql_fetch_array( $result3 )) {
            $id = $row3['id_product'];
            $result2 = mysql_query("SELECT * FROM ps_product_lang WHERE id_product='$id'");
            while($row2 = mysql_fetch_array( $result2 )) {
                $name = $row2['name'];
                $desc_short = $row2['description_short'];
                $available = $row2['available_later'];
                
                $result = mysql_query("SELECT * FROM ps_product WHERE id_product='$id'");
                while($row = mysql_fetch_array( $result )) {
                    $price = sprintf('%0.2f', $row['price']);
                }//end while 'Price'
        
                $result_i = mysql_query("SELECT * FROM ps_image WHERE id_product='$id'");
                while($row_i = mysql_fetch_array( $result_i )) {
                    if ($row_i['position'] == 1) $image = $row_i['id_image'];
                }//end while 'Image'
                
                if ($row2['id_lang'] == 6) $send = $send . $modx->getChunk('prestaTpl',array(
                    'image' => $image,
                    'id' => $id,
                    'name' => $name,
                    'shortdesc' => $desc_short,
                    'available' => $available,
                    'price' => $price,
                ));
            }//end while 'Products in right category'
        }//end while 'Get product IDs in right category'
        mysql_close($db_server);
        
        return $send;


        Very primitive. I didn't get Prestashop SEF friendly URLs working so must modify the code if you have SEF URLs working.

        Also, there's one issue I'm not sure how to fix - it takes from Prestashop database öäüõ characters as �. One idea is that xPDO should be used but I'm not that advanced yet. Rather wrote it as a test if it'll work.
          • 34954
          • 12 Posts
          Thank you very much for posting this.

          I suspect that the weird characters are due to a unicode (encoding) error with presumably modx and the database not using the same encoding. Unfortunately I am more of a Python than php person and can't offer any practical advice as to how to solve the issue, there is an easy solution in python so it may not be very difficult in php.

          We are about to start doing our website in Prestashop and in August we could do a bit of testing if this is of any use to you. I would like to help you but unfortunately I really struggle with php so can't do much more than adapting existing code.
            • 37009
            • 21 Posts
            Thanks. I'm also not a coder - rather hobby coder. We have a professional coder also but he's in holiday so that's actually good for me as I have no chance for easy questions and have to use my own head:)

            I'll try next week the special char issue somehow.

            BTW, at line 30 you must change to your language $row2['id_lang'] == 6 - if it's English then probably 1.
              • 37009
              • 21 Posts
              With this script you create a resource for each category manually and add there snippet call:
              [[!prestaCat? &categ=`5`]] 
              - not sure how to automate that. I can write a script to get the list of categories from DB that have products in it but how to make MODx automatically show products in that category when you click on the category?