magento adjust product visible - magento

I have 2 new custom productattributes that enables or disables a product in the category list and product-detail page.Both are dates.
need to calculate if the current date is between the 2 custom dates.
if it is, the product must be enabled.
I can't find a place in the code to enable/disable a product in the category list and detail page. I don't want to fix this in a phtml.
Can somebody help me?

You have to modify two things :
the product collection in order to add the filtering on your two news attributes.. For that, for example, you can implement the event catalog_block_product_list_collection from Mage_Catalog_Block_Product_List (used in product listing and search) where you'll add your filtering with the function $collection->addAttributeToFilter('attribute_code', $condition)
the product page itself. You can add your logic in order to display or not your product by multiple ways.. I would choose to implement the event catalog_product_is_salable_after in order to add your logic here and call $product->isSalable() in the template or controller...

Related

Magento show empty grouped product

I want tot display the grouped products in magento(version 1.9.1.1) even if they don't have a active simple product attached to them.
It's possible for me to view the grouped product on the frontend if i visit the product by using the direct url, but when I use the search form or check the category page I don't see the product.
If I activate the simple product that is associated to the grouped product the grouped product does appears in the category page and search form.
Thanks in advance!
This is due to a bug in Magento's grouped product price indexer (Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped).
The indexing process only takes into account grouped products that have simple products associated, see Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped Line 118:
if (!is_null($entityIds)) {
$select->where('l.product_id IN(?)', $entityIds);
}
This needs to be changed to
if (!is_null($entityIds)) {
$select->where('e.entity_id IN(?)', $entityIds);
}
to make it work. Also, the mass indexing of product prices (via admin interface or via shell) fixes the problem because the reindexAll() function of the named class does not limit to grouped products that have associated simple products either.
Please note that you shouldn't make those changes within the core file but overwrite the class instead.
The issue has also been reported to Magento.

How to remove information in Magento catalog, but only for specific product type

I am wondering how can I delete this two divs -
in Magento catalog, but only for specific product type. In short, I would like to have product type which would appear in catalog only with product-image and product-name, without - price, Out of stock, Add to Wishlist, Add to Compare.
It's possible to load different layout updates depending on loaded product type. You can see an example of how it's done in Magento for configurable products here: https://github.com/LokeyCoding/magento-mirror/blob/magento-1.7/app/design/frontend/base/default/layout/catalog.xml#L275-L287
It's possible because view action of product controller makes this to be executed: https://github.com/LokeyCoding/magento-mirror/blob/magento-1.7/app/code/core/Mage/Catalog/Helper/Product/View.php#L59-L60
You can change the design for any product from the admin.
You need to create a separate theme with a different product page which will have only the attributes you would like.
Then you can select the design for that specific product. Please see the screenshot, how you can change design for any product

Update magento price using custom attributes

I am a newbie to Magento Framework.
Can any one tell me how to add custom pricing to products based on custom attributes.
For example: I would not enter price or I will enter a dummy number for price in admin panel and other attributes like weight and type of item and category.
Based on the category, weight and type of item I want to calculate the actual price something
like price=weight*category+typeOfItem And also if there is any special price to the product it should also apply along with tier prices
I have created a custom module using Alan Storm's Blog but I am unable to override the pricing. Sometimes it works in the product listing page but never works with 'tier' price.
You might find it easier to use a configurable product for this, assuming you don't have a huge range of weights and products
Otherwise maybe look at overwriting the
getFinalPrice() method in the Mage_Catalog_Model_Product_Type_Price model.

Forward to configurable product when opening simple product

I have a Magento shop with 2 simple products
Great Red Cup
Great Blue Cup
and a configurable product
Great Cup
with those cups assigned.
The Red and Blue cups are visible in the search.
If the use clicks one of those simple products, the configurable product should be opened instead, but the right color should be preselected.
I am aware that a simple product can be assigned to multiple configurable products, so I would log an exception if two matching configurable products are found an just take the first one.
I think I have to catch the predispatch event of catalog/product/view and somehow replace the simple product by the configurable one.
How can I now pre-configure the right simple product one?
Is there an elegant solution for this?
I found a solution:
register observer on controller_action_predispatch_catalog_product_view
check if we have a simple product with a parent that is a configurable product
create a array that contains the configuration data of the simple product
pass this data to Mage::helper('catalog/product_view')->prepareAndRender() (third parameter)
stop dispatching by setting the FLAG_NO_DISPATCH on the front action
Full code is available in the Mestrona_ForwardToConfigurable module on github.
To preselect a simple product in a configurable product, the address of a simple product should look like this for example:
/mona-pullover-hoodlie.html#143=167&93=53
where
/mona-pullover-hoodlie.html - configurable product URL
143, 93 - attribute IDs
167, 53 - option IDs.
In order to change the URL of simple products, you can create a Plugin (Interceptor) for Magento\Catalog\Model\Product::getProductUrl(), where to generate the URL as in the example above.
Product selection using URL parameters from example above is already implemented in Magento out of the box.
I made VCT Simple Product URl module on Magento Marketplace that solves this problem with the choice of the first configurable product if there are several.
One idea would be to redirect to the configurable product if the simple products meets somes requirements :
have a new attribute "should_redirect_to_parent" to True (optionnal)
have at least a parent product (for that point, I let you follow the link of Alex)
ps: if you don't want to do a parent product lookup you could add a new attribute like "redirect_sku" or "redirect_product_id" in order to directly make a redirection on that product
For the redirection you should use the event catalog_controller_product_init_after and if the two previous conditions match you redirect the user to the configurable product.
ps: for performance optimisation, you could use instead the catalog_controller_product_init_before which would save an expansive and useless Product::load() but it requires that you build custom SQL queries to search for a parent product
Tell if you want some code examples

Magento: Layered Navigation by Price in Main Navigation

I have a category called "Price" in my main navigation which has every product in the system assigned to it. The main point of the category is when you view it you can use the price filter on the layered navigation to filter any product on the site by price.
What I would like to do is output the price filter as a sub menu on the main navigation so a user could see a drop down of the different price bands and press one and be taken to the category with the filter already set.
I had a plan to edit this function Mage_Catalog_Block_Navigation::_renderCategoryMenuItemHtml() and output this function Mage_Catalog_Model_Layer_Filter_Abstract::getItems() if the category was called "Price" but I cant see a way to get the filters to out put from the category i pass it.
Has anyone done something like this before that could point me in the right direction?
if i was you i'd be tempted to change the plan a bit.
magento menus can be avoided. you can create you category and render a custom block for a price based filter.
if you extend Mage_Catalog_Block_Layer_Filter_Price you can set your category and get most of the info.
probably the best thing might actually just be to build a little slider. it only has to go from the most expensive to cheapest price, or zero and then load the category list with price apllied.

Resources