Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_GoogleBase_Adminhtml_Googlebase_ItemsController
  • Mage_GoogleBase_Adminhtml_Googlebase_SelectionController
  • Mage_GoogleBase_Adminhtml_Googlebase_TypesController
  • Mage_GoogleBase_Block_Adminhtml_Captcha
  • Mage_GoogleBase_Block_Adminhtml_Items
  • Mage_GoogleBase_Block_Adminhtml_Items_Item
  • Mage_GoogleBase_Block_Adminhtml_Items_Product
  • Mage_GoogleBase_Block_Adminhtml_Store_Switcher
  • Mage_GoogleBase_Block_Adminhtml_Types
  • Mage_GoogleBase_Block_Adminhtml_Types_Edit
  • Mage_GoogleBase_Block_Adminhtml_Types_Edit_Attributes
  • Mage_GoogleBase_Block_Adminhtml_Types_Edit_Form
  • Mage_GoogleBase_Block_Adminhtml_Types_Grid
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_GoogleBase
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Adminhtml Google Base types mapping form block
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_GoogleBase
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: 
 35: class Mage_GoogleBase_Block_Adminhtml_Types_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
 36: {
 37:     protected function _prepareForm()
 38:     {
 39:         $form = new Varien_Data_Form();
 40: 
 41:         $itemType = $this->getItemType();
 42: 
 43:         $fieldset = $form->addFieldset('base_fieldset', array(
 44:             'legend'    => $this->__('Attribute Set and Item Type')
 45:         ));
 46: 
 47:         if ( !($targetCountry = $itemType->getTargetCountry()) ) {
 48:             $isoKeys = array_keys($this->_getCountriesArray());
 49:             $targetCountry = isset($isoKeys[0]) ? $isoKeys[0] : null;
 50:         }
 51:         $countrySelect = $fieldset->addField('select_target_country', 'select', array(
 52:             'label'     => $this->__('Target Country'),
 53:             'title'     => $this->__('Target Country'),
 54:             'name'      => 'target_country',
 55:             'required'  => true,
 56:             'options'   => $this->_getCountriesArray(),
 57:             'value'     => $targetCountry,
 58:         ));
 59:         if ($itemType->getTargetCountry()) {
 60:             $countrySelect->setDisabled(true);
 61:         }
 62: 
 63:         $attributeSetsSelect = $this->getAttributeSetsSelectElement($targetCountry)->setValue($itemType->getAttributeSetId());
 64:         if ($itemType->getAttributeSetId()) {
 65:             $attributeSetsSelect->setDisabled(true);
 66:         }
 67: 
 68:         $fieldset->addField('attribute_set', 'note', array(
 69:             'label'     => $this->__('Attribute Set'),
 70:             'title'     => $this->__('Attribute Set'),
 71:             'required'  => true,
 72:             'text'      => '<div id="attribute_set_select">' . $attributeSetsSelect->toHtml() . '</div>',
 73:         ));
 74: 
 75:         $itemTypesSelect = $this->getItemTypesSelectElement($targetCountry)->setValue($itemType->getGbaseItemtype());
 76:         if ($itemType->getGbaseItemtype()) {
 77:             $itemTypesSelect->setDisabled(true);
 78:         }
 79: 
 80:         $fieldset->addField('itemtype', 'note', array(
 81:             'label'     => $this->__('Google Base Item Type'),
 82:             'title'     => $this->__('Google Base Item Type'),
 83:             'required'  => true,
 84:             'text'      => '<div id="gbase_itemtype_select">' . $itemTypesSelect->toHtml() . '</div>',
 85:         ));
 86: 
 87:         $attributesBlock = $this->getLayout()
 88:             ->createBlock('googlebase/adminhtml_types_edit_attributes')
 89:             ->setTargetCountry($targetCountry);
 90:         if ($itemType->getId()) {
 91:             $attributesBlock->setAttributeSetId($itemType->getAttributeSetId())
 92:                 ->setGbaseItemtype($itemType->getGbaseItemtype())
 93:                 ->setAttributeSetSelected(true);
 94:         }
 95: 
 96:         $attributes = Mage::registry('attributes');
 97:         if (is_array($attributes) && count($attributes) > 0) {
 98:             $attributesBlock->setAttributesData($attributes);
 99:         }
100: 
101:         $fieldset->addField('attributes_box', 'note', array(
102:             'label'     => $this->__('Attributes Mapping'),
103:             'text'      => '<div id="attributes_details">' . $attributesBlock->toHtml() . '</div>',
104:         ));
105: 
106:         $form->addValues($itemType->getData());
107:         $form->setUseContainer(true);
108:         $form->setId('edit_form');
109:         $form->setMethod('post');
110:         $form->setAction($this->getSaveUrl());
111:         $this->setForm($form);
112:     }
113: 
114:     public function getAttributeSetsSelectElement($targetCountry)
115:     {
116:         $field = new Varien_Data_Form_Element_Select();
117:         $field->setName('attribute_set_id')
118:             ->setId('select_attribute_set')
119:             ->setForm(new Varien_Data_Form())
120:             ->addClass('required-entry')
121:             ->setValues($this->_getAttributeSetsArray($targetCountry));
122:         return $field;
123:     }
124: 
125:     public function getItemTypesSelectElement($targetCountry)
126:     {
127:         $field = new Varien_Data_Form_Element_Select();
128:         $field->setName('gbase_itemtype')
129:             ->setId('select_itemtype')
130:             ->setForm(new Varien_Data_Form())
131:             ->addClass('required-entry')
132:             ->setValues($this->_getGbaseItemTypesArray($targetCountry));
133:         return $field;
134:     }
135: 
136:     protected function _getCountriesArray()
137:     {
138:         $_allowed = Mage::getSingleton('googlebase/config')->getAllowedCountries();
139:         $result = array();
140:         foreach ($_allowed as $iso => $info) {
141:             $result[$iso] = $info['name'];
142:         }
143:         return $result;
144:     }
145: 
146:     protected function _getAttributeSetsArray($targetCountry)
147:     {
148:         $entityType = Mage::getModel('catalog/product')->getResource()->getEntityType();
149:         $collection = Mage::getResourceModel('eav/entity_attribute_set_collection')
150:             ->setEntityTypeFilter($entityType->getId());
151: 
152:         $ids = array();
153:         $itemType = $this->getItemType();
154:         if ( !($itemType instanceof Varien_Object && $itemType->getId()) ) {
155:             $typesCollection = Mage::getResourceModel('googlebase/type_collection')
156:                 ->addCountryFilter($targetCountry)
157:                 ->load();
158:             foreach ($typesCollection as $type) {
159:                 $ids[] = $type->getAttributeSetId();
160:             }
161:         }
162: 
163:         $result = array('' => '');
164:         foreach ($collection as $attributeSet) {
165:             if (!in_array($attributeSet->getId(), $ids)) {
166:                 $result[$attributeSet->getId()] = $attributeSet->getAttributeSetName();
167:             }
168:         }
169:         return $result;
170:     }
171: 
172:     protected function _getGbaseItemTypesArray($targetCountry)
173:     {
174:         $itemTypes = Mage::getModel('googlebase/service_feed')->getItemTypes($targetCountry);
175:         $result = array('' => '');
176:         foreach ($itemTypes as $type) {
177:             $result[$type->getId()] = $type->getName();
178:         }
179:         return $result;
180:     }
181: 
182:     public function getItemType()
183:     {
184:         return Mage::registry('current_item_type');
185:     }
186: 
187:     public function getSaveUrl()
188:     {
189:         return $this->getUrl('*/*/save', array('type_id' => $this->getItemType()->getId()));
190:     }
191: }
192: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0