Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Conditional statement in shopping_cart

Conditional statement in shopping_cart

Views: 1,109

Results 1 to 11 of 11
6 Mar 2014, 2:05 AM
#1
the_mech avatar

the_mech

New Zenner

Join Date:
Feb 2012
Posts:
67
Plugin Contributions:
0

Conditional statement in shopping_cart

Source: tpl_shopping_cart_default.php

I added the following conditional statement to the sheet. It is meant to not show any row with a option_value of "None".

<?php

if $value['products_options_values_name'] == "None" {
} else {
<li>

<?php echo $value['products_options_name'] . TEXT_OPTION_DIVIDER . nl2br($value['products_options_values_name']); ?>

</li>
}

?>

When the code is uploaded, the page doesn't load. Any thoughts?

6 Mar 2014, 2:14 AM
#2
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Conditional statement in shopping_cart

<?php

if ($value['products_options_values_name'] == "None") {
// show nothing
} else {
echo '<li>';
echo $value['products_options_name'] . TEXT_OPTION_DIVIDER . nl2br($value['products_options_values_name']);
echo '</li>';
}

?>
6 Mar 2014, 12:06 PM
#3
the_mech avatar

the_mech

New Zenner

Join Date:
Feb 2012
Posts:
67
Plugin Contributions:
0

Re: Conditional statement in shopping_cart

Same outcome :(

6 Mar 2014, 12:12 PM
#4
the_mech avatar

the_mech

New Zenner

Join Date:
Feb 2012
Posts:
67
Plugin Contributions:
0

Re: Conditional statement in shopping_cart

I was thinking about this one all night... Wouldn't the change have to be made near the array? So the section as a whole changes, not just that one section seeing as the whole section is for the one array.

I tried this but with the same outcome:

<?php
  foreach ($productArray as $product) {

echo $value['products_options_values_name'];

if ($value['products_options_values_name'] == "None") {
echo "test";
// show nothing
}
?>

     <tr class="<?php echo $product['rowClass']; ?>">
       <td class="cartQuantity">
<?php
  if ($product['flagShowFixedQuantity']) {
    echo $product['showFixedQuantityAmount'] . '<br /><span class="alert bold">' . $product['flagStockCheck'] . '</span><br /><br />' . $product['showMinUnits'];
  } else {
    echo $product['quantityField'] . '<br /><span class="alert bold">' . $product['flagStockCheck'] . '</span><br /><br />' . $product['showMinUnits'];
  }
?>
       </td>
       <td class="cartQuantityUpdate">
<?php
  if ($product['buttonUpdate'] == '') {
    echo '' ;
  } else {
    echo $product['buttonUpdate'];
  }
?>
       </td>
       <td class="cartProductDisplay">
<a href="<?php echo $product['linkProductsName']; ?>"><span id="cartImage" class="back"><?php echo $product['productsImage']; ?></span><span id="cartProdTitle"><?php echo $product['productsName'] 

. '<span class="alert bold">' . $product['flagStockCheck'] . '</span>'; ?></span></a>
<br class="clearBoth" />


<?php
  echo $product['attributeHiddenField'];
  if (isset($product['attributes']) && is_array($product['attributes'])) {
  echo '<div class="cartAttribsList">';
  echo '<ul>';
    reset($product['attributes']);
    foreach ($product['attributes'] as $option => $value) {


?>

<li>

<?php echo $value['products_options_name'] . TEXT_OPTION_DIVIDER . nl2br($value['products_options_values_name']); ?>

</li>
<?php
    }
  echo '</ul>';
  echo '</div>';
  }
?>
       </td>
       <td class="cartUnitDisplay"><?php echo $product['productsPriceEach']; ?></td>
       <td class="cartTotalDisplay"><?php echo $product['productsPrice']; ?></td>
       <td class="cartRemoveItemDisplay">
<?php
  if ($product['buttonDelete']) {
?>
           <a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, 'action=remove_product&product_id=' . $product['id']); ?>"><?php echo zen_image($template->get_template_dir(ICON_IMAGE_TRASH, 

DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_TRASH, ICON_TRASH_ALT); ?></a>
<?php
  }
  if ($product['checkBoxDelete'] ) {
    echo zen_draw_checkbox_field('cart_delete[]', $product['id']);
  }
?>
</td>
     </tr>
<?php
  } // end foreach ($productArray as $product)
?>
7 Mar 2014, 8:09 PM
#5
the_mech avatar

the_mech

New Zenner

Join Date:
Feb 2012
Posts:
67
Plugin Contributions:
0

Re: Conditional statement in shopping_cart

anyone? :(

7 Mar 2014, 8:34 PM
#6
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Conditional statement in shopping_cart

Can you show me where the option value 'none' is loading on the page you'd like to hide it from? Also why the value is being set to the cart as 'none' ?

9 Mar 2014, 2:14 PM
#7
the_mech avatar

the_mech

New Zenner

Join Date:
Feb 2012
Posts:
67
Plugin Contributions:
0

Re: Conditional statement in shopping_cart

The "None" is the option value set in the attributes. It's not hard coded. The goal is that a list full of options are modified to show only what was selected in the cart / receipt. Anything set to "None" are bypassed. If the next one is set to "Tomato", it is shown.

9 Mar 2014, 2:23 PM
#8
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Conditional statement in shopping_cart

I understand what you're explaining but I'll need to see it in action to give you direction on the code. Also are there any other edits to your cart?

9 Mar 2014, 5:25 PM
#9
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Conditional statement in shopping_cart

Thanks, now I can see exactly what needs to be done, check your PM there's instructions. We can update the forum once it's fixed :)

9 Mar 2014, 10:23 PM
#10
the_mech avatar

the_mech

New Zenner

Join Date:
Feb 2012
Posts:
67
Plugin Contributions:
0

Re: Conditional statement in shopping_cart

I figured it out:

<?php

  echo $product['attributeHiddenField'];
  if (isset($product['attributes']) && is_array($product['attributes'])) {
  echo '<div class="cartAttribsList">';
  echo '<ul>';
    reset($product['attributes']);
    foreach ($product['attributes'] as $option => $value) {
if ($value['products_options_values_name'] == "None") {
} else { ?>
<li>
<?php echo $value['products_options_name'] . TEXT_OPTION_DIVIDER . nl2br($value['products_options_values_name']); ?>
</li>


<?php
}
?>


<?php
    }
  echo '</ul>';
  echo '</div>';
  }

?>
9 Mar 2014, 10:29 PM
#11
the_mech avatar

the_mech

New Zenner

Join Date:
Feb 2012
Posts:
67
Plugin Contributions:
0

Re: Conditional statement in shopping_cart

May this help many people ;)