Post by ianhaney50 » Sun Jun 18, 2023 9:00 pm

I have been sent a task for a client that if there is a specific product name called BRC Levy in the cart in the url index.php?route=checkout/cart then the red remove button needs to be hidden but if there is no product by that name is in the cart then the red remove button needs to be displayed

Is bit of a odd task and not been asked that question before, could someone possibly look at the code I tried below and see what I done wrong please

I tried the following code in catalog/view/theme/default/template/checkout/cart.tpl but it didn't work

Code: Select all

<?php
if($product['name']==$product['BRC Levy']){
?> 
                    <button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="hidden-xs hidden-sm hidden-md" onclick="cart.remove('<?php echo $product['cart_id']; ?>');"><i class="fa fa-times-circle"></i></button>
                        <?php } else { ?>
                        <button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger" onclick="cart.remove('<?php echo $product['cart_id']; ?>');"><i class="fa fa-times-circle"></i></button>
                        <?php } ?>
                        
I am using oc 2.3.0.2

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by by mona » Sun Jun 18, 2023 10:19 pm

Without getting into the pros and cons of questions not asked ..
it is not equal to $product['BRC Levy'] it is only equal to 'BRC Levy'

https://www.thecodingguys.net/tutorials ... -statement

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by ianhaney50 » Sun Jun 18, 2023 11:12 pm

Thank you by mona

Think I just solved it going by the link you sent, it's probably not perfect but it works, below is what I did

Code: Select all

<?php
$product1 = "BRC Levy";
$product2 = "Pontefract Levy";

if ($product1 == "BRC Levy" || $product2 == "Pontefract Levy"){
?>
                        <div style="display: none;"><button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="hidden-xs hidden-sm hidden-md" onclick="cart.remove('<?php echo $product['cart_id']; ?>');"><i class="fa fa-times-circle"></i></button></div>
                        <?php
} else {
?>
<button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger" onclick="cart.remove('<?php echo $product['cart_id']; ?>');"><i class="fa fa-times-circle"></i></button>
                        <?php
}
?>
Sorry thought I had it, just done a test and added another product with a totally different name to the cart and it's hidden the remove button for that product as well, think it's this line that I need to tweak so it's only hiding the remove button for the products named above

Code: Select all

if ($product1 == "BRC Levy" || $product2 == "Pontefract Levy"){

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ADD Creative » Sun Jun 18, 2023 11:31 pm

You may want.

Code: Select all

if ($product['name'] == 'BRC Levy') {

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ianhaney50 » Sun Jun 18, 2023 11:50 pm

ADD Creative wrote:
Sun Jun 18, 2023 11:31 pm
You may want.

Code: Select all

if ($product['name'] == 'BRC Levy') {
Thank you so much, that works perfect

Last question if ok, I need to have them products kept in the cart permanently so I came up with some javascript that adds them to the cart automatically and a cookie that is for 1 day but I just had a thought, when the cookie expires, would the products get removed from the cart, if so I may just extend the cookie length of time in seconds to be alot longer than a day, below is the code for that question

Code: Select all

<script type="text/javascript">
    $(document).ready(function() {
  if (document.cookie.indexOf("FooBar=true") == -1) {
    document.cookie = "FooBar=true; max-age=86400"; // 86400: seconds in a day
      $("document").ready(function(){ cart.add(151,'1'); cart.add(152,'1'); } );
  }
});
</script>

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ADD Creative » Mon Jun 19, 2023 1:00 am

OpenCart will delete items from a guest cart after an hour anyway. Also the session could expire, losing all the cart contents.

I'm not sure what you are trying to achieve, but you may be better modifying the cart library.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ianhaney50 » Mon Jun 19, 2023 2:13 am

ADD Creative wrote:
Mon Jun 19, 2023 1:00 am
OpenCart will delete items from a guest cart after an hour anyway. Also the session could expire, losing all the cart contents.

I'm not sure what you are trying to achieve, but you may be better modifying the cart library.
Ahh ok, I'll have a look to see if I can find the session code and to extend it so it don't expire after 1 hour

The client wants to achieve the following
1) Have two specific products added to the cart automatically on page load just the once so it don't keep adding them each time on page load - I think I have managed to do this part with the javascript code above but may need to extend the time of the cookie length to longer than a day
2) Keep the two specific products in the cart so the guest/customer is unable to remove them - Done this part earlier with your help on the code
3) Keep the two specific products in the cart permanently - This is the last part that is needed to be done

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by by mona » Mon Jun 19, 2023 3:56 am

Not clear exactly - but what you are describing sounds overcomplicated for what I understand.
You want to have two items in the cart all the time.
These items can not be deleted.
These items are sent always.

Just add the items as part of the cart itself to look like products but with no functionality ?

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Mon Jun 19, 2023 4:19 am

ianhaney50 wrote:
Mon Jun 19, 2023 2:13 am
ADD Creative wrote:
Mon Jun 19, 2023 1:00 am
OpenCart will delete items from a guest cart after an hour anyway. Also the session could expire, losing all the cart contents.

I'm not sure what you are trying to achieve, but you may be better modifying the cart library.
Ahh ok, I'll have a look to see if I can find the session code and to extend it so it don't expire after 1 hour

The client wants to achieve the following
1) Have two specific products added to the cart automatically on page load just the once so it don't keep adding them each time on page load - I think I have managed to do this part with the javascript code above but may need to extend the time of the cookie length to longer than a day
2) Keep the two specific products in the cart so the guest/customer is unable to remove them - Done this part earlier with your help on the code
3) Keep the two specific products in the cart permanently - This is the last part that is needed to be done
More modifications needs to be done for this, since the cart library from the core removes all products within an hour by default. You would need to look for an extension on the Marketplace that allows you to modify the extent of the value without breaking the store.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ianhaney50 » Mon Jun 19, 2023 5:17 am

straightlight wrote:
Mon Jun 19, 2023 4:19 am
ianhaney50 wrote:
Mon Jun 19, 2023 2:13 am
ADD Creative wrote:
Mon Jun 19, 2023 1:00 am
OpenCart will delete items from a guest cart after an hour anyway. Also the session could expire, losing all the cart contents.

I'm not sure what you are trying to achieve, but you may be better modifying the cart library.
Ahh ok, I'll have a look to see if I can find the session code and to extend it so it don't expire after 1 hour

The client wants to achieve the following
1) Have two specific products added to the cart automatically on page load just the once so it don't keep adding them each time on page load - I think I have managed to do this part with the javascript code above but may need to extend the time of the cookie length to longer than a day
2) Keep the two specific products in the cart so the guest/customer is unable to remove them - Done this part earlier with your help on the code
3) Keep the two specific products in the cart permanently - This is the last part that is needed to be done
More modifications needs to be done for this, since the cart library from the core removes all products within an hour by default. You would need to look for an extension on the Marketplace that allows you to modify the extent of the value without breaking the store.
Thank you, I found a extension called Persistent Cart https://www.opencart.com/index.php?rout ... n_id=42345, just thought though it would save every product in the cart for a extended period of time but think the client just wants to keep these two specific products in the cart permanently but worst case then may have to keep every product in the cart for longer if can't think of any other way

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by ianhaney50 » Mon Jun 19, 2023 5:20 am

by mona wrote:
Mon Jun 19, 2023 3:56 am
Not clear exactly - but what you are describing sounds overcomplicated for what I understand.
You want to have two items in the cart all the time.
These items can not be deleted.
These items are sent always.

Just add the items as part of the cart itself to look like products but with no functionality ?
"You want to have two items in the cart all the time." Yes that's it, they need to be in the cart all the time
"These items can not be deleted." Yes they can't be deleted
"These items are sent always." Do you mean sent to the cart? if so then yes they will be sent to the cart automatically

I have managed to do number 2 and 3 but it's keeping them two items in the cart as guest carts sessions expire after a hour

"Just add the items as part of the cart itself to look like products but with no functionality ?" I'm not sure how I would do that?

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by by mona » Mon Jun 19, 2023 6:54 am

I am still not sure I understand fully but I will give an example.

Say I have a store and I am offering a free gift with every purchase (if it is not free - the price can be added in totals - say a handling fee).

All I do is fake it in the mini cart and the shopping cart .. I don’t really need to know I am sending out a free gift with every order (and I could add it to the order in an after event anyway)

Fake it .. as in - manually add a product line for both items to the cart itself.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by ianhaney50 » Mon Jun 19, 2023 6:37 pm

by mona wrote:
Mon Jun 19, 2023 6:54 am
I am still not sure I understand fully but I will give an example.

Say I have a store and I am offering a free gift with every purchase (if it is not free - the price can be added in totals - say a handling fee).

All I do is fake it in the mini cart and the shopping cart .. I don’t really need to know I am sending out a free gift with every order (and I could add it to the order in an after event anyway)

Fake it .. as in - manually add a product line for both items to the cart itself.
I think I understand what your saying but I don't think it will work sadly

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by straightlight » Wed Jun 21, 2023 8:47 am

ianhaney50 wrote:
Mon Jun 19, 2023 5:17 am
straightlight wrote:
Mon Jun 19, 2023 4:19 am
ianhaney50 wrote:
Mon Jun 19, 2023 2:13 am


Ahh ok, I'll have a look to see if I can find the session code and to extend it so it don't expire after 1 hour

The client wants to achieve the following
1) Have two specific products added to the cart automatically on page load just the once so it don't keep adding them each time on page load - I think I have managed to do this part with the javascript code above but may need to extend the time of the cookie length to longer than a day
2) Keep the two specific products in the cart so the guest/customer is unable to remove them - Done this part earlier with your help on the code
3) Keep the two specific products in the cart permanently - This is the last part that is needed to be done
More modifications needs to be done for this, since the cart library from the core removes all products within an hour by default. You would need to look for an extension on the Marketplace that allows you to modify the extent of the value without breaking the store.
Thank you, I found a extension called Persistent Cart https://www.opencart.com/index.php?rout ... n_id=42345, just thought though it would save every product in the cart for a extended period of time but think the client just wants to keep these two specific products in the cart permanently but worst case then may have to keep every product in the cart for longer if can't think of any other way
Contact the extension developer to see if it's an available option that could be added into that extension.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 43 guests