<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function get_calender_events() { $params = array(); /*Get current date*/ $current_date = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key = "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...
Adding new category attribute in Magento
In this article we would like to show you how to add a new custom category attribute. Let’s say, this attribute is needed to display some content on the category page. First of all, we need to create a new module for adding custom category attribute, we will call it “Custom Category Attribute”. Step 1. Create new module We should let Magento know about our new module. Initial configuration file is located in ‘app/etc/modules/Samrat_CustomCategoryAttribute.xml’. Samrat_CustomCategoryAttribute.xml
<?xml version="1.0"?>
<config>
<modules>
<Samrat_CustomCategoryAttribute>
<active>true</active>
<codePool>community</codePool>
</Samrat_CustomCategoryAttribute>
</modules>
</config>
It means that the module is active and it is located in the community code pool. Step 2. Configure module Module configuration file is located in ‘app/code/<code pool>/<name space>/<module name>/etc’ and its name is config.xml – note, that in our case this looks like ‘ app/code/community/Samrat/CustomCategoryAttribute/etc/config.xml’. config.xml
<?xml version="1.0"?>
<config>
<modules>
<Samrat_CustomCategoryAttribute>
<version>0.0.1</version>
</Samrat_CustomCategoryAttribute>
</modules>
<global>
<resources>
<add_category_attribute>
<setup>
<module>Samrat_CustomCategoryAttribute</module>
<class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</add_category_attribute>
<add_category_attribute_write>
<connection>
<use>core_write</use>
</connection>
</add_category_attribute_write>
<add_category_attribute_read>
<connection>
<use>core_read</use>
</connection>
</add_category_attribute_read>
</resources>
</global>
</config>
As you can see, configuration file is not large, there are two nodes only: module version and resources for install script. Install script helps us to create a new attribute. In the node <resources> we defined the class for our install script which will be used for the extension. Working with methods of this class helps to create, update, remove attribute (etc). And the node <add_category_attribute> says that script must be located in the folder with the same name (in our case path will be ‘app/code/community/Samrat/CustomCategoryAttribute/sql/add_category_attribute’) Step 3. Create attribute Another important thing is to create install script file in the folder ‘add_category_attribute’, and the file name depends on the module version, so it looks like ‘mysql4-install-x.x.x.php’, where x.x.x is the version of the module. mysql4-install-0.0.1.php
<?php
$this->startSetup();
$this->addAttribute('catalog_category', 'custom_attribute', array(
'group' => 'General',
'input' => 'textarea',
'type' => 'text',
'label' => 'Custom attribute',
'backend' => '',
'visible' => true,
'required' => false,
'wysiwyg_enabled' => true,
'visible_on_front' => true,
'is_html_allowed_on_front' => true,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
As a result, we created a new attribute in the category with label ‘Custom attribute ‘. This attribute is a text area and it must be visible on the frontend. Check this out! Step 4. Check result Here, let’s clear cache and after this, go to Manage Categories – in ‘General’ tab you will see a new attribute: ‘Custom attribute’.
to see the content from ‘Custom attribute’ on the frontend in the category page – you need to use the helper for reading attribute in the template of this page (‘app/design/frontend/<package> /<theme>/template/catalog/category/view.phtml’), check please the following code:
In this article we would like to show you how to add a new custom category attribute. Let’s say, this attribute is needed to display some content on the category page. First of all, we need to create a new module for adding custom category attribute, we will call it “Custom Category Attribute”. Step 1. Create new module We should let Magento know about our new module. Initial configuration file is located in ‘app/etc/modules/Samrat_CustomCategoryAttribute.xml’. Samrat_CustomCategoryAttribute.xml
<?xml version="1.0"?>
<config>
<modules>
<Samrat_CustomCategoryAttribute>
<active>true</active>
<codePool>community</codePool>
</Samrat_CustomCategoryAttribute>
</modules>
</config>
It means that the module is active and it is located in the community code pool. Step 2. Configure module Module configuration file is located in ‘app/code/<code pool>/<name space>/<module name>/etc’ and its name is config.xml – note, that in our case this looks like ‘ app/code/community/Samrat/CustomCategoryAttribute/etc/config.xml’. config.xml
<?xml version="1.0"?>
<config>
<modules>
<Samrat_CustomCategoryAttribute>
<version>0.0.1</version>
</Samrat_CustomCategoryAttribute>
</modules>
<global>
<resources>
<add_category_attribute>
<setup>
<module>Samrat_CustomCategoryAttribute</module>
<class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</add_category_attribute>
<add_category_attribute_write>
<connection>
<use>core_write</use>
</connection>
</add_category_attribute_write>
<add_category_attribute_read>
<connection>
<use>core_read</use>
</connection>
</add_category_attribute_read>
</resources>
</global>
</config>
As you can see, configuration file is not large, there are two nodes only: module version and resources for install script. Install script helps us to create a new attribute. In the node <resources> we defined the class for our install script which will be used for the extension. Working with methods of this class helps to create, update, remove attribute (etc). And the node <add_category_attribute> says that script must be located in the folder with the same name (in our case path will be ‘app/code/community/Samrat/CustomCategoryAttribute/sql/add_category_attribute’) Step 3. Create attribute Another important thing is to create install script file in the folder ‘add_category_attribute’, and the file name depends on the module version, so it looks like ‘mysql4-install-x.x.x.php’, where x.x.x is the version of the module. mysql4-install-0.0.1.php
<?php
$this->startSetup();
$this->addAttribute('catalog_category', 'custom_attribute', array(
'group' => 'General',
'input' => 'textarea',
'type' => 'text',
'label' => 'Custom attribute',
'backend' => '',
'visible' => true,
'required' => false,
'wysiwyg_enabled' => true,
'visible_on_front' => true,
'is_html_allowed_on_front' => true,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
As a result, we created a new attribute in the category with label ‘Custom attribute ‘. This attribute is a text area and it must be visible on the frontend. Check this out! Step 4. Check result Here, let’s clear cache and after this, go to Manage Categories – in ‘General’ tab you will see a new attribute: ‘Custom attribute’.
to see the content from ‘Custom attribute’ on the frontend in the category page – you need to use the helper for reading attribute in the template of this page (‘app/design/frontend/<package> /<theme>/template/catalog/category/view.phtml’), check please the following code:
<?php
if
(
$_customAttribute
=
$this
->getCurrentCategory()->getCustomAttribute()): ?>
<?php
echo
$_helper
->categoryAttribute(
$_category
,
$_customAttribute
,
'custom_attribute'
) ?>
<?php
endif
; ?>
Comments
Post a Comment