Skip to content

Instantly share code, notes, and snippets.

@cfaria
Created October 1, 2013 11:58
Show Gist options
  • Save cfaria/6777358 to your computer and use it in GitHub Desktop.
Save cfaria/6777358 to your computer and use it in GitHub Desktop.
Breadcrumbs in product always have category Magento app/code/core/Mage/Page/Block/Html/Breadcrumbs.php
protected function _toHtml() {
$cat_id = "";
if (Mage::registry('current_product')) {
$product_id = Mage::registry('current_product')->getId();
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($product_id); // Enter your Product Id in $product_id
if ($product_id) {
$categoryIds = $_product->getCategoryIds();
$primera_activa = false;
foreach ($categoryIds as $key => $_tempid) {
$_tempcat = Mage::getModel('catalog/category')->load($_tempid);
if ($_tempcat->getIsActive()){
//Cojo por defecto la primera categoría que está activa
if(!$primera_activa){
$cat_id = $_tempid;
$primera_activa = true;
}
if($_tempcat->getPrincipal())
{
$cat_id = $_tempid;
break;
}
}
}
}
$category = Mage::getModel('catalog/category')->load($cat_id);
$cat_name = $category->getName();
$cat_url = $this->getBaseUrl().$category->getUrlPath();
}
if (is_array($this->_crumbs)) {
reset($this->_crumbs);
$this->_crumbs[key($this->_crumbs)]['first'] = true;
end($this->_crumbs);
$this->_crumbs[key($this->_crumbs)]['last'] = true;
}
if($cat_id) {
$this->_crumbs['category'.$cat_id] = array('label'=>$cat_name, 'title'=>'', 'link'=>$cat_url,'first'=>'','last'=>'','readonly'=>'');
ksort($this->_crumbs);
$home = $this->_crumbs['home'];
unset($this->_crumbs['home']);
array_unshift($this->_crumbs,$home);
}
$this->assign('crumbs', $this->_crumbs);
return parent::_toHtml();
}
<?php
error_reporting(E_ALL | E_STRICT);
require_once 'app/Mage.php';
Mage::app();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
// below code will add text attribute
$setup->addAttribute('catalog_category', 'principal', array(
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Principal',
'input' => 'select',
'class' => '',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment