32 / 32
Feb 2019

blacklabel what cart are you using? E-junkie Cart or Fat Free Cart?

10 months later
Hi, all working fine here but we need a html 'onload refresh' type thing for the cart to work pre rendering - did you ask your Lead Devloper?



I am sure there must be a method for doing this.



Cheers



Jez



E-junkieGuruI did say it was an unofficial hack. :^)



I don't know of any way to display the itemsInCart div contents automatically before the cart is rendered, but I might guess there could be some way to do that with JavaScript?



I'll assign this to the attention of our Lead Developer, in case he has a solution to offer.

If you're handy with JavaScript, our Lead Developer says you can use the functions EJEJC_cartsize(); and EJEJC_cartamt(); at will, to get the number of items and the cart total respectively. The amount currently does not reflect discounts but that'll be fixed shortly.

18 days later

Slight update to help formatting :-



function EJEJC_config() { EJEJC_POSTCALL=true; }

function EJEJC_shown() {

items=EJEJC_cartsize();

if (items== null) {items = 0};

document.getElementById('itemsInCart').innerHTML=items+" Items <BR/>£"+EJEJC_cartamt().toFixed(2)+" total";

}



This gets rid of null value and helps currency format, results of an emply cart :-



0 Items

£0.00 total



Still struggling to get html values on initial page load.



Jez

1 month later
E-junkieGuruIf you're handy with JavaScript, our Lead Developer says you can use the functions EJEJC_cartsize(); and EJEJC_cartamt(); at will, to get the number of items and the cart total respectively. The amount currently does not reflect discounts but that'll be fixed shortly.





can you check with you DEV guy as those functions quoted are returning errors and only available after EJEJC_shown has been run - has he got example code?



thanks



Jez

Note those functions would not be used in cart customization code, although they do depend on having our cart's box.js script loaded into your page (via the <script> portion of our View Cart code); you would need to write your own custom javascript to call those functions and output cart items/total onload within your page.

2 months later

yarg. so close... only the last bit is missing!

how to automatically initialize the mini cart on page load...

too bad my javascript knowledge ends exactly there :frowning:

2 months later

We've got a slight improvement in the recommended syntax, incorporating Jezd's contribution and our cart's jQuery support:



function EJEJC_config() {

EJEJC_POSTCALL=true;

}

function EJEJC_shown() {

items=EJEJC_cartsize();

if (items== null) {items = 0};

jQuery("#itemsInCart").attr("innerHTML",

items+" Items<BR/>$"+EJEJC_cartamt().toFixed(2)+" total");

}



Then just place this in your page wherever you want the minicart to appear:



<div id="itemsInCart"></div>



Now, if anyone's worked out how to get that minicart DIV to display on page load, rather than only appearing after the main cart has been viewed, feel free to share the approach you devised here.

11 days later

Hi



I have this code



<script type="text/javascript">

<!--

function EJEJC_lc(th) { return false;}

function EJEJC_config() {

EJEJC_POSTCALL=true;

EJEJC_OPACITY = 30;

EJEJC_HEIGHT = 500;

EJEJC_WIDTH = 750;

EJEJC_BRDRCOLOR = "#00f";

EJEJC_CDAYS = 61;

}

function EJEJC_shown() {

jQuery("#state1").attr("innerHTML", "Enter <b>SHIPPING ZIP CODE<\/b>");

}

// -->

</script>



not sure how to integrate the mini card code ?

The code you have, plus the minicart code, would look like this when put together:



<script type="text/javascript">

<!--

function EJEJC_lc(th) { return false;}

function EJEJC_config() {

EJEJC_POSTCALL=true;

EJEJC_OPACITY = 30;

EJEJC_HEIGHT = 500;

EJEJC_WIDTH = 750;

EJEJC_BRDRCOLOR = "#00f";

EJEJC_CDAYS = 61;

}

function EJEJC_shown() {

jQuery("#state1").attr("innerHTML", "Enter <b>SHIPPING ZIP CODE<\/b>");

if (items== null) {items = 0};

jQuery("#itemsInCart").attr("innerHTML",

items+" Items<BR/>$"+EJEJC_cartamt().toFixed(2)+" total");

}

// -->

</script>



Then just place this in your page wherever you want the minicart to appear:



<div id="itemsInCart"></div>

Whoops, my bad; in my July 26 post providing the updated minicart syntax (now fixed), somehow I omitted this line:



items=EJEJC_cartsize();



Thus, your version of the code should look like this:



<script type="text/javascript">

<!--

function EJEJC_lc(th) { return false;}

function EJEJC_config() {

EJEJC_POSTCALL=true;

EJEJC_OPACITY = 30;

EJEJC_HEIGHT = 500;

EJEJC_WIDTH = 750;

EJEJC_BRDRCOLOR = "#00f";

EJEJC_CDAYS = 61;

}

function EJEJC_shown() {

jQuery("#state1").attr("innerHTML", "Enter <b>SHIPPING ZIP CODE</b>");

items=EJEJC_cartsize();

if (items== null) {items = 0};

jQuery("#itemsInCart").attr("innerHTML",

items+" Items<BR/>$"+EJEJC_cartamt().toFixed(2)+" total");

}

// -->

</script>

working now - but as soon as you navigate away from the page, it disappears

Yes, as we have explained previously here, the minicart does not appear in a page until the main cart has already been viewed once from that page. You or a developer you'd hire may be able to write some custom javascript to solve that problem. We only present this minicart code as-is, as an unofficial, unsupported hack that our Lead Developer whipped up as a fun side project many years ago but hasn't touched since.

1 year later
E-junkieGuruYes, as we have explained previously here, the minicart does not appear in a page until the main cart has already been viewed once from that page. You or a developer you'd hire may be able to write some custom javascript to solve that problem. We only present this minicart code as-is, as an unofficial, unsupported hack that our Lead Developer whipped up as a fun side project many years ago but hasn't touched since.





I can force the mini cart to appear in the page using this code in the body tag :



<body onload="document.getElementById('mylink').click(); document.getElementById('EJEJC_overlay').style.display = 'none'; document.getElementById('EJEJC_window').style.display = 'none'; setTimeout(function(){document.getElementById('EJEJC_closeWindowButton').click();},1000);">



But i get the same as some other user reported.. Always 0.00 for the cart total.

The item total is displayed correctly.



Anyway this body tag hack should work and show the mini cart on page load.

You may just need to increase the set timeout a little. I am testing on a very fast connection.





edit: i should point out that the id in the code above "mylink" is an id i added to my view cart button.

So essentially on page load, the button is being clicked automatically by the script.

We then hide the overlay and cart window while we get the data we need.

Then after the timeout we close the cart window, with another automated click.

1 year later
doobox



I can force the mini cart to appear in the page using this code in the body tag :



<body onload="document.getElementById('mylink').click(); document.getElementById('EJEJC_overlay').style.display = 'none'; document.getElementById('EJEJC_window').style.display = 'none'; setTimeout(function(){document.getElementById('EJEJC_closeWindowButton').click();},1000);">



edit: i should point out that the id in the code above "mylink" is an id i added to my view cart button.





It took me most of the evening to finally ferret out this workaround... well done! I'm amazed that it takes this much hubub to simply instantiate the cart variables on page load, but this does work.



Cheers!

2 years later

I am a newbie with javascript. I have added the code above. It works. However, when I click on the View Cart button nothing happens.

Here is my test code:

******************

<body onload="document.getElementById('autolink').click(); document.getElementById('EJEJC_overlay').style.display = 'none'; document.getElementById('EJEJC_window').style.display = 'none'; setTimeout(function(){document.getElementById(' EJEJC_closeWindowButton').click();},1000);">



<!-- VIEW CART button code. -->

<a href="1https://www.e-junkie.com/ecom/gb.php?c=cart&ejc=2&cl=3159571" target="ejejc" class="ec_ejc_thkbx" onclick="return EJEJC_lc(this);" id="autolink">

<img src="https://www.e-junkie.com/ej/ejview_cart.gif" border="0" alt="View Cart"></a>



<div id='itemsInCart'></div>

<script>



function EJEJC_lc(th) { return false; };



function EJEJC_config()

{

EJEJC_POSTCALL=true;

}



function EJEJC_shown()

{

myitems=EJEJC_cartsize();

mydollars = EJEJC_cartamt().toFixed(2);

if (myitems=== null)

{

myitems = 0;

}

document.getElementById('itemsInCart').innerHTML=myitems+" Items : Total $"+EJEJC_cartamt().toFixed(2);

}

</script>



<script src='http://www.e-junkie.com/ecom/box.js' type='text/javascript'></script>





</body>



I will appreciate any help you can give.



Thanks

I see we're already working with you via email, so we'll just continue the discussion there if necessary.

2 years later

Just an update to say that our new cart supports a new method to display the cart item quantity anywhere you wish in your page -- better yet, this will appear on initial page-load, even before the cart itself has been viewed on the page.

First, paste this script code into every page where you want to show the cart item quantity; anywhere in the page is fine, but placing it in the page HEAD or above our standard cart <script ...etc.> code would be ideal:

<script type="text/javascript">
var EJConfig = {}
EJConfig.onload = cartLoaded
function cartLoaded(x){
	if(typeof x !== "undefined"){
		if(x.Cart.Items)
			document.querySelectorAll(".EJ-CartItemsNum").forEach(function(y){ y.innerHTML = x.Cart.Items.length; })
		else
			document.querySelectorAll(".EJ-CartItemsNum").forEach(function(y){ y.innerHTML = "0"; })
	}
}
window.onload = function(){
	EJCart.getCartJSON("CID", cartLoaded)
}
</script>

NOTE: Replace the CID near the end there with your E-junkie Client ID, which you can find in Seller Admin > Manage Seller Account > View Account Summary.

Next, simply add any HTML element(s) with class="EJ-CartItemsNum" wherever you want the cart item quantity to appear in your page -- e.g., you could use <b class="EJ-CartItemsNum"></b> or <div class="EJ-CartItemsNum"></div>, etc. -- along with any custom HTML you wish to accompany the quantity shown. For example, you could even make it work as a clickable View Cart link like so:

<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&ejc=2&cl=CID" target="ej_ejc" class="ec_ejc_thkbx" onclick="return EJEJC_lc(this);">
Items in Cart: <b class="EJ-CartItemsNum"></b></a>

(...again replacing CID there with your E-junkie Client ID.)