You are here:  » Bootstrap 4 Conversion


Bootstrap 4 Conversion

Submitted by sbedigital on Sun, 2017-11-26 20:13 in

Hi Dave,

I am trying to create a theme based on Bootstrap 4. I am trying to show 3x3 products based on the following example:

<div class="container">
  <div class="row">
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
  </div>
</div>

However, my problem is <div class="row"> must be opened before every 3 products block and </div> must be placed end of every three product block to produce proper spacing of the items.

Could you please help me out how can I achieve this?

Many thanks in advance.

Noor

Submitted by support on Mon, 2017-11-27 10:03

Hello Noor,

I assume this would be in the context of a product loop so you will have the container followed by a foreach() loop within which the row class needs to be opened and closed every 3 products...

You can do this by including the index variable - $k in this example - in the foreach statement, and then use the % operator (modulus) in an IF condition to create a block that will execute every 3 items within which you can place the close / open divs - for example;

<div class='container'>
  <?php foreach($searchresults["products"] as $k => $product): ?>
    <?php
    if (!($k % 3))
    {
      if ($k) print "</div>";
      print "<div class='row'>";
    }
    ?>
    <div class="col-sm">
      <!-- product info here -->
    </div>
  <?php endforeach; ?>
</div>

Note how the closing div is output using if (!$k) so that it won't output on the first iteration when $k is zero...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sbedigital on Tue, 2017-11-28 18:12

Thank you! It was relatively easy to follow your example. For a front-end, statistical purposes is it possible print out number of products and number of merchant in the database? I am hoping to show them on the
html/searchform.php.

I am sure there is a variable available somewhere. Talking about Variables, I think everyone will benefit if you could publish a list of global variables that template designers can use.

Many thanks.

Noor

Submitted by support on Wed, 2017-11-29 09:00

Hello Noor,

To display number of products and merchants;

<?php
  $sql 
"SELECT count(*) as numProducts FROM `".$config_databaseTablePrefix."products`";
  
database_querySelect($sql,$rows);
  
$numProducts $rows[0]["numProducts"];
  
$sql "SELECT count(DISTINCT(merchant)) as numMerchants FROM `".$config_databaseTablePrefix."products`";
  
database_querySelect($sql,$rows);
  
$numMerchants $rows[0]["numMerchants"];
  print 
"<p>Comparing ".$numProducts." from ".$numMerchants." merchants</p>";
?>

Wherever you want to see what variables are available to use within the HTML modules, print_r() can be used which will just dump the variable to the page - note that the strategy throughout the script is that the top level scripts create a variable of the same name as the HTML module, so for example at the top of html/product.php you could use;

<?php
  
print "<pre>";
  
print_r($product);
  print 
"</pre>";
?>

...to see everything that's available for display.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sbedigital on Wed, 2017-11-29 20:32

Fantastic, I knew you had this covered somewhere along. I did try print_r(); but I was getting some error I wasn't passing the top level variable.

I'll try the SQL implementation later on and I'll let you know how I get on.

Submitted by sbedigital on Fri, 2017-12-01 22:10

UPDATE: SQL for displaying the number of product and Items works brilliantly. Thank you. Would you be able to do me one more favor? I implemented HSTS to satisfy googles SEO requirement, which involves running site using https. Now few merchants supply their product's images over non-secure HTTP port and most of then does supply over secure https.

At first, I have used your SEARCH & REPLACE filters to replace HTTP with HTTPS, obviously, that doesn't solve the problem in the first place.

While researching, I saw on one of the posts regarding a script you have created to cache the images an on the server. So I have tried that, the problem I had was, although I have managed to get it working to write the images to cache folder, for some reason, they never showed up on web pages. I have cleared the browser cache, still no luck. If I give you the FTP access to the server, would be able to troubleshoot this problem for me?

At the moment I can't quite figure out what could be the problem.

Thanks

Noor

Submitted by support on Sat, 2017-12-02 09:14

Hello Noor,

If you'd like to email me a link to an example page where cached images are not showing i'll check it out and then by FTP if I can't spot anything from that page..

Thanks,

David.
--
PriceTapestry.com