Echo Specific Category Description on Magento Frontend - magento

I want to create a page in the Magento CMS, then echo specific category descriptions on it. What is the code snippet i will need to accomplish this. I am assuming I will need to reference the categories' unique id within the database to echo their description...
thanks for the help!
john

Using PHP:
$categoryId = 15;
$category = Mage::getModel('catalog/category')->load($categoryId);
if($category->getId()) {
echo $category->getDescription(); // Should escape this, blocks have $this->escapeHtml()
}
I don't know how to do this using magentos email/cms template markup (I don't think its possible) - unless you create a block or widget.

Related

Magento 2 table weight name

I want to do a major changes in the weights of my products in Magento 2.
I don't want to manually change all the products, that will take days. I want to change them in the database directly, but in which table(s) are the product weights stored?
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$_product = $objectManager->create('Magento\Catalog\Model\Product');
$_product = $_product->setWeight(4.0000);
$_product->save();
It is a just example for you.
To achieve your requirement you have to getProductCollection make foreach loop over that collection and get product from that collection than you can apply this example as per your requirement.
This example will not work in .phtml file or your extension.
To check this file you need to create external .php file on root of your magento 2.
Hope this will helps you.

Get categories in a Prestashop theme

I'd like to get all my categories in my header (header.tpl) of my Prestashop theme but it seems not working well...
My code header.tpl :
{$childCategories= Category::getChildren(0, 0, $active = true, $id_shop = false);}
{printf($childCategories)}
Issue : Error 500
The code you have written is not valid for smarty. Prestashop uses Smarty to render templates. Please, take a look to the rules if you want to avoid troubles like this. Also, you have a lot of examples in the default theme of Prestashop to learn more about coding in Smarty.
The right code would be:
{assign var='childCategories' value=Category::getChildren(1, 1, true, false)}
Arguments to be passed
$id_parent : The parent category id. The root id category is 1 and the home id category is 2.
$id_lang: The id language. You can check it in the localization area to get the id of a language. If you have enable multiple languages, you could use the $language variable to get the id. List of global variables in Prestashop.
$active: Return only the active caregories.
$id_shop: The id of a shop if you have got multiple shops in an instalation.
Printing variables to debug
If you want debug or see the variables, you could try the following snippets of code:
{* Print only the variable $childCategories *}
{$childCategories|var_dump}
or:
{* Print all variables *}
{debug}
A template header.tpl comes from FrontController.php function displayHeader().
Category doesn't exists there, because header.tpl is a comprehensive template used in all pages.
There are several hooks which you can use adding content there: displayHeader, displayTop, displayLeftColumn, displayRightColumn, displayFooter.
You can add all categories in any module and one of these hooks like that:
$category = new Category((int)Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);
$sub_categories = $category->getSubCategories($this->context->language->id);
// else code

How to disable products that are not assigned to a category?

Could someone assist with this issue I am having please... I need to disable all products that are not assigned to a category in Magento but the problem is there are some 10,000+ products that I will need to sort through.
I would like to ask what the best approach would be so I could at least begin to solve the problem.
Would it be possible to set all products to disabled if they are not assigned to a category using an Observer? Should I echo the list of unassigned products in a loop then set the status to disabled...
I'm not sure how to go about this one...
Best way to do this is using Magento collections.
Create a new PHP file, include Mage.php, initialize the application and make your changes.
It might take a while depending on product count.
I think you want to do something like that:
require_once('../app/Mage.php');
Mage::init();
$product = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
$store_id = 1;
foreach ($product as $prod)
{
if ($prod->getCategoryIds() == NULL)
{
Mage::getModel('catalog/product_status')
->updateProductStatus($prod->getId(), $store_id, Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
}
}

Magento Pre Order Product with Date attribute

I am new to Magento and maybe its a very basic question, but I want to display Pre-Order products on my home page. I have created an attribute Product_Release_Date and set it to a future date. When I try to get Product_Release_Date its returning blank. What I am doing wrong?
$_productCollection=$this->getLoadedProductCollection(); to get all products
foreach ($_productCollection as $_product):
<?php $currentDate = Mage::getModel('core/date')->date('Y-m-d H:i:s'); to get current date for compare
echo $_product->getResource()->getAttribute('Product_Release_Date');
When I try to display its showing blank, but it returns productName and other things. Only this date is not showing. Please help or provide some tutorial where it shows how to enable pre-order.
The $_product->getResource()->getAttribute('Product_Release_Date'); line is only loading the attribute collection. You can do this after to see what it contains: var_dump($_product->getResource()->getAttribute('Product_Release_Date'));. If it's NULL then make sure your new attribute is really set to Product_Release_Date and not product_release_date (lower-case).
You can use a "magic get" to retrieve the value, like this:
echo $_product->getProductReleaseDate();
Here is a fairly recent tutorial on how to enable display of out-of-stock items:
http://www.inmotionhosting.com/support/edu/magento/103-magento-products-and-inventory-settings/how-to-display-products-that-are-out-of-stock-in-magento
Its very likely the product attribute "Product_Release_Date" is not in the loaded product collection.
If you need to get it then load the products from Magento Product Resource Model
$productCollection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
foreach($productCollection as $product):
echo '<br/>' . $product->getProductReleaseDate();
endforeach;

Magento Product Insert Function

I need to add a custom option to all products as they get saved. For that I need to find the function that inserts the products into the database, which I'm not able to find.
Please, any help would be appreciated.
thanx
$client = new SoapClient('http://www.magentolocal.it/api/?wsdl');
$session = $client->login('productloader', '1234567890');
$sku = "123456";
$attrs['name'] = "Template #1";
$attrs['description'] = "This is the first template.";
$attrs['short_description'] = "This is the short description of the template";
$attrs['websites'] = array('1');
$attrs['price'] = "11.53";
$attrs['categories'] = array('35');
$attrs['images'] = array()
$result = $client->call($session, 'catalog_product.create', array('simple', '63', $sku, $attrs));
echo $result;
$client->endSession($session);
Magento's EAV system is pretty strung out among several files, so you won't find a single function that accomplishes what you want. If you did go looking for it, and changed it, you would also be changing the same save method that mostly every other object in Magento uses, which is probably not what you want.
To do what you want, try setting up an observer/listener on the events that catalog products use when saving, namely catalog_product_save_before or catalog_product_save_after. That way, you don't have to hack the framework.
Hope that helps!
Thanks,
Joe
How about http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.create?

Resources