Link to Page if active in store view in Magento - magento

I try to add a link to a cms page if the page active in store view but don't work. If the page is only active for the store A, keeps appears in store B. Magento 1.9.1.1
<?php $active = Mage::getModel('cms/page')->setStoreId($storeId)->load('guia', $storeId)->getIsActive(); ?><?php if ($active == '1') : ?><?php $aCmsPage = Mage::getModel('cms/page')->load('guia', 'identifier'); $theTitle = $aCmsPage->getTitle(); echo $theTitle; ?><?php endif; ?>
Thank you

<?php
$cmsCollections = Mage::getModel('cms/block')->getCollection();
$attribute = "identifier"; //name of column like Identifier, Title etc.
$value = "home-page-static"; // Value of attribute
$cmsCollections->addFieldToFilter($attribute, $value);
$item = $cmsCollections->getFirstItem();
$id = $item->getData('is_active');
if($id == 1){
echo "CMS PAGE or Static Block Exists and Enable";
}else{
echo "CMS PAGE or Static Block is in-active";
}
?>

Related

how to display all category in magento 1.9.1

i am new in magento developer i am install magento in my domain but now I am displaying all the categories in home page but it is displaying only the top level categories. I want to display all the categories.
Get category and subcategory:
<?php
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0){
foreach($_categories as $_category){
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_subcategories = $_category->getChildrenCategories();
if (count($_subcategories) > 0){
echo $_category->getName();
echo $_category->getId();
foreach($_subcategories as $_subcategory){
echo $_subcategory->getName();
echo $_subcategory->getId();
}
}
}
}
?>
To get only one category: (put category Id as we want)
<?php
$category = Mage::getModel('catalog/category')->load(4);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0){
echo $category->getName();
foreach($subcategories as $subcategory){
echo $subcategory->getName();
}
}
?>
You can use below collection for display all categories. this code fetch data from catch.
$categoriesCollection = $helper->getStoreCategories('name', true, false);

Cart page content, display product individual according to quantity

if i add product with quantity two then in cart contect there is only one product with 2 quantity display. but i want to display separate rows of same product according to quantity.
like cart contect should be as below.
product name Qty price
ABC 1 $10
ABC 1 $10
Finally i got solution. Here is an answer
open this file \app\code\core\Mage\Sales\Model\Quote.php and search for "_addCatalogProduct" function
and replace
$item = $this->getItemByProduct($product);
if (!$item) {
$item = Mage::getModel('sales/quote_item');
$item->setQuote($this);
if (Mage::app()->getStore()->isAdmin()) {
$item->setStoreId($this->getStore()->getId());
}
else {
$item->setStoreId(Mage::app()->getStore()->getId());
}
$newItem = true;
}
to with commenting code.
// $item = $this->getItemByProduct($product);
//if (!$item) {
$item = Mage::getModel('sales/quote_item');
$item->setQuote($this);
if (Mage::app()->getStore()->isAdmin()) {
$item->setStoreId($this->getStore()->getId());
}
else {
$item->setStoreId(Mage::app()->getStore()->getId());
}
$newItem = true;
// }
and in \app\code\core\Mage\Checkout\controllers\CartController.php
replace
$cart->addProduct($product, $params);
to
if($params['qty'] == 0 || $params['qty'] == '')
{
$params['qty'] = 1;
}
$quantity = $params['qty'];
for($loop=1; $loop<=$quantity; $loop++)
{
$params['qty'] = 1;
$cart->addProduct($product, $params);
}
If you really must do this then you could try creating an observer for the event sales_order_place_before and then in your observer you could modify the quote by looping through it and finding multiple qty items, change the qty back to 1 and then add the remainder of items as quote items to the quote object. Not sure if Magento will group them together again during/after the order is placed. You could maybe do the same thing using the event sales_quote_product_add_after which might be better as the user will see the individual lines on the cart page, but again, don't know if Magento will group the qty's back together during the checkout process without actually having a go at making it work. If it does, you could maybe try setting the product to be a super product and override the sku so it has a unique identifer tagged on (e.g. SKU100-1, SKU100-2 etc) before you add it to the quote.
What about this:
Replace this
<?php foreach($this->getItems() as $_item): ?>
<?php echo $this->getItemHtml($_item) ?>
<?php endforeach ?>
with that on line 130 default theme /app/design/frontend/yourtheme/default/template/checkout/cart.phtml
<?php foreach($this->getItems() as $_item): ?>
<?php $qty = $_item->getQty() ?>
<?php for($i=0; $i < $qty; $i++) : ?>
<?php $_item->setQty(1); ?>
<?php echo $this->getItemHtml($_item); ?>
<?php endfor; ?>
<?php endforeach ?>

unable to get product price in custom file magento

Hi i am new to magento and i need to get the products from a particular category
for this i have use
<?php
$id1=4;
$category1 = Mage::getModel('catalog/category')->load($id1);
$collection1 = $category1->getProductCollection();
$collection1->addAttributeToSelect('name');
$collection1->addAttributeToSelect('description');
$collection1->addAttributeToSelect('image');
$collection1->addAttributeToSelect('producturl');
$collection1->addAttributeToSelect('prlce');
$products1 = $collection1->getItems();
$_helper1 = $this->helper('catalog/output'); ?>
<?php foreach ($products1 as $product1){ ?>
<?php echo $this->htmlEscape($product1->getPrice()) ?>
<?php } ?>
in this it is showing the name , image and url but when i am trying to echo price it doenot show anyhing.Please suggest me where i am doing mistake
This is how you do it:
<?php
// Test Params
$cat_id = 4;
$store_id = 1;
// Load Category
$category = Mage::getModel('catalog/category')->load($cat_id);
// Load Category Products
$categoryProducts = $category->getProductCollection();
// Iterate Through Product Collection
foreach ($categoryProducts as $categoryProduct)
{
// Load Product At Specified Store Id
$product = Mage::getModel('catalog/product')
->setStoreId($store_id)
->load($categoryProduct->getId());
// Debug
print_r($product->getData());
// Get Price (e.g.)
echo 'Product Price: '. $product->getPrice()
}
?>

Magento: list all values of a single attribute

I'm trying to list up all the existing values of a newly created attribute in magento 1.7.0.2.
(and make them clickable links, so that on click they list up all of the items with the specific attribute value, but that's not a priority right now)
The attribute code is "artist"
So far i created the file Artist.php in app/code/core/Mage/Catalog/Block/ with the following code:
public function getAllArtists()
{
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'artist');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$artists = $attribute->getSource()->getAllOptions(false);
return $artists;
}
and the file artist.phtml in /app/design/frontend/default/template-name/template/catalog/product with this code:
<ul id="artist_list">
<?php foreach ($this->getAllArtists() as $artist): ?>
<li><?php echo $artist['label'] ?></li>
<?php endforeach; ?>
</ul>
which i then call in a static block with
{{block type="core/template" template="catalog/product/artist.phtml"}}
but nothing appears...
i used the code from this thread: http://www.magentocommerce.com/boards/viewthread/19982/P0/
the attribute is set "Visible on Product View Page on Front-end"
and i call the attribute value of each item in the ../template/product/view.phtml with
<?php echo $_product->getData('artist') ?>
and it correctly displays the value.
any ideas?
$name='whatever_your_attribute_name';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
$attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions(false);
print_r($attributeOptions);
Ref: Magento - get all attribute value
it will be just
$attribute = Mage::getModel('eav/config')->getAttribute(4,'artist');
if($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
foreach($options as $key=>$value) {
if(count($value)==2) {
$artists[] = $value['label'];
}
}
}

How to make second root category navigation in magento?

Other than the normal navigation I get when I add subcategories to the main root category, I want to be able to make a new root category, assign subcategories to it and have it display as a separate menu.
Is this possible?
May this can help you :Link 1Link 2
To retrieve another root category
<?php
echo '<pre>';
$id=9;
$catagory_model = Mage::getModel('catalog/category');
$categories = $catagory_model->load($id); // where $id will be the known category id
if(!empty($categories))
{
echo 'category name->'.$categories->getName(); //get category name
echo '<br>';
echo 'category image url->'.$categories->getImageUrl(); //get category image url
echo '<br>';
echo 'category url path->'.$categories->getUrlPath(); //get category url path
echo '<br>';
}
?>
now $id=9; is my new root category id.
To retrieve sub categories of these new root category ($id=9;) below is the following reference code.Customize it according to your requirements.
<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<?php foreach($categories as $category): ?>
<?php $subcategories = $category->getChildren() ?>
<?php foreach($subcategories as $subcategory): ?>
<?php $subsubcategories = $subcategory->getChildren() ?>
<?php foreach($subsubcategories as $subsubcategory): ?>
<?php endforeach; ?><!-- end foreach subsubcategories -->
<?php endforeach; ?><!-- end foreach subcategories -->
<?php endforeach; ?><!-- end foreach categories -->
In an ideal world you would have found the answer by now, but in case you didn't I modified Nikhil's answer to work for me to basically do what you describe, minus any convenience at all...
$id=9;
$catagory_model = Mage::getModel('catalog/category');
$categories = $catagory_model->load($id);
if(!empty($categories))
{
$cats = explode(",", $categories->getChildren());
foreach($cats AS $c)
{
$cat = $catagory_model->load(trim($c));
echo ''.$cat->getName().'';
}
}
I'm just pasting what I used. The reality is you will have to build the html to make this do whatever you want it to do. If you have subcategories within your loop, you will have to run another fetch in the foreach part.
I am not familiar with magento enough to know what methods you can run on the $cat object. I did a print_r($cat) to examine the object and made a lucky guess that getUrlKey would be available.
Magento... pfft! you'd think ebay would have higher standards than this.

Resources