Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - Display product and category body page for each design in admin

Tags:

php

magento

I need to identify the add to cart button and disabled it (js and php) based on product id(this is not the real aim of the question, the bold is the real one)
Since I haven't found any solution I have thought to let the admin press the button in the admin section dedicated tomy extension and capture the button information with js and then save them later.
To do so I would like to display the main body of the product page and the one of a category for each theme in the design section.
This is how I retrieve the themes and packages:

//Main package/theme
Mage::getStoreConfig('design/package/name')
//Reegex theme
$ob=unserialize(Mage::getStoreConfig('design/package/ua_regexp'));
foreach($ob as $key)
    echo $key['value'];


My main concern is about the bold part, is if it is possible? How do I do it?
Just to be clear: I need only the red rectangle: enter image description here
Above it there is the breadcrumbs and on the right the sidebar



MORE DETAILS
When the admin creates/edit a product, it can select or not the countries where the item can be selled.
What happens: when a page load the system check if the item is merchantable in the costumers country otherwise it removes the button.
Now this bring some problems:

  • Wide theme support: I'm not sure the button html is the same of the default one

  • In the same page can exist merchantable and not-merchantable products: identify the button of the correct item in the category page where there are multiple of them, to do so I check the button behaviour: usually it contains: /checkout/cart/ plus the product id in the onlick attribute or the button submits a form, I think that if the admin "shows" me what happens and, after an analysis, I will be able to identify the button and replace it using the id (secure) or class ( not so certain), since not all the stores use the default btn-cart class

  • Cache/FPC system that fetch the page: I don't know if they will catch the js that disable the button or if the customer has disbaled any script (probably it can't even use the site), however usualy the add to cart block is not cached by those programs (sometimes if the item is not available the button is hidden)

  • SEO problem: guest aren't forced to select a country, but I try to identify it with some external service using the ip, so probably it will also detect the bots as users, I don't know if it will be a problem (I don't think so), otherwise I have to use JS to do an AJAX call and then hide the button

I would like to avoid any edit to any template file and create a very simple way for the user to set up the module( click a button is less complicated than the whole procedure to create an attribute, the relatives options and associate it to the sets)

Basically: How can I display the product and category page in the backend?

like image 651
Razorphyn Avatar asked Apr 26 '15 08:04

Razorphyn


1 Answers

What about using next logic for removing button from product page:

  1. Add new attribute (for example: hide_button, type Yes/No) to products in Catalog > Attributes > Manage Attributes. By default it will be 'no', so all products has the button. Admin can set attribute to 'Yes' for needed products.

  2. Create observer which will catch catalog_product_load_after event:

    public function checkProduct(Varien_Event_Observer $observer){
        Mage::register('hide_button', $observer->getEvent()->getProduct()->getData('hide_button'));
    
        return $this;
    }
    
  3. Create observer which will catch controller_action_layout_generate_blocks_after event and inject your js code to all themes:

    public function injectScript(Varien_Event_Observer $observer){
        if (Mage::registry('hide_button' == 1) {
            $head = $observer->getEvent()->getLayout()->getBlock('head');
            $head->addItem('js', 'hide-button.js');
        }
    
        return $this;
    }
    
  4. Create file js/hide-button.js which will remove buttons with class 'btn-cart' from page:

    Event.observe(window, 'load', function() {
        $$("button.btn-cart").remove();
    });
    

I didn't test the code, it's just an idea.

like image 145
ToxaBes Avatar answered Oct 20 '22 06:10

ToxaBes