Magento Pre Order Product with Date attribute - magento

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;

Related

Issues using a custom attribute in Magento for retrieve several products

I have a problem with my code. I created a custom attribute called product_type, as single value, and I was used that value for filtering the products...
$productType = $_GET['type'];
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToFilter("product_type", array('eq' => $productType));
Later, I had change the attribute for allow multiple selections. I mean, before change in the attribute behavior one product have only one product_type, now one product can have multiple product_type.
I was sure that the code could be continue working but it's not.
Any help? Thank U!

export the products having no images in magento

I have imported more than 55k products in magento. And i found that some of the products don't have images imported.
Can you give me a way how can i export the products having no images ?
I have tried to export the product having image value as 'no_selection' but, it gives me only 2-3 items. Then i tried to cross verify those entity_id which have no images into 'catalog_product_entity_varchar' table. And i surprised by not finding when some entity_id presents in 'catalog_product_entity' table but not in 'catalog_product_entity_varchar' table.
Can anyone give me a way to solve this problem.
Any help will really be appreciated.
Regards
Does this query help?
SELECT t0.sku
FROM catalog_product_entity AS t0
WHERE NOT EXISTS(
SELECT NULL
FROM catalog_product_entity_media_gallery AS t1
WHERE (t1.entity_id = t0.entity_id)
)
If you only need SKUs, one method I have used in the past is via a Magento shell script. This example will output only SKU's (one per line) for only those products which have no value for the image attribute.
<?php
error_reporting(E_ALL);
error_reporting(-1);
require_once 'app/Mage.php';
Mage::app();
$collection = Mage::getModel('catalog/product')->getCollection();
foreach($collection as $product){
$productId = $product->getId();
$prod = Mage::getModel('catalog/product')->load($productId);
$hasImage = Mage::helper('catalog/image')->init($prod, 'image');
if (!$hasImage){
echo $prod->getSku() . "\n";
}
}
?>
I put this into "list-noimages.php, and into my Magento root folder. Only use this in development environment, or very limited on production. Run it via shell as so:
php list-noimages.php
For that many products you can output to a file:
php list-noimages.php >> skus.txt
Otherwise visit the file via your web browser and save the output.

Magento:how to get manufacturer name in Product page?

I want to display manufacturer name in product/view.phtml .I have all used all sort of functions like
<?php echo $_product->getAttributeText('manufacturer');?>
<?php echo $this->htmlEscape($_product->getData('manufacturer'));
<?php echo $_product->getData('manufacturer'); ?>
But none of them helped.So how to get manufacturer name in product view page .
As mentioned above you will need to follow a few steps:
1) goto Attribute Sets, and make sure "manufacturer" is assigned to the attribute set you are using.
2) Make sure you have added some manufacturers into the attribute options.
3) Assign one of the options to your product.
Depending on your magento version this should work:
<?php echo $_product->getAttributeText('manufacturer') ?>
I can see the error you are getting:
gives error Call to a member function getManufacturer() on a non-object in
Are you sure you are putting this code after this line:
<?php $_product = $this->getProduct(); ?>
you can use something like this to get manufacture name
$_product->getResource()->getAttribute('manufacture')->getFrontend()->getValue($_product);
Make sure the following things
1. Your attribute code is "manufacturer".
2. "Manufacturer" attribute is added to your attribute set.
3. You have chosen attribute values in admin catalog product.
4. That corresponding product is visible on frontend.
If all the 4 points are yes your code should work.
Try:
$_procuct->getManufacturer();
<?php
echo $_helper->productAttribute($_product, $_product->getManufacturer(), 'manufacturer')
?>
manufacturer (and all other attributes) is part of the optionslist, which is accessible by getOptionsList.
Try this snippet:
<?php
$_options = $this->getOptionList();
echo $_options['manufacturer']['value'];
?>
Make sure that the "Used in product listing" option for the manufacturer attribute has been set to "Yes".
After that you should be able to do
$_product->getManufacturer();
$_product->getAttributeText('country_of_manufacture');

Magento get all products

I am trying to get the entire magento product collection, without any filters or restrictions, but I fail to get all products.
I've tried various methods already, but they all give me a very limited selection of products. Let's say the store contains 5000 products, but it only shows 500. When I check the catalog -> products is does show me the entire list.
Mage::getModel('catalog/product')->getCollection();
Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
Mage::getModel("catalog/product")->getResourceCollection()->load();
All of them return the same amount (500), while I expect it to give me 5000 products. I would prefer not to use Zend or PHP and just stick to the Magento way to get them.
Does anyone know how to really get ALL products or can point me in the right direction why this isn't working?
The select-string that is returned is:
SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id` FROM `catalog_product_flat_4` AS `e`
//to overwrite limit but you need first to increase your memory limit
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') // select all attributes
->setPageSize(5000) // limit number of results returned
->setCurPage(1); // set the offset (useful for pagination)
// we iterate through the list of products to get attribute values
foreach ($collection as $product) {
echo $product->getName(); //get name
echo (float) $product->getPrice(); //get price as cast to float
echo $product->getDescription(); //get description
echo $product->getShortDescription(); //get short description
echo $product->getTypeId(); //get product type
echo $product->getStatus(); //get product status
// getCategoryIds(); returns an array of category IDs associated with the product
foreach ($product->getCategoryIds() as $category_id) {
$category = Mage::getModel('catalog/category')->load($category_id);
echo $category->getName();
echo $category->getParentCategory()->getName(); // get parent of category
}
//gets the image url of the product
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
'catalog/product'.$product->getImage();
echo $product->getSpecialPrice();
echo $product->getProductUrl(); //gets the product url
echo '<br />';
}
And something like this:
$products = Mage::getModel('catalog/product')->getCollection();
foreach($products as $prod) {
$product = Mage::getModel('catalog/product')->load($prod->getId());
}
With this method I get more than 500 but all my product...
Several possibilities here:
1. Some inner limitation, like 500 at all.
2. Some paging limitation. Products per page(in db abstract)
3. Some lazyload limitation.
Perhaps, there is some over problem, but I think this is some inner limit.
Turn off your flat_catalog_product in admin > system > configuration > catalog > catalog. After this you will get a full product collection. Even though this is a workaround, it helped me to achieve what I needed to achieve.
You might be using Flat Catalog Product Structure . This create separate table for each store view.
Use Code below to print sql query . you will see the collection is coming from flat table like
catalog_product_flat_38
echo Mage::getModel('catalog/product')->getCollection()->getSelect();
try using
Mage::app()->setCurrentStore('0');
// same as
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
this hepled me

How Can I Echo A Managed Attribute With An Object In Magento?

I am Again here with my learning problem in magento. I created a field in for my products Catalog/Attributes/Manage Attributes. Now I want to display this Field with the product Information. When I use This Code
$_product = new Mage_Catalog_Model_Product();
$_product->load($product->getId());
echo "<pre>"; print_r($_product->getDelivery());exit;
I am able to print other values like name by writing this :
echo "<pre>"; print_r($_product->getName());exit;
Can anyone tell me how can I print those attributes that i have added manually through Admin interface..
you can try and see what's inside
echo "<pre>"; print_r($_product->getData());exit;

Resources