Your Cart / Empty message hardcoded into header?

Permalink
Hi,

I would like to add the E-commerce 'Your cart is empty / cart contents' to the header of my website so its on each page.

Where could I find the code to do this? Can it be done?

thanks for reading!

 
SVijay replied on at Permalink Reply
SVijay
Hi,

you just need to add the content "Your cart is empty/cart contents" or its a functionality work?

If it is just a content, then do the following
1. Go to dashboard ==> pages and themes ==> page types
2. Click the default button for you page type
3. Add the content block ==> add your text and save it.
4. Whenever you create a page with this page type, the content block you added will be there.

For more details,please watch
http://vimeo.com/3023508

or

you can hardcode in themes/your_themes/elements/header.php

Hope you understand
jaredquinn replied on at Permalink Reply
jaredquinn
If you want to code it into your theme:

$bt = BlockType::getByHandle('cart_links', 'core_commerce');
$bt->controller->showCartLink = true;
$bt->controller->showItemQuantity = false;
$bt->controller->showCheckoutLink = true;
$bt->controller->cartLinkText = t('View Cart');
$bt->controller->checkoutLinkText = t('Checkout');
$bt->render('view');


Should do the trick.
obaluba replied on at Permalink Reply
thanks jared, this is exactly what i was after. I put this exact code in and got:

<?php
   $bt = BlockType::getByHandle('cart_links', 'core_commerce'); $bt->controller->showCartLink = true; $bt->controller->showItemQuantity = false; $bt->controller->showCheckoutLink = true; $bt->controller->cartLinkText = t('View Cart'); $bt->controller->checkoutLinkText = t('Checkout');
$bt->render('view')
?>


But when i check the site, I'm getting this response:

Fatal error: Cannot access protected property CartLinksBlockController::$showCartLink in /home/themename/public_html/themes/themename/elements/header.php on line 32

Line 32 is where I put the code!

Thanks for looking and replying!
jordanlev replied on at Permalink Reply
jordanlev
It looks like you won't be able to do this because of the way that the cart_links block is coded (those settings are coded in a way which prevents them from being changed like this, unfortunately).

I think there is a workaround, though. Add a cart_links block to your global scrapbook (Dashboard -> Scrapbook -> Global Scrapbook, click 'Add Block to Scrapbook' button), give it the settings you want there, save it, and then rename it something like "Header Cart Links". Then in your template add this code:
<?php Block::getByName('Header Cart Links')->display(); ?>
ScottC replied on at Permalink Reply
ScottC
alternatively, if you have it on your homepage and you want to display it everywhere else:

$cartArea = new Area('Cart Links');
$cartArea->BlockWrapperStart(sprintf('div class="error">%s</div>',t('Visit HomePage to edit this block'));
$cartArea->display(Page::getByID(HOME_CID));
iconicschema replied on at Permalink Reply
Hello,

You may have already gotten the answer you were looking for, however I used an alternative method and thought I'd share

The following code will output the number of items in the cart:
Loader::model('cart', 'core_commerce');
$o = CoreCommerceCart::get();
echo $o->getTotalProducts();