Magento - Select the cms pages of the current store - magento

I use this collecion to select the cms pages
$collection = Mage::getModel('cms/page')->getCollection()
->addFieldToFilter('is_active',1)
->addFieldToFilter('identifier',array(array('nin'=>array('no-route','enable-cookies'))));
How can I change it to select only the cms pages of the current store ?
Thanks a lot

Check the code below: ->addStoreFilter($store,$withAdmin)
$collection = Mage::getModel('cms/page')->getCollection()
->addStoreFilter($storeId)// You have to provide a store id or Mage_Core_Model_Store Object #see class Mage_Cms_Model_Mysql4_Page_Collection
->addFieldToFilter('is_active',1)
->addFieldToFilter('identifier',array(array('nin'=>array('no-route','enable-cookies'))));

If you do not need filters try this:
$cmsPage = Mage::getModel('cms/page')->setStore(Mage::app()->getStore()->getId())->load('faq-and-help', 'identifier');

Related

How to get the list of attributes on frontend in Magento 2

I'm using Magento 2, when I try add product in Backend, in the Configurations tab, I have created Configuration and I saw there three attributes.
How can I get them in a module on frontend?
I see they are stored in eav_attribute table but I dont know which SQL can be do it, because it has no conditional column
Thank so much!
Use can use below code to get attribute in your module frontend.
$attribute = $objectManager->create('\Magento\Eav\Model\Config')->getAttribute('catalog_product', 'color');
$colorAttributeId= $attribute->getAttributeId();
foreach ($attribute->getSource()->getAllOptions(true) as $option) {
$colors[$option['value']] = strtolower($option['label']);
}
print_r($colors);

Magento: get block of product view

I instanciate the following block by using the operator new but when I am going to use getProduct() it does not return anything because it doesn't have the ID of the product. How can I add it?
$block = new Mage_Catalog_Block_Product_View_Options();
Thanks in advance.
Try this:
$product_id = Mage::registry('current_product')->getId();

Get Custom Product Information Value

I have amazon import script in my magento store. And each product has "Amazon Import Products" inside Product Information (Near General, Prices, Meta Information, Images...).
What I'm trying to get using PHP is located in "Amazon Import Products" And the value of "Amazon Product URL"
Here is my code to choose the product by SKU:
$sku = $id;
$_product=Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
$amazonlink =
Can someone help? The only thing I can find online is how to get product name or images etc but not how to get custom attributes? Also this speed sensitive so I would like to fetch it by the name and not to loop through all the attributes
Try
$sku = $id;
$_product=Mage::getModel('catalog/product')->load($sku, 'sku');
$amazonlink = $_product->getData('custom_attributes_code_here');
// or
$amazonlink = $_product->getCustomAttributesCodeHere();
Below is the safest way to get custom attribute value.
$attribute = $_product->getResource()->getAttribute('custom_attribute_code');
if ($attribute)
{
echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
}
Above code is explained in my blog post here
Getting custom attribute value in Magento

How can I get the Url of a product from its SKU in Magento

The question is simple.
If I know the sku of my product and nothing else, how can I retrieve the url to that item. This is commonly useful for third party integration where the unique id at the remote service wont match a product id. Or maybe you want to make a search box to search by sku only.
You can just do this:
$sku = 'ecco'; // SKU you want to load. 'ecco' is a sku in the Magento demo data
$url = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku)->getProductUrl();
echo $url;
Also.... You could add this to a file named 'geturlbysku.php' in magento root dir. This code enables a small amount of json representing the product to be pulled easily, enabling small javascript integration. Product URL is part of the dataset
<?php
require_once '/app/Mage.php';
umask(0);
Mage::app('admin');
$actual_link = "http://$_SERVER[HTTP_HOST]";
$sku = $_GET['sku'];
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
$fullUrl = "/catalog/product/view/id/" . $product->getId();
header("Content-Type: application/json");
echo $_GET['callback'] . '('.json_encode($product->getData()).')';
?>
Use like this...
www.yoursite.com/geturlbysku.php?sku=theskuoftheproduct
Part of the data returned includes "url_path":"your-product-name.html" which corresponds to the real url.
You can use the load method. This is quicker and easier than all other solutions.
Mage::getModel('catalog/product')->load('sku', 'sku');
For more information on loading products Click Here
$product = Mage::helper('catalog/product')->getProduct($this->getData('sku'), Mage::app()->getStore()->getId(), 'sku');
$url = Mage::getUrl($product->getUrlPath());
You can access the full url of the product based on its sku by adding this to a method and then setting the sku attribute on the class to the sku that you wish to search by.

How get cart content ? (prestashop)

I'd like get cart content on prestashop os-commerce. How can do it ?
You should take a look at the Cart class, located in classes/Cart.php. There's a method called getProducts().
/**
* Return cart products
*
* #result array Products
*/
public function getProducts($refresh = false, $id_product = false)
{
// code...
}
Hope this helps,
Br,
Simply use
Context::getContext()->cart
refer this link
https://www.prestashop.com/forums/topic/440516-how-to-get-all-product-ids-in-current-cart/
It's Working: Enjoy
in module hook you can use this:
$products = $params['cart']->getProducts(true);
If you are using a hook on Shopping Cart page you can use:
$products = $params['products'];

Resources