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!
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!
If you want to code it into your theme:
Should do the trick.
$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.
thanks jared, this is exactly what i was after. I put this exact code in and got:
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!
<?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!
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:
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(); ?>
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));
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:
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();
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