Saturday, January 21, 2017

Php - Adding divs to a foreach loop every 4 times

Basically what i need to do is wrap a div around the output of the data every 4 loops.

I have the following loop:

foreach( $users_kicks as $kicks ) {
    echo $kicks->brand;
}

For every 4 times it echos that out i want to wrap it in a  so at the end it will look like so:

<div>
    kicks brand
    kicks brand
    kicks brand
    kicks brand
</div>
<div>
    kicks brand
    kicks brand
    kicks brand
    kicks brand
</div>
<div>
    kicks brand
    kicks brand
    kicks brand
    kicks brand
</div>


Solution:
=========
$count = 1;

foreach( $users_kicks as $kicks )
{
    if ($count%4 == 1)
    { 
         echo "<div>";
    }
    echo $kicks->brand;
    if ($count%4 == 0)
    {
        echo "</div>";
    }
    $count++;
}
if ($count%4 != 1) echo "</div>";

//This is to ensure there is no open div if the number of elements in user_kicks is not a multiple of 4



Cheers and thanks !!! For get more refer this link

Wednesday, January 04, 2017

Opencart - Shipping For Multiple Flat Rates


Do you want a second (or third, or fourth) flat rate for your site’s shipping? OpenCart doesn’t include a shipping method that allows for multiple flat rates by default, but you can easily set up multiple flat shipping options using the built-in Weight Based Shipping extension.

1. In System > Localisation > Geo Zones, set up a duplicate geo zone for each flat rate that you want. For example, if you wanted these three shipping options available to the U.S.:
  • Standard: $5.00
  • Express: $12.00
  • Next-Day: $18.00
then you would create three geo zones all with United States selected as the country, named “Standard”, “Express”, and “Next-Day”.

2. In Extensions > Shipping > Weight Based Shipping, create a rate for each geo zone with a rate (in the format Weight:Cost) like so:
RATE #1
  • Geo Zone: Standard
  • Rates: 999999:5.00
RATE #2
  • Geo Zone: Express
  • Rates: 999999:12.00
RATE #3
  • Geo Zone: Next-Day
  • Rates: 999999:18.00
Don’t forget to enable the extension as a whole in the “General” tab, and each geo zone in its own tab. If you have other geo zones for other purposes then leave those disabled in their tabs. If you need a tax rate applied to the shipping costs, then select the Tax Class in the “General” tab.

3. During checkout, each option will be presented to the customer on the “Delivery Method” step. They are ordered alphabetically by name, so if you need them in a particular order then you should name them accordingly.

4. If you want to remove the cart weight that is attached to each rate title, then you can make the following edit:

IN:
/catalog/model/extension/shipping/weight.php
REPLACE:
$result['name'] . ' (' . $this->language->get('text_weight') . ' ' . $this->weight->format($weight, $this->config->get('config_weight_class_id')) . ')',
WITH:
$result['name']
 
And that’s it! Your OpenCart store now has multiple flat rate shipping options for your customer.

Thanks to for the article