How to display Magento Custom Options Individually - magento

My Magento site has a product which has a few Custom Options, one text, one file upload and four drop down lists.
The design of the site dictates that I need to show these options throughout the product view page and not all in one group.
Is there a function that I can call to return the HTML of a single Custom Option?

There are ways to do this that are tantamount to cheating.
Your shop requires javascript to operate and there is a lot you can do with Prototype before the page renders, by using the on dom:loaded event. You can attach your custom options to wherever you want in the DOM, or you can hide them and put something else where you want it on the page that updates the form element. You may want to do this if you have to capture a colour name but don't want to put oodles of colours on every product - a textbox can go on the product and your control can write to it.
The benefit of some $$('cheating') is that you don't have to go too deep into Magento code for what is a 'design consideration'.

I didn't understand correctly about group. If you mean category then ;
create a new attribute set which this attribute set should contain attributes that you want to show. After that, when you create a product, select this attribute set instead of default. So that, only this attributes will be available in the specified products.
Try the following code snippets ( don't forget to change "attribute_code")
Let say, you want to show Multi Select list in your product page, in that case :
$selectArray = $this->getProduct()->getAttributeText('YOUR_ATTRIBUTE_CODE');
$endOfArray = end($selectArray);
echo "<ul class='set-some-class'>";
foreach($selectArray as $selectionItem) {
echo "<li> . $selectionItem";
if($selectionItem != $endOfArray) {
echo "</li>\n";
} else {
echo "</ul>";
}
}
For page other than product view page, in that case:
$attribute = Mage::getModel('catalog/product')->getAttribute('catalog_product', 'YOUR_ATTRIBUTE_CODE');
$options = $attribute->getSource()->getAllOptions(true, true);
$lastOption = end($options);
echo "<ul class='set-some-class'";
foreach($options as $option) {
echo $option['label'];
if($option != $lastOption) {
echo "<li>\n";
} else {
echo "</ul>";
}
}

Related

Hide (configurable) products with attribute

I'm working on a Magento website, and what I would like to do is the following: I created an attribute to hide certain products. On a grid view page, I'm using the following code to exclude them from the list:
<?php if ($_product->getAttributeText('hideproduct')):?>
<?php else: ?>
Basically, it's just saying that when 'hideproduct' shows up, don't show anything.
This works for simple products, but for configurable products, it's a bit more complex, and it doens't seem to work with this. Let's say that I want to hide a product with a certain color, it always keeps appearing in the dropdown menu of the configurable product.
Does anyone have a solution for this?
This is what i did for one of my task (if there is a better way please let me know)
You have to extend Mage_Catalog_Block_Product_View_Type_Configurable for this purpose.
In it
public function getAllowProducts()
{
if (!$this->hasAllowProducts()) {
$products = array();
$allProducts = $this->getProduct()->getTypeInstance(true)
->getUsedProducts(null, $this->getProduct());
foreach ($allProducts as $product) {
if ($product->isSaleable()) {
if(!$product->getEcoReport())
{
$products[] = $product;
}
}
}
$this->setAllowProducts($products);
}
return $this->getData('allow_products');
}
eco_report is my attribute label.
So this is how it works... if for a simple product ( of a particular configurable product) if attribute eco_report is set then that product wont show in the configurable product's drop down list (on view page).
So all simple product's eco_report attribute has to be set so that it wont be shown on the configurable product's dropdown...

Joomla pagination across different components

Because pagination is using getUserStateFromRequest method to get the limit and limitstart variable, I'm having a problem where as I navigate from one component to another, I'm shown a no items found message.
To clarify, I have a products component that has 3 pages worth of products listed. Then I have a branches component with 2 pages worth of branch information. So if I navigate to the third page in the products list, and then go to the branches component, nothing is displayed.
Has anyone any idea how to stop this from happening? Any way to maybe clear the session data?
What I ended up doing was this,
in line 624 in libraries/joomla/application/application.php file I added the following lines
$this->setUserState('option','default');
$curr_comp = JRequest::getCmd( 'option' );;
if($this->getUserState('option') != $curr_comp)
{
$this->setUserState($option . 'limitstart',0);
$this->setUserState('option',$curr_comp);
}
so the whole function reads this,
public function getUserStateFromRequest($key, $request, $default = null, $type = 'none')
{
$this->setUserState('option','default');
$curr_comp = JRequest::getCmd( 'option' );
if($this->getUserState('option') != $curr_comp)
{
$this->setUserState($option . 'limitstart',0);
$this->setUserState('option',$curr_comp);
}
$cur_state = $this->getUserState($key, $default);
$new_state = JRequest::getVar($request, null, 'default', $type);
// Save the new value only if it was set in this request.
if ($new_state !== null)
{
$this->setUserState($key, $new_state);
}
else
{
$new_state = $cur_state;
}
return $new_state;
}
This seems to be working fine at the moment. But please test before implementing on a live site
To prevent editing the core files, but with the effect limited to your extension (so other extensions could load at the wrong page, but not yours), and if your model extends modellist, override the getStart() method:
public function getStart()
{
$store = $this->getStoreId('getstart');
$input = JFactory::getApplication()->input;
$start = $limitstart = $input->getInt('limitstart', 0);
$this->setState('list.start', $limitstart); // maybe redundant
$limit = $this->getState('list.limit');
$total = $this->getTotal();
if ($start > $total - $limit)
{
$start = max(0, (int) (ceil($total / $limit) - 1) * $limit);
}
// Add the total to the internal cache.
$this->cache[$store] = $start;
return $this->cache[$store];
}
If you want a solution that works system-wide and for all extensions, you should be able to override modellist with your implementation in a plugin. Start here.
This is an old question, but I just had the same issue as the OP, but in my case with Joomla 3.4.3.
After a lot of digging and testing, I discovered a solution for this that doesn't involve any plugin or core change:
If you put limitstart=0 in the URL, the pagination will restart for that page, and this solves the problem between menus.
The way to implement this could be either with javascript, or by overriding the menu module, I chose the override:
I just need this in some menus, so I placed a CSS class into the
menu link (edit the menu, and in the "Link Type" tab, place the CSS
class in the "Link CSS Style" field), in my case it was "
video-area" (without the quotes).
Add override (add the module to the html folder of your template,
in my case it was the menu module, so it was a matter of adding the
mod_menu folder: templatefolder/html/mod_menu)
In the override of the component part of the module
(default_component.php), check to see if we have the CSS class, if
so, add the extra query to the URL (I edited case 0):
case 0: $paginationLinks = ""; if(isset($class) && strpos($class, '
video-area') !== false){ $paginationLinks =
"?limitstart=0&limit=12"; } ?><a <?php echo $class; ?>href="<?php
echo $item->flink; ?><?php echo $paginationLinks;?>" <?php echo
$title; ?>><span><?php echo $linktype; ?></span></a><?php break;
That's it! it solved my problem, and even the pagination links have the extra query :)
BONUS: notice that I have &limit=12, this changes the limit for the pagination into 12 per page, without any extra code!, (before, I had a lot of code to implement this, and by adding this to the menu it calculates the correct page number and totals, and filters the query, nice one Joomla!)

magento tracking pixel

There are two variables which are required in the tracking pixel which needs to be placed on category, product info, cart and confirmation page.
I've managed to get the Prod list and Prod working, however, the second two are causing me problems.
I can echo out the sku in the cart, however, the products are configurable products so it's duplicating the sku in the output. The code I'm using is below:
<?php
// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();foreach($items as $item) { echo ''.$item->getSku().' ';}
?>
How do i change this to just display the one configurable SKU?
The second element is the Category name that the product exists in, Any one got any ideas on that? I've tried multiple variations but they've either broke the page or returned nothing.
Any help would be appreciated. If someone could also give me examples of how these would work on the confirmation page as well, that would be great.
Thanks for your help.
Check for the products visibility (simple products attached to a configurable would not be visible):
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item) {
if ($item->getProduct()->isVisibleInSiteVisibility()) {
echo ''.$item->getSku().' ';
}
}
With regards to the category name, a product can appear in multiple categories so im not sure how you want to handle that. Also, there is a concern that you are beginning to duplicate code across several template files. You will want to consider moving this all out to a block.
Anyway, to get the category names that the product belongs to here is at least one method of doing this...
$categoryCollection = $item->getProduct()->getCategoryCollection()
->addAttributeToSelect('name');
foreach($categoryCollection as $category) {
echo $category->getData('name') . "<br/>";
}

how not to show category name in magento breadcrumb?

I am working with a magento website. I have used a featured category to display homepage slider products. So when I click on the product it shows featured as a category in the breadcrumb.
Would it be possible not to show featured in the breadcrumb ? I want category name in the breadcrumb for the rest of categories .
Thanks
Ab
actually not getting your question but you can get some idea from here:
in page/html/breadcrumb.phtml file near line 34-36 change, $_crumbInfo['label'] to $_crumbInfo['title']
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['title']) ?></strong>
then in catalog/block/breadcrumb.php add 2 lines after
$path = Mage::helper('catalog')->getBreadcrumbPath();
$currentCategory = Mage::registry('current_category');
$metaname = $currentCategory['name'];
and change foreach loop like
foreach ($path as $name => $breadcrumb) {
$breadcrumb['title'] = $metaname;
$breadcrumbsBlock->addCrumb($name, $breadcrumb);
$title[] = $breadcrumb['label'];
}
and check it,
hope you get some idea..
Why no simpler than that?
Try to use CSS. Your category will have an automatic and specific class for it. For example:
<li class="category4">
<strong>ARCHERY HUNTING</strong>
</li>
In this piece of code, I have a category that I created, called "Archery hunting". The code auto-created the class="category4", So, only write on your CSS:
.category4 strong { display: none; }
And it will hide only that category.
Instead of using
$_product->getProductUrl()
to fetch URL, use this:
$_product->unsRequestPath()->getUrlInStore(array('_ignore_category' => true))
Then you need to unset last visited category id at the end of your featured block:
Mage::getSingleton('catalog/session')->setLastVisitedCategoryId('');
This is all because key part for forming breadcrumbs is the following code:
$categoryId = $params->getCategoryId();
if (!$categoryId && ($categoryId !== false)) {
$lastId = Mage::getSingleton('catalog/session')->getLastVisitedCategoryId();
if ($product->canBeShowInCategory($lastId)) {
$categoryId = $lastId;
}
}
basically, current category is determined by either URL params (hence the modified URL call), or through the session object (hence the removal of last visited category id)
so, to recapitulate, in your Featured block, instead of regular productUrl call, use the one I provided, and at the end of your featured product block listing, remove the lastVisitedCategoryId using the code I gave you

Determining which section is being viewed

Folks, I am trying to implement a rudimentary feature in Joomla but having no luck getting my head around it.
My client has setup Joomla with several sections; each section having its own categories and eventually content underneath.
I need each section to have a slightly different color component (e.g. Section A and its all subsequent child pages red, Section B - blue, etc); certain borders and backgrounds need to be unique according to each section.
I have one theme which is used by all sections. Somewhere in the theme file, I need to detect which section I am on, and based on that set a css variable accordingly:
<html>
<body class="cars-section">
</body>
</html>
All I need is to set my body's class to the right section, and all my coloring has been setup to work magically.
Any ideas how this can be done in the Joomla world? Is there another way of doing such a thing.
You need to pick the section ID up from the request.
Use this to get the relevant request variables:
<?php
$option = JRequest::getWord('option', null);
$view = JRequest::getWord('view', null);
$idalias = JRequest::getVar('id', null);
if (strpos($idalias, ":") != false) {
$idandalias = explode(":", $idalias);
$id = $idandalias[0];
} else {
$id = JRequest::getInt ('id' , 0);
}
Then use something like this to see what section you are in, if you are on a section page:
if ( $option=="com_content" && $view=="section" ) {
$sectid = $id;
}
In section pages you can just use the request, but in other pages you need to do a database query as well:
else {
$database =& JFactory::getDBO();
if ( $option=="com_content" && $view=="category" ) {
$query = "SELECT section FROM jos_categories WHERE id=$id";
}
if ( $option=="com_content" && $view=="article" } {
$query = "SELECT sectionid FROM jos_content WHERE id=$id";
}
$database->setQuery($query);
$sectid = $database->loadResult();
}
When you have the section ID you can use it to set and insert the right class.
if ( $sectid == '3' ) {
$my_cars_section_class = 'three';
}
?>
<body class="<?php echo $my_cars_section_class; ?>">
Something like that should do it.
There are a couple of ways to achieve body css-classing:
Utilize Joomla's menu page class suffix system.
Output the class based on the selected menu link from within the template. Of course, if you plan to do this, you'll need to modify your template a bit.
$menu = &JSite::getMenu();
$active = $menu->getActive();
<body <?php if($active->alias) echo 'class="' .$active->alias .'"' ?>>

Resources