Jump to content

Help with Modulas


hometown

Recommended Posts

Let me start off by saying that I know nothing about PHP, but I need a work around in order to make my open source e-commerce software do what I need it to do. The software allows for several products to be grouped and displayed on one page. These grouped products are displayed as follows on the front end:

 

Product One      Price    Qty.

Product Two      Price    Qty.

Product Three    Price    Qty.

Product Four      Price    Qty.

 

For reasons I won't bore you with right now, I need to be able to display products like this:

 

Product One    Price  Qty      Product Two    Price  Qty

Product Three  Price  Qty      Product Four  Price  Qty

 

After educating myself a little on PHP, I found out I could get rid of the table html so that all of the products appear in one row. I've tried that and it seems to work just fine.

 

I think I should then be able to use the “Modulas %” operator to add a <br> after every other product as the code loops through. This is where I'm lost though. I have no idea on how to add this to the code.

 

I've copied the section of code that displays the products on the front end  for your reference. The parts that I think are most relevant I've highlighted in blue. Any direction or input will be greatly appreciated.

 

Thanks

 

 

<?php $_product = $this->getProduct() ?>

<?php $_associatedProducts = $this->getAssociatedProducts() ?>

<table cellspacing="0" class="data-table" id="super-product-table">

<tbody>

<?php if (count($_associatedProducts)): ?>

<?php foreach ($_associatedProducts as $_item): ?>

<tr>

<td><?php echo $this->htmlEscape($_item->getName()) ?></td>

<td class="a-right">

<?php $_price = $_item->getPrice() ?>

<?php $_finalPrice = $_item->getFinalPrice() ?>

<?php if ($_finalPrice == $_price): ?>

<span class="nobr"><?php echo Mage::helper('core')->currency($_price) ?></span><br />

<?php else: ?>

<span class="nobr old-price"><?php echo $this->__('Price') ?> <?php echo Mage::helper('core')->currency($_price) ?></span><br />

<span class="nobr special-price” style="font-size:12px;"><?php echo $this->__('Special Price') ?> <?php echo Mage::helper('core')->currency($_finalPrice) ?></span>

<?php endif; ?>

<?php if($_item->getTierPriceCount()): ?>

<?php foreach ($_item->getFormatedTierPrice() as $_tierPrice): ?>

<?php if($_tierPrice['price'] <= $_finalPrice): ?>

<span class="nobr"><?php echo $this->__('Buy %s for %s', $_tierPrice['price_qty']*1, $_tierPrice['formated_price']) ?></span>

<?php endif; ?>

<?php endforeach; ?>

<?php endif; ?>

</td>

<?php if ($_product->isSaleable()): ?>

<td class="a-center">

<?php if ($_item->isSaleable()) : ?>

<input name="super_group[<?php echo $_item->getId() ?>]” value="<?php echo $_item->getQty()*1 ?>” type="text" class="input-text qty"/>

<?php else: ?>

<?php echo $this->__('Out of stock.') ?>

<?php endif; ?>

</td>

<?php endif; ?>

</tr>

<?php endforeach; ?>

<?php else: ?>

<tr>

<td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>

</tr>

<?php endif; ?>

</tbody>

</table>

Link to comment
Share on other sites

There's a very good FAQ/post here on just this very thing. You are correct that the best approach to use is to use the modulus operator to work out when to create your new rows.

 

Your code is quite hard to read. Not sure you're opening and closing PHP with every line; it's certainly not necessary!

Link to comment
Share on other sites

Thank you Ben, I will take a look at the FAQ/post and see if I can make sense of it. As for the code I apologize, but the code is not mine, it is part of the open source software.

 

Thanks again,

 

Burton

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.