Welcome Guest, Not a member yet? Register   Sign In
Shopping Cart Question
#1

[eluser]RMinor[/eluser]
Hi Everyone,
I need to try and sort through my shopping cart to make some custom adjustments but am having very little luck doing so. Basically I want to get the total price and quantity of items in the cart that DO NOT have the words "Tank Top", "Tabs", or "Gift Card" in the product name. The code I have below is not working properly. It is returning the total amount and price of everything in the cart even though I am trying to not include the said items above. Can anyone help me out at all?

Code:
<?php $gift_allowed = FALSE;
$price = array();
$quantity = array();
foreach ($cart as $product) {
    if (strpos($product['name'], 'Tank Top') !== TRUE || strpos($product['name'], 'Gift Card') !== TRUE || strpos($product['name'], 'Tabs') !== TRUE) {
        $price[] = $product['price'] * $product['qty'];
        $quantity[] = $product['qty'];
    }
}
$nail_total = array_sum($price);
$nail_quantity = array_sum($quantity);
if ($nail_total >= 25) {
    $gift_allowed = TRUE;
    $free_tank = TRUE;
}
if ($nail_quantity >= 3) {
    $gift_allowed = TRUE;
    $free_nail = TRUE;
}
var_dump($gift_allowed);
//print_r($price);
//print_r($quantity);
echo '<br />' . $nail_total . '<br />';
echo $nail_quantity; ?&gt;
&lt;?php if ($this->session->userdata('free_nail') != TRUE && $this->session->userdata('free_tanktop') != TRUE && ($gift_allowed == TRUE)) { ?&gt;
    <table width="100%" border="0" cellspacing="5">
    <tr>
        <td align="center" valign="bottom" width="50%">
        &lt;?php if ($this->cart->total_items() >= 3 && $free_nail == TRUE) { ?&gt;
            <a href="&lt;?php echo base_url(); ?&gt;free_nail"><img src="&lt;?php echo base_url(); ?&gt;images/cart-free-nail.png" width="100%" /></a>
        &lt;?php } ?&gt;
        </td>
        <td align="center" valign="bottom" width="50%">
        &lt;?php if ($this->cart->total() > 25.00 && $free_tank == TRUE) { ?&gt;
            <a href="&lt;?php echo base_url(); ?&gt;free_tanktop"><img src="&lt;?php echo base_url(); ?&gt;images/cart-free-nail-or-tank.png" width="100%" /></a>
        &lt;?php } ?&gt;
        </td>
    </tr>
    </table>
&lt;?php } ?&gt;
#2

[eluser]WanWizard[/eluser]
strpos() never returns TRUE, so that if always adds everything.
#3

[eluser]RMinor[/eluser]
I switched my code to use "=== FALSE" instead and it's still not working. Is there a better function that I can use to test for this?
#4

[eluser]RMinor[/eluser]
I got it working by changing the || to &&.




Theme © iAndrew 2016 - Forum software by © MyBB