{"id":51680,"date":"2015-02-11T03:49:52","date_gmt":"2015-02-11T03:49:52","guid":{"rendered":"http:\/\/barrycarlyon.co.uk\/wordpress\/?p=51680"},"modified":"2015-02-11T03:49:52","modified_gmt":"2015-02-11T03:49:52","slug":"magento-the-missing-view-type","status":"publish","type":"post","link":"https:\/\/barrycarlyon.co.uk\/wordpress\/2015\/02\/11\/magento-the-missing-view-type\/","title":{"rendered":"Magento &#8211; The missing view type!"},"content":{"rendered":"<p>Magento has four options when it comes to display products on your e-commerce website:<\/p>\n<ol>\n<li>Not Visible Individually<\/li>\n<li>Catalog<\/li>\n<li>Search<\/li>\n<li>Catalog, Search<\/li>\n<\/ol>\n<p>Now, normally that about covers most use cases. But if you have configurable products it is somewhat more common place to set the children to <i>Not Visible Individually<\/i>.<\/p>\n<p>This is great and all, but what if you are using Google Shopping real-time attribute\/schema scraping which requires the Child to be visible individually to read those tags (and can be handy for direct to a page when SKU searching on the front end), and you don&#8217;t want the children to show in either your category or search grid pages?<\/p>\n<p>This is where an additional catalog visibility type comes in useful, and it is actually very straight forward to achieve!<\/p>\n<p>First setup a basic Magento module\/plugin, which I won&#8217;t bore you with the complete details of, but we are binding to a model of the Mage Catalog Module under a rewrite!<\/p>\n<p>Set up your<\/p>\n<pre>local\/Company\/Catalog\/etc\/config.xml<\/pre>\n<p>as follows:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot;?&gt;\r\n&lt;config&gt;\r\n    &lt;modules&gt;\r\n        &lt;Company_Catalog&gt;\r\n            &lt;version&gt;0.0.1&lt;\/version&gt;\r\n        &lt;\/Company_Catalog&gt;\r\n    &lt;\/modules&gt;\r\n    &lt;global&gt;\r\n        &lt;models&gt;\r\n            &lt;catalog&gt;\r\n                &lt;rewrite&gt;\r\n                    &lt;product_visibility&gt;Company_Catalog_Model_Product_Visibility&lt;\/product_visibility&gt;\r\n               &lt;\/rewrite&gt;\r\n            &lt;\/catalog&gt;\r\n        &lt;\/models&gt;\r\n    &lt;\/global&gt;\r\n&lt;\/config&gt;\r\n<\/pre>\n<p>Fairly straight forward here, setup a basic module and override Mage\/Catalog\/Product\/Visibility.<\/p>\n<p>Next setup the Model<\/p>\n<pre>local\/Company\/Catalog\/Model\/Product\/Visibility.php<\/pre>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass Company_Catalog_Model_Product_Visibility extends Mage_Catalog_Model_Product_Visibility {\r\n    const VISIBILITY_PAGE = 5;\r\n    \r\n    public function getVisibleInSiteIds()\r\n    {\r\n        return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH, self::VISIBILITY_PAGE);\r\n    }\r\n    \r\n    static public function getOptionArray()\r\n    {\r\n        return array(\r\n            self::VISIBILITY_NOT_VISIBLE=&gt; Mage::helper('catalog')-&gt;__('Not Visible Individually'),\r\n            self::VISIBILITY_IN_CATALOG =&gt; Mage::helper('catalog')-&gt;__('Catalog'),\r\n            self::VISIBILITY_IN_SEARCH  =&gt; Mage::helper('catalog')-&gt;__('Search'),\r\n            self::VISIBILITY_BOTH       =&gt; Mage::helper('catalog')-&gt;__('Catalog, Search'),\r\n            self::VISIBILITY_PAGE       =&gt; Mage::helper('catalog')-&gt;__('Own Page Only')\r\n        );\r\n    }\r\n    \r\n    \/**\r\n     * Retrieve all options\r\n     *\r\n     * @return array\r\n     *\/\r\n    static public function getAllOption()\r\n    {\r\n        $options = self::getOptionArray();\r\n        array_unshift($options, array('value'=&gt;'', 'label'=&gt;''));\r\n        return $options;\r\n    }\r\n    \r\n    \/**\r\n     * Retireve all options\r\n     *\r\n     * @return array\r\n     *\/\r\n    static public function getAllOptions()\r\n    {\r\n        $res = array();\r\n        $res&#x5B;] = array('value'=&gt;'', 'label'=&gt; Mage::helper('catalog')-&gt;__('-- Please Select --'));\r\n        foreach (self::getOptionArray() as $index =&gt; $value) {\r\n            $res&#x5B;] = array(\r\n               'value' =&gt; $index,\r\n               'label' =&gt; $value\r\n            );\r\n        }\r\n        return $res;\r\n    }\r\n    \r\n    \/**\r\n     * Retrieve option text\r\n     *\r\n     * @param int $optionId\r\n     * @return string\r\n     *\/\r\n    static public function getOptionText($optionId)\r\n    {\r\n        $options = self::getOptionArray();\r\n        return isset($options&#x5B;$optionId]) ? $options&#x5B;$optionId] : null;\r\n    }\r\n}\r\n<\/pre>\n<p>First of all we add a new Constant, logically named<\/p>\n<pre>VISIBILITY_PAGE<\/pre>\n<p>and we give it the next free &#8220;id&#8221; of 5. (Check core\/Mage\/Catalog\/Model\/Product\/Visibility.php for the base list).<\/p>\n<p>Next the <b>important<\/b> function<\/p>\n<pre>getVisibleInSiteIds<\/pre>\n<p>tells Magento which Products to allow to be shown individually, so we just add our constant to the array here.<\/p>\n<p>All the other functions deal with rendering the new Visibility type in the admin interface for editing products (as otherwise the parent functions are used and they can&#8217;t &#8220;see&#8221; the new visibility type).<\/p>\n<p>As per usual when you add\/edit a new module make sure to clear the cache accordingly!<\/p>\n<p>That is it all done, short and sweet!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento has four options when it comes to display products on your e-commerce website: Not Visible Individually Catalog Search Catalog, Search Now, normally that about covers most use cases. But if you have configurable products it is somewhat more common place to set the children to Not Visible Individually. This is great and all, but &hellip; <a href=\"https:\/\/barrycarlyon.co.uk\/wordpress\/2015\/02\/11\/magento-the-missing-view-type\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Magento &#8211; The missing view type!&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[88,198,299,45,307,27],"tags":[82,311,309,84,308,310],"class_list":["post-51680","post","type-post","status-publish","format-standard","hentry","category-code-geekery","category-code-snippets","category-fred-aldous","category-geekery","category-magento","category-work","tag-code","tag-ecommerce","tag-magento","tag-php","tag-simple","tag-visibility"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/posts\/51680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/comments?post=51680"}],"version-history":[{"count":9,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/posts\/51680\/revisions"}],"predecessor-version":[{"id":51696,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/posts\/51680\/revisions\/51696"}],"wp:attachment":[{"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/media?parent=51680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/categories?post=51680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/tags?post=51680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}