I am trying to get the product attribute in my downloadable controller. I am working on an ebook store. I have created a custom module sp. I need the product attribute to watermark my ebooks.
The controller I am working on is Mage/Downloadable/controllers/DownloadController.php
Any suggestions?
Thanks.
Depends totally in which action you are.
If you have a look at the linkAction you can see how they obtain the product:
$id = $this->getRequest()->getParam('id', 0);
$linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')->load($id, 'link_hash');
[...]
$product = Mage::getModel('catalog/product')->load($linkPurchasedItem->getProductId());
Now the product is loaded in the $product variable.
You can get product attributes as usual by $product->getData('my_custom_attribute') or $product->getMyCustomAttribute.
Related
For example, here is url
http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-l-s-93368.html.
There are several simple products. How can I get the actual simple product ID, from this url?
Magento 1.8
First use the URL rewrite model to find the route which matches your product:
$vPath = 'http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-l-s-93368.html';
$oRewrite = Mage::getModel('core/url_rewrite')
->setStoreId(Mage::app()->getStore()->getId())
->loadByRequestPath($vPath);
Then you can call getProductId() on the route to locate the produc's id:
$iProductId = $oRewrite->getProductId();
Finally if you require the product model object itself it's then a simple matter to call:
$oProduct = Mage::getModel('catalog/product')->load($iProductId);
I'm just developing codes for a custom Prestashop module. I can access list of all products in my module using Product::getProducts(...) however I don't know how can I access details of specified product having its ID.Can someone tell how can this be accomplished?
// there is Product object that contains all details of certain product.
// for arguments details see in classes/Product.php constructor method
$product = new Product($id_of_product_that_you_have, false, $id_lang);
echo $product->name, $product->description; // etc
For getting the specific description of the product,
First you have to make a object of product and for that you have to know the id of the product for which you want to get description.
$product = new Product($product_id, false, $id_lang);
$product_description = $product->description;
d($product_description);
I would like to get root category on product.tpl with Prestashop.
It means if I have a product which is in cat1>cat2>cat3, I should get "cat1".
Is it possible ?
I tried $product->id_category_default, but I only get the current category.
You have to create new smarty variable in ProductController and use getParentsCategories() function for your product category.
I have a bundle product and I have added 3 bundle items (of type checkboxes) to it through the admin panel. 2 of the bundle item have only one selection in it, while the third one has 7 selections(each of which are simple products).
Now i have a situation in which i need to display the names of simple products that i have added to the third bundle product and not the entire bundle item(default case).I have tried a lot and i couldn't find a solution for it
Hint: the checkbox default display is defined in the file app/design/frontend/base/default/template/bundle/catalog/product/view/type/bundle/option/checkbox.phtml and i think we need to do codings here in this file.
please help me guys.. i really need a solution for this..
Yes... I think I have found a solution for this. I have added bundle item with a name 'LLC' and added simple products as checkboxes.. what i need to do is to display the names of simple products that I have added under the LLC bundle item instead of displaying LLC along with their checkboxes(default case).
The way of displaying checkboxes are defined in the file :
app/design/frontend/base/default/template/bundle/catalog/product/view/type/bundle/option/checkbox.phtml
so i have defined a function there as like this..
<?php
if($this->htmlEscape($_option->getTitle())=="LLC")
{
$current_product=Mage::registry('current_product');
echo $this->getpackagedetails($current_product,$this->htmlEscape($_option->getTitle()));
}
?>
here as you can see, i checked the name of the bundle item is LLC or not. If yes, get the current product to a variable and then i called a function 'getpackagedetails()' which is defined in the block of checkbox which you can find here /app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php. This function passes two arguments: current product and the bundle item name.
Now add our function in to the block file. it is given below.
<?php
public function getpackagedetails($currentproduct,$optid)
{
$display="";
$bundled = Mage::getModel('catalog/product');
$bundled->load($currentproduct->getId());
$selectionCollection = $bundled->getTypeInstance(true)->getSelectionsCollection(
$bundled->getTypeInstance(true)->getOptionsIds($bundled), $bundled);
foreach($selectionCollection as $option)
{
$sku=$option->getSku();
if($optid=="LLC" && $optid==$bistype)
{
if(strpos($sku,"llc")!== false)
{
$display.=$option->getName();
}
}
}
return($display);
}
Here what I have done is i have loaded my current product using the variable $bundled. Then i get all selection type options that i have added to my bundle product to the variable $selectionCollection. In order to seperate options correspond to the LLC bundle item, I have checked whether there is 'llc' string in the sku of each option(all simple product corresponds to the LLC bundle item, i have set 'llc' string in there sku). If yes get there name and store it into the variable $display. then returned the variable.
thats it. now you can see only the simple product name that i have added for the bundle item with name LLC.
Using this tutorial on this page Adding new tabs and fields to Prestashop products’ back office, I was able to add a new field for author for products in my Prestashop. I was also able to display it on product page by adding Product.php to override/classes/ and inserting this code below:
class Product extends ProductCore
{
/** #var string Custom Product Field */
public $custom_field;
}
I then added {$product->custom_field} to product.tpl to display the new field. My challenge is that the same code does not work when added to product-list.tpl and the homefeatured.tpl module files.
Can any one explain how to achieve this? I am not an expert but I can find my way around tutorials if I have one. Thanks!
Find the function used by the module Homefeatured to get the products and edit the SQL request in this function to add your new field.
You can't display your new propertie because the SQL request don't get it.
Use . instead of ->
In product-list.tpl & homefeatured.tpl $procuct is array not object.
And do not miss the getFields() method in Product class:
public function getFields()
{
$fields = parent::getFields();
$fields['custom_field'] = $this->custom_field;
return $fields;
}