diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Captcha.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Captcha.php deleted file mode 100644 index 2472c242b50..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Captcha.php +++ /dev/null @@ -1,59 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Captcha extends Mage_Adminhtml_Block_Template -{ - - public function __construct() - { - parent::__construct(); - $this->setTemplate('googlebase/captcha.phtml'); - } - - public function getConfirmButtonHtml() - { - $confirmButton = $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( - 'label' => $this->__('Confirm'), - 'onclick' => "if($('user_confirm').value != '') - { - setLocation('" - . $this->getUrl('*/*/confirmCaptcha', array('_current'=>true)) - . "' + 'user_confirm/' + $('user_confirm').value + '/'); - }", - 'class' => 'task' - )); - return $confirmButton->toHtml(); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items.php deleted file mode 100644 index 64a652e80a9..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items.php +++ /dev/null @@ -1,79 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Items extends Mage_Adminhtml_Block_Widget_Grid_Container -{ - - public function __construct() - { - parent::__construct(); - $this->setTemplate('googlebase/items.phtml'); - } - - protected function _prepareLayout() - { - $this->setChild('item', $this->getLayout()->createBlock('googlebase/adminhtml_items_item')); - $this->setChild('product', $this->getLayout()->createBlock('googlebase/adminhtml_items_product')); - $this->setChild('store_switcher', $this->getLayout()->createBlock('googlebase/adminhtml_store_switcher')); - } - - public function getAddButtonHtml() - { - $addButtonData = array( - 'id' => 'products_grid_button', - 'label' => $this->__('View Available Products'), - ); - return $this->getLayout() - ->createBlock('adminhtml/widget_button') - ->setData($addButtonData) - ->toHtml(); - } - - public function getStoreSwitcherHtml() - { - return $this->getChildHtml('store_switcher'); - } - - public function getCaptchaHtml() - { - return $this->getLayout()->createBlock('googlebase/adminhtml_captcha') - ->setGbaseCaptchaToken($this->getGbaseCaptchaToken()) - ->setGbaseCaptchaUrl($this->getGbaseCaptchaUrl()) - ->toHtml(); - } - - public function getStore() - { - return $this->_getData('store'); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Item.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Item.php deleted file mode 100644 index 4705e71e8cc..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Item.php +++ /dev/null @@ -1,183 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Items_Item extends Mage_Adminhtml_Block_Widget_Grid -{ - public function __construct() - { - parent::__construct(); - $this->setId('items'); - $this->setUseAjax(true); - } - - protected function _prepareCollection() - { - $collection = Mage::getResourceModel('googlebase/item_collection'); - $store = $this->_getStore(); - $collection->addStoreFilterId($store->getId()); - $this->setCollection($collection); - parent::_prepareCollection(); - return $this; - } - - protected function _prepareColumns() - { - $this->addColumn('name', - array( - 'header' => $this->__('Product Name'), - 'width' => '30%', - 'index' => 'name', - )); - - $this->addColumn('gbase_item_id', - array( - 'header' => $this->__('Google Base ID'), - 'width' => '150px', - 'index' => 'gbase_item_id', - 'renderer' => 'googlebase/adminhtml_items_renderer_id', - - )); - - $this->addColumn('gbase_itemtype', - array( - 'header' => $this->__('Google Base Item Type'), - 'width' => '150px', - 'index' => 'gbase_itemtype', - )); - -// $this->addColumn('published', -// array( -// 'header'=> $this->__('Published'), -// 'type' => 'datetime', -// 'width' => '100px', -// 'index' => 'published', -// )); - - $this->addColumn('expires', - array( - 'header' => $this->__('Expires'), - 'type' => 'datetime', - 'width' => '100px', - 'index' => 'expires', - )); - - $this->addColumn('impr', - array( - 'header' => $this->__('Impr.'), - 'width' => '150px', - 'index' => 'impr', - 'filter' => false, - )); - - $this->addColumn('clicks', - array( - 'header' => $this->__('Clicks'), - 'width' => '150px', - 'index' => 'clicks', - 'filter' => false, - )); - - $this->addColumn('active', - array( - 'header' => $this->__('Active'), - 'type' => 'options', - 'width' => '70px', - 'options' => Mage::getSingleton('googlebase/source_statuses')->getStatuses(), - 'index' => 'is_hidden', - )); - - return parent::_prepareColumns(); - } - - protected function _prepareMassaction() - { - $this->setMassactionIdField('item_id'); - $this->getMassactionBlock()->setFormFieldName('item'); - $this->setNoFilterMassactionColumn(true); - - $this->getMassactionBlock()->addItem('delete', array( - 'label' => $this->__('Delete'), - 'url' => $this->getUrl('*/*/massDelete', array('_current' => true)), - 'confirm' => $this->__('Are you sure?') - )); - - $this->getMassactionBlock()->addItem('publish', array( - 'label' => $this->__('Publish'), - 'url' => $this->getUrl('*/*/massPublish', array('_current' => true)) - )); - - $this->getMassactionBlock()->addItem('unpublish', array( - 'label' => $this->__('Hide'), - 'url' => $this->getUrl('*/*/massHide', array('_current' => true)) - )); - - $this->getMassactionBlock()->addItem('refresh', array( - 'label' => $this->__('Synchronize'), - 'url' => $this->getUrl('*/*/refresh', array('_current' => true)), - 'confirm' => $this->__('This action will update items statistics and remove the items which are not available in Google Base. Continue?') - )); - return $this; - } - -// public function getSynchronizeButtonHtml() -// { -// $confirmMsg = $this->__('This action will update items statistics and remove the items which are not available in Google Base. Continue?'); -// -// $refreshButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button') -// ->setData(array( -// 'label' => $this->__('Synchronize'), -// 'onclick' => "if(confirm('".$confirmMsg."')) -// { -// setLocation('".$this->getUrl('*/*/refresh', array('_current'=>true))."'); -// }", -// 'class' => 'task' -// ))->toHtml(); -// -// return $refreshButtonHtml; -// } -// -// public function getMainButtonsHtml() -// { -// return $this->getSynchronizeButtonHtml() . parent::getMainButtonsHtml(); -// } - - public function getGridUrl() - { - return $this->getUrl('*/*/grid', array('_current' => true)); - } - - protected function _getStore() - { - return Mage::app()->getStore($this->getRequest()->getParam('store')); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Product.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Product.php deleted file mode 100644 index 40266e366a2..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Product.php +++ /dev/null @@ -1,167 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Items_Product extends Mage_Adminhtml_Block_Widget_Grid -{ - - public function __construct() - { - parent::__construct(); - $this->setId('googlebase_selection_search_grid'); - $this->setDefaultSort('id'); - $this->setUseAjax(true); - } - - protected function _beforeToHtml() - { - $this->setId($this->getId() . '_' . $this->getIndex()); - $this->getChild('reset_filter_button')->setData('onclick', $this->getJsObjectName() . '.resetFilter()'); - $this->getChild('search_button')->setData('onclick', $this->getJsObjectName() . '.doFilter()'); - return parent::_beforeToHtml(); - } - - protected function _prepareCollection() - { - $collection = Mage::getModel('catalog/product')->getCollection() - ->setStore($this->_getStore()) - ->addAttributeToSelect('name') - ->addAttributeToSelect('sku') - ->addAttributeToSelect('price') - ->addAttributeToSelect('attribute_set_id'); -// ->addFilterByRequiredOptions(); - - $store = $this->_getStore(); - if ($store->getId()) { - $collection->addStoreFilter($store); - } - - if ($excludeIds = $this->_getGoogleBaseProductIds()) { - $collection->addIdFilter($excludeIds, true); - } - - Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection); - - $this->setCollection($collection); - - return parent::_prepareCollection(); - } - - protected function _prepareColumns() - { - $this->addColumn('id', array( - 'header' => Mage::helper('sales')->__('ID'), - 'sortable' => true, - 'width' => '60px', - 'index' => 'entity_id' - )); - $this->addColumn('name', array( - 'header' => Mage::helper('sales')->__('Product Name'), - 'index' => 'name', - 'column_css_class'=> 'name' - )); - - $sets = Mage::getResourceModel('eav/entity_attribute_set_collection') - ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId()) - ->load() - ->toOptionHash(); - - $this->addColumn('type', - array( - 'header'=> Mage::helper('catalog')->__('Type'), - 'width' => '60px', - 'index' => 'type_id', - 'type' => 'options', - 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(), - )); - - $this->addColumn('set_name', - array( - 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'), - 'width' => '100px', - 'index' => 'attribute_set_id', - 'type' => 'options', - 'options' => $sets, - )); - - $this->addColumn('sku', array( - 'header' => Mage::helper('sales')->__('SKU'), - 'width' => '80px', - 'index' => 'sku', - 'column_css_class'=> 'sku' - )); - $this->addColumn('price', array( - 'header' => Mage::helper('sales')->__('Price'), - 'align' => 'center', - 'type' => 'currency', - 'currency_code' => $this->_getStore()->getCurrentCurrencyCode(), - 'rate' => $this->_getStore()->getBaseCurrency()->getRate($this->_getStore()->getCurrentCurrencyCode()), - 'index' => 'price' - )); - - return parent::_prepareColumns(); - } - - protected function _prepareMassaction() - { - $this->setMassactionIdField('product_id'); - $this->getMassactionBlock()->setFormFieldName('product'); - - $this->getMassactionBlock()->addItem('add', array( - 'label' => $this->__('Add to Google Base'), - 'url' => $this->getUrl('*/*/massAdd', array('_current' => true)), - )); - return $this; - } - - public function getGridUrl() - { - return $this->getUrl('*/googlebase_selection/grid', array('index' => $this->getIndex(), '_current' => true)); - } - - protected function _getGoogleBaseProductIds() - { - $collection = Mage::getResourceModel('googlebase/item_collection') - ->addStoreFilterId($this->_getStore()->getId()) - ->load(); - $productIds = array(); - foreach ($collection as $item) { - $productIds[] = $item->getProductId(); - } - return $productIds; - } - - protected function _getStore() - { - return Mage::app()->getStore($this->getRequest()->getParam('store')); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Renderer/Id.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Renderer/Id.php deleted file mode 100644 index efb1011589f..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Renderer/Id.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Items_Renderer_Id - extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract -{ - /** - * Renders Google Base Item Id - * - * @param Varien_Object $row - * @return string - */ - public function render(Varien_Object $row) - { - $baseUrl = 'http://www.google.com/merchants/view?docId='; - - $itemUrl = $row->getData($this->getColumn()->getIndex()); - $urlParts = parse_url($itemUrl); - if (isset($urlParts['path'])) { - $pathParts = explode('/', $urlParts['path']); - $itemId = $pathParts[count($pathParts) - 1]; - } else { - $itemId = $itemUrl; - } - $title = $this->__('View Item in Google Base'); - - return sprintf('%s', $baseUrl . $itemId, $title, $title, $itemId); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Store/Switcher.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Store/Switcher.php deleted file mode 100644 index 56ed554cb21..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Store/Switcher.php +++ /dev/null @@ -1,49 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Store_Switcher extends Mage_Adminhtml_Block_Store_Switcher -{ - /** - * @var bool - */ - protected $_hasDefaultOption = false; - - /** - * Set overriden params - */ - public function __construct() - { - parent::__construct(); - $this->setUseConfirm(false)->setSwitchUrl($this->getUrl('*/*/*', array('store' => null))); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types.php deleted file mode 100644 index 1ea2b7e30d8..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ - -class Mage_GoogleBase_Block_Adminhtml_Types extends Mage_Adminhtml_Block_Widget_Grid_Container -{ - public function __construct() - { - $this->_blockGroup = 'googlebase'; - $this->_controller = 'adminhtml_types'; - $this->_addButtonLabel = Mage::helper('googlebase')->__('Add Attribute Mapping'); - $this->_headerText = Mage::helper('googlebase')->__('Manage Attribute Mapping'); - parent::__construct(); - } - -// public function getGridHtml() -// { -// $_storeSwitcherHtml = $this->getLayout()->createBlock('googlebase/adminhtml_store_switcher')->toHtml(); -// return $_storeSwitcherHtml . parent::getGridHtml(); -// } -// -// public function getCreateUrl() -// { -// return $this->getUrl('*/*/new', array('_current'=>true)); -// } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit.php deleted file mode 100644 index c5bcc13c1cb..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit.php +++ /dev/null @@ -1,149 +0,0 @@ - - */ - -class Mage_GoogleBase_Block_Adminhtml_Types_Edit extends Mage_Adminhtml_Block_Widget_Form_Container -{ - public function __construct() - { - parent::__construct(); - $this->_blockGroup = 'googlebase'; - $this->_controller = 'adminhtml_types'; - $this->_mode = 'edit'; - $model = Mage::registry('current_item_type'); - $this->_removeButton('reset'); - $this->_updateButton('save', 'label', $this->__('Save Mapping')); - $this->_updateButton('save', 'id', 'save_button'); - $this->_updateButton('delete', 'label', $this->__('Delete Mapping')); - if(!$model->getId()) { - $this->_removeButton('delete'); - } - - $this->_formInitScripts[] = ' - var itemType = function() { - return { - updateAttributes: function() { - if ($("select_attribute_set").value != "" - && $("select_itemtype").value != "" - && itemType.confirmChanges() - ) { - var elements = [ - $("select_attribute_set"), - $("select_itemtype"), - $("select_target_country") - ].flatten(); - $(\'save_button\').disabled = true; - new Ajax.Updater("attributes_details", "' . $this->getUrl('*/*/loadAttributes') . '", - { - parameters:Form.serializeElements(elements), - evalScripts:true, - onComplete:function(){ $(\'save_button\').disabled = false; } - } - ); - } - }, - - reloadItemTypes: function() { - if ($("select_target_country").value != "" && itemType.confirmChanges()) - { - var elements = [ - $("select_attribute_set"), - $("select_itemtype"), - $("select_target_country") - ].flatten(); - new Ajax.Updater("gbase_itemtype_select", "' . $this->getUrl('*/*/loadItemTypes') . '", - { - parameters:Form.serializeElements(elements), - evalScripts:true, - onComplete:function(){ - $(\'save_button\').disabled = false; - Event.observe($("select_itemtype"), \'change\', itemType.updateAttributes); - } - } - ); - - new Ajax.Updater("attribute_set_select", "' . $this->getUrl('*/*/loadAttributeSets') . '", - { - parameters:Form.serializeElements(elements), - evalScripts:true, - onComplete:function(){ - $(\'save_button\').disabled = false; - Event.observe($("select_attribute_set"), \'change\', itemType.updateAttributes); - } - } - ); - $("attributes_details").innerHTML = "' . Mage::helper('core')->jsQuoteEscape($this->__('Please, select Attribute Set and Google Item Type to load attributes')) . '"; - } - }, - - confirmChanges: function() { - var blocksCount = Element.select($("attributes_details"), "div[id^=gbase_attribute_]").length; - if (blocksCount > 0 - && confirm(\'' . Mage::helper('core')->jsQuoteEscape($this->__('Current Mapping will be reloaded. Continue?')) .'\') - || blocksCount == 0 - ) { - return true; - } - return false; - } - } - }(); - - Event.observe(window, \'load\', function(){ - if ($("select_attribute_set")) { - Event.observe($("select_attribute_set"), \'change\', itemType.updateAttributes); - } - if ($("select_itemtype")) { - Event.observe($("select_itemtype"), \'change\', itemType.updateAttributes); - } - if ($("select_target_country")) { - Event.observe($("select_target_country"), \'change\', itemType.reloadItemTypes); - } - }); - '; - } - - public function getHeaderText() - { - if(!is_null(Mage::registry('current_item_type')->getId())) { - return $this->__('Edit Item Type "%s"', $this->escapeHtml(Mage::registry('current_item_type')->getGbaseItemtype())); - } else { - return $this->__('New Item Type'); - } - } - - public function getHeaderCssClass() { - return 'icon-head head-customer-groups'; - } - -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Attributes.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Attributes.php deleted file mode 100644 index 5b18f3e15b2..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Attributes.php +++ /dev/null @@ -1,140 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Types_Edit_Attributes extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element -{ - public function __construct() - { - $this->setTemplate('googlebase/types/edit/attributes.phtml'); - } - - protected function _prepareLayout() - { - $this->setChild('add_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( - 'label' => Mage::helper('googlebase')->__('Add New Attribute'), - 'class' => 'add', - 'id' => 'add_new_attribute', - 'on_click' => 'gBaseAttribute.add()' - )) - ); - $this->setChild('delete_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( - 'label' => Mage::helper('googlebase')->__('Remove'), - 'class' => 'delete delete-product-option', - 'on_click' => 'gBaseAttribute.remove(event)' - )) - ); - - parent::_prepareLayout(); - } - - public function getFieldId() - { - return 'gbase_attribute'; - } - - public function getFieldName () - { - return 'attributes'; - } - - public function getGbaseAttributesSelectHtml() - { - $options = array('' => $this->__('Custom attribute, no mapping')); - - $attributes = Mage::getModel('googlebase/service_feed') - ->getAttributes($this->getGbaseItemtype(), $this->getTargetCountry()); - foreach ($attributes as $attr) { - $options[$attr->getId()] = $attr->getName(); - } - - $select = $this->getLayout()->createBlock('adminhtml/html_select') - ->setId($this->getFieldId() . '_{{index}}_gattribute') - ->setName($this->getFieldName() . '[{{index}}][gbase_attribute]') - ->setOptions($options); - return $select->getHtml(); - } - - /** - * Build HTML select element of attribute set attributes - * - * @param boolean $escapeJsQuotes - * @return string - */ - public function getAttributesSelectHtml($escapeJsQuotes = false) - { - $select = $this->getLayout()->createBlock('adminhtml/html_select') - ->setId($this->getFieldId() . '_{{index}}_attribute') - ->setName($this->getFieldName() . '[{{index}}][attribute_id]') - ->setOptions($this->_getAttributes($this->getAttributeSetId(), $escapeJsQuotes)); - return $select->getHtml(); - } - - public function getAddButtonHtml() - { - return $this->getChildHtml('add_button'); - } - - public function getDeleteButtonHtml() - { - return $this->getChildHtml('delete_button'); - } - - /** - * Get attributes of an attribute set - * Skip attributes not needed for Google Base - * - * @param int $setId - * @param boolean $escapeJsQuotes - * @return array - */ - public function _getAttributes($setId, $escapeJsQuotes = false) - { - $attributes = Mage::getModel('googlebase/attribute')->getAllowedAttributes($setId); - $result = array(); - - foreach ($attributes as $attribute) { - /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ - $result[$attribute->getAttributeId()] = $escapeJsQuotes ? $this->jsQuoteEscape($attribute->getFrontendLabel()) : $attribute->getFrontendLabel(); - } - return $result; - } - - protected function _toJson($data) - { - return Mage::helper('core')->jsonEncode($data); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Form.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Form.php deleted file mode 100644 index 7db7e69d4c8..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Form.php +++ /dev/null @@ -1,191 +0,0 @@ - - */ - -class Mage_GoogleBase_Block_Adminhtml_Types_Edit_Form extends Mage_Adminhtml_Block_Widget_Form -{ - protected function _prepareForm() - { - $form = new Varien_Data_Form(); - - $itemType = $this->getItemType(); - - $fieldset = $form->addFieldset('base_fieldset', array( - 'legend' => $this->__('Attribute Set and Item Type') - )); - - if ( !($targetCountry = $itemType->getTargetCountry()) ) { - $isoKeys = array_keys($this->_getCountriesArray()); - $targetCountry = isset($isoKeys[0]) ? $isoKeys[0] : null; - } - $countrySelect = $fieldset->addField('select_target_country', 'select', array( - 'label' => $this->__('Target Country'), - 'title' => $this->__('Target Country'), - 'name' => 'target_country', - 'required' => true, - 'options' => $this->_getCountriesArray(), - 'value' => $targetCountry, - )); - if ($itemType->getTargetCountry()) { - $countrySelect->setDisabled(true); - } - - $attributeSetsSelect = $this->getAttributeSetsSelectElement($targetCountry)->setValue($itemType->getAttributeSetId()); - if ($itemType->getAttributeSetId()) { - $attributeSetsSelect->setDisabled(true); - } - - $fieldset->addField('attribute_set', 'note', array( - 'label' => $this->__('Attribute Set'), - 'title' => $this->__('Attribute Set'), - 'required' => true, - 'text' => '
' . $attributeSetsSelect->toHtml() . '
', - )); - - $itemTypesSelect = $this->getItemTypesSelectElement($targetCountry)->setValue($itemType->getGbaseItemtype()); - if ($itemType->getGbaseItemtype()) { - $itemTypesSelect->setDisabled(true); - } - - $fieldset->addField('itemtype', 'note', array( - 'label' => $this->__('Google Base Item Type'), - 'title' => $this->__('Google Base Item Type'), - 'required' => true, - 'text' => '
' . $itemTypesSelect->toHtml() . '
', - )); - - $attributesBlock = $this->getLayout() - ->createBlock('googlebase/adminhtml_types_edit_attributes') - ->setTargetCountry($targetCountry); - if ($itemType->getId()) { - $attributesBlock->setAttributeSetId($itemType->getAttributeSetId()) - ->setGbaseItemtype($itemType->getGbaseItemtype()) - ->setAttributeSetSelected(true); - } - - $attributes = Mage::registry('attributes'); - if (is_array($attributes) && count($attributes) > 0) { - $attributesBlock->setAttributesData($attributes); - } - - $fieldset->addField('attributes_box', 'note', array( - 'label' => $this->__('Attributes Mapping'), - 'text' => '
' . $attributesBlock->toHtml() . '
', - )); - - $form->addValues($itemType->getData()); - $form->setUseContainer(true); - $form->setId('edit_form'); - $form->setMethod('post'); - $form->setAction($this->getSaveUrl()); - $this->setForm($form); - } - - public function getAttributeSetsSelectElement($targetCountry) - { - $field = new Varien_Data_Form_Element_Select(); - $field->setName('attribute_set_id') - ->setId('select_attribute_set') - ->setForm(new Varien_Data_Form()) - ->addClass('required-entry') - ->setValues($this->_getAttributeSetsArray($targetCountry)); - return $field; - } - - public function getItemTypesSelectElement($targetCountry) - { - $field = new Varien_Data_Form_Element_Select(); - $field->setName('gbase_itemtype') - ->setId('select_itemtype') - ->setForm(new Varien_Data_Form()) - ->addClass('required-entry') - ->setValues($this->_getGbaseItemTypesArray($targetCountry)); - return $field; - } - - protected function _getCountriesArray() - { - $_allowed = Mage::getSingleton('googlebase/config')->getAllowedCountries(); - $result = array(); - foreach ($_allowed as $iso => $info) { - $result[$iso] = $info['name']; - } - return $result; - } - - protected function _getAttributeSetsArray($targetCountry) - { - $entityType = Mage::getModel('catalog/product')->getResource()->getEntityType(); - $collection = Mage::getResourceModel('eav/entity_attribute_set_collection') - ->setEntityTypeFilter($entityType->getId()); - - $ids = array(); - $itemType = $this->getItemType(); - if ( !($itemType instanceof Varien_Object && $itemType->getId()) ) { - $typesCollection = Mage::getResourceModel('googlebase/type_collection') - ->addCountryFilter($targetCountry) - ->load(); - foreach ($typesCollection as $type) { - $ids[] = $type->getAttributeSetId(); - } - } - - $result = array('' => ''); - foreach ($collection as $attributeSet) { - if (!in_array($attributeSet->getId(), $ids)) { - $result[$attributeSet->getId()] = $attributeSet->getAttributeSetName(); - } - } - return $result; - } - - protected function _getGbaseItemTypesArray($targetCountry) - { - $itemTypes = Mage::getModel('googlebase/service_feed')->getItemTypes($targetCountry); - $result = array('' => ''); - foreach ($itemTypes as $type) { - $result[$type->getId()] = $type->getName(); - } - return $result; - } - - public function getItemType() - { - return Mage::registry('current_item_type'); - } - - public function getSaveUrl() - { - return $this->getUrl('*/*/save', array('type_id' => $this->getItemType()->getId())); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Grid.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Grid.php deleted file mode 100644 index 537e70ae6bd..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Grid.php +++ /dev/null @@ -1,95 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Types_Grid extends Mage_Adminhtml_Block_Widget_Grid -{ - public function __construct() - { - parent::__construct(); - $this->setId('types_grid'); - $this->setSaveParametersInSession(true); - $this->setUseAjax(true); - } - - protected function _prepareCollection() - { - $collection = Mage::getResourceModel('googlebase/type_collection')->addItemsCount(); - $this->setCollection($collection); - parent::_prepareCollection(); - return $this; - } - - protected function _prepareColumns() - { - $this->addColumn('attribute_set_name', - array( - 'header' => $this->__('Attributes Set'), - 'index' => 'attribute_set_name', - )); - - $this->addColumn('gbase_itemtype', - array( - 'header' => $this->__('Google Base Item type'), - 'index' => 'gbase_itemtype', - )); - - $this->addColumn('target_country', - array( - 'header' => $this->__('Target Country'), - 'width' => '150px', - 'index' => 'target_country', - 'renderer' => 'googlebase/adminhtml_types_renderer_country', - 'filter' => false - )); - - $this->addColumn('items_total', - array( - 'header' => Mage::helper('catalog')->__('Total Qty Base Items'), - 'width' => '150px', - 'index' => 'items_total', - 'filter' => false - )); - - return parent::_prepareColumns(); - } - - public function getRowUrl($row) - { - return $this->getUrl('*/*/edit', array('id'=>$row->getId(), '_current'=>true)); - } - - public function getGridUrl() - { - return $this->getUrl('*/*/grid', array('_current'=>true)); - } -} diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Renderer/Country.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Renderer/Country.php deleted file mode 100644 index d59a750ffec..00000000000 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Renderer/Country.php +++ /dev/null @@ -1,49 +0,0 @@ - - */ -class Mage_GoogleBase_Block_Adminhtml_Types_Renderer_Country - extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract -{ - /** - * Renders Google Base Item Id - * - * @param Varien_Object $row - * @return string - */ - public function render(Varien_Object $row) - { - $iso = $row->getData($this->getColumn()->getIndex()); - return Mage::getSingleton('googlebase/config')->getCountryInfo($iso, 'name'); - } -} diff --git a/app/code/core/Mage/GoogleBase/Helper/Data.php b/app/code/core/Mage/GoogleBase/Helper/Data.php deleted file mode 100644 index fb22cd3867b..00000000000 --- a/app/code/core/Mage/GoogleBase/Helper/Data.php +++ /dev/null @@ -1,37 +0,0 @@ - - */ -class Mage_GoogleBase_Helper_Data extends Mage_Core_Helper_Abstract -{ -} diff --git a/app/code/core/Mage/GoogleBase/Model/Attribute.php b/app/code/core/Mage/GoogleBase/Model/Attribute.php deleted file mode 100644 index 661c49afa7f..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Attribute.php +++ /dev/null @@ -1,126 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Attribute extends Mage_Core_Model_Abstract -{ - /** - * Default ignored attribute codes - * - * @var array - */ - protected $_ignoredAttributeCodes = array( - 'custom_design','custom_design_from','custom_design_to','custom_layout_update', - 'gift_message_available','news_from_date','news_to_date','options_container', - 'price_view','sku_type' - ); - - /** - * Default ignored attribute types - * - * @var array - */ - protected $_ignoredAttributeTypes = array('hidden', 'media_image', 'image', 'gallery'); - - protected function _construct() - { - $this->_init('googlebase/attribute'); - } - - public function getAllowedAttributes($setId) - { - $attributes = Mage::getModel('catalog/product')->getResource() - ->loadAllAttributes() - ->getSortedAttributes($setId); - - $result = array(); - foreach ($attributes as $attribute) { - /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ - if ($attribute->isInSet($setId) && $this->_isAllowedAttribute($attribute)) { - $list[$attribute->getAttributeId()] = $attribute; - $titles[$attribute->getAttributeId()] = $attribute->getFrontendLabel(); - } - } - asort($titles); - $result = array(); - foreach ($titles as $attributeId => $label) { - $result[$attributeId] = $list[$attributeId]; - } - return $result; - } - - /** - * Check if attribute allowed - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param array $attributes - * @return boolean - */ - protected function _isAllowedAttribute($attribute) - { - return !in_array($attribute->getFrontendInput(), $this->_ignoredAttributeTypes) - && !in_array($attribute->getAttributeCode(), $this->_ignoredAttributeCodes) - && $attribute->getFrontendLabel() != ""; - } - - /** - * Return Google Base Attribute Type By Product Attribute - * - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @return string Google Base Attribute Type - */ - public function getGbaseAttributeType($attribute) - { - $typesMapping = array( -// 'date' => 'dateTime', - 'price' => 'floatUnit', - 'decimal' => 'numberUnit', - ); - if (isset($typesMapping[$attribute->getFrontendInput()])) { - return $typesMapping[$attribute->getFrontendInput()]; - } elseif (isset($typesMapping[$attribute->getBackendType()])) { - return $typesMapping[$attribute->getBackendType()]; - } else { - return Mage_GoogleBase_Model_Service_Item::DEFAULT_ATTRIBUTE_TYPE; - } - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Config.php b/app/code/core/Mage/GoogleBase/Model/Config.php deleted file mode 100644 index baf0678819e..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Config.php +++ /dev/null @@ -1,168 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Config extends Varien_Object -{ - /** - * Return config var - * - * @param string $key Var path key - * @param int $storeId Store View Id - * @return mixed - */ - public function getConfigData($key, $storeId = null) - { - if (!$this->hasData($key)) { - $value = Mage::getStoreConfig('google/googlebase/' . $key, $storeId); - $this->setData($key, $value); - } - return $this->getData($key); - } - - /** - * Google Account login - * - * @param int $storeId - * @return string - */ - public function getAccountLogin($storeId = null) - { - return $this->getConfigData('login', $storeId); - } - - /** - * Google Account password - * - * @param int $storeId - * @return string - */ - public function getAccountPassword($storeId = null) - { - return Mage::helper('core')->decrypt($this->getConfigData('password', $storeId)); - } - - /** - * Google Account type - * - * @param int $storeId - * @return string - */ - public function getAccountType($storeId = null) - { - return $this->getConfigData('account_type', $storeId); - } - - /** - * Google Account target country info - * - * @param int $storeId - * @return array - */ - public function getTargetCountryInfo($storeId = null) - { - return $this->getCountryInfo($this->getTargetCountry($storeId), null, $storeId); - } - - /** - * Google Account target country - * - * @param int $storeId - * @return string Two-letters country ISO code - */ - public function getTargetCountry($storeId = null) - { - return $this->getConfigData('target_country', $storeId); - } - - /** - * Google Account target currency (for target country) - * - * @param int $storeId - * @return string Three-letters currency ISO code - */ - public function getTargetCurrency($storeId = null) - { - $country = $this->getTargetCountry($storeId); - return $this->getCountryInfo($country, 'currency'); - } - - /** - * Check whether System Base currency equals Google Base target currency or not - * - * @param int $storeId - * @return boolean - */ - public function isValidBaseCurrencyCode($storeId = null) - { - return Mage::app()->getStore($storeId)->getBaseCurrencyCode() == $this->getTargetCurrency($storeId); - } - - /** - * Default Item Type for country - * - * @param int $storeId - * @return string - */ - public function getDefaultItemType($storeId = null) - { - $country = $this->getTargetCountry($storeId); - return $this->getCountryInfo($country, 'default_item_type'); - } - - /** - * Google Base supported countries - * - * @param int $storeId - * @return array - */ - public function getAllowedCountries($storeId = null) - { - return $this->getConfigData('allowed_countries', $storeId); - } - - /** - * Country info such as name, locale, language etc. - * - * @param string $iso two-letters country ISO code - * @param string $field If specified, return value for field - * @param int $storeId - * @return array|string - */ - public function getCountryInfo($iso, $field = null, $storeId = null) - { - $countries = $this->getAllowedCountries($storeId); - $country = isset($countries[$iso]) ? $countries[$iso] : null; - return is_null($field) ? $country : ( isset($country[$field]) ? $country[$field] : null ); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Item.php b/app/code/core/Mage/GoogleBase/Model/Item.php deleted file mode 100644 index d038157af77..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Item.php +++ /dev/null @@ -1,386 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Item extends Mage_Core_Model_Abstract -{ - const ATTRIBUTES_REGISTRY_KEY = 'gbase_attributes_registry'; - const TYPES_REGISTRY_KEY = 'gbase_types_registry'; - - protected function _construct() - { - parent::_construct(); - $this->_init('googlebase/item'); - } - - /** - * Return Service Item Instance - * - * @return Mage_GoogleBase_Model_Service_Item - */ - public function getServiceItem() - { - return Mage::getModel('googlebase/service_item')->setStoreId($this->getStoreId()); - } - - /** - * Target Country - * - * @return string Two-letters country ISO code - */ - public function getTargetCountry() - { - return Mage::getSingleton('googlebase/config')->getTargetCountry($this->getStoreId()); - } - - /** - * Save item to Google Base - * - * @return Mage_GoogleBase_Model_Item - */ - public function insertItem() - { - $this->_checkProduct() - ->_prepareProductObject(); - - $typeModel = $this->_getTypeModel(); - $this->getServiceItem() - ->setItem($this) - ->setObject($this->getProduct()) - ->setAttributeValues($this->_getAttributeValues()) - ->setItemType($typeModel->getGbaseItemtype()) - ->insert(); - $this->setTypeId($typeModel->getTypeId()); - return $this; - } - - /** - * Update Item data - * - * @return Mage_GoogleBase_Model_Item - */ - public function updateItem() - { - $this->_checkProduct() - ->_prepareProductObject(); - $this->loadByProduct($this->getProduct()); - if ($this->getId()) { - $typeModel = $this->_getTypeModel(); - $this->getServiceItem() - ->setItem($this) - ->setObject($this->getProduct()) - ->setAttributeValues($this->_getAttributeValues()) - ->setItemType($typeModel->getGbaseItemtype()) - ->update(); - } - return $this; - } - - /** - * Delete Item from Google Base - * - * @return Mage_GoogleBase_Model_Item - */ - public function deleteItem() - { - $this->getServiceItem()->setItem($this)->delete(); - return $this; - } - - /** - * Delete Item from Google Base - * - * @return Mage_GoogleBase_Model_Item - */ - public function hideItem() - { - $this->getServiceItem()->setItem($this)->hide(); - $this->setIsHidden(1); - $this->save(); - return $this; - } - - /** - * Delete Item from Google Base - * - * @return Mage_GoogleBase_Model_Item - */ - public function activateItem() - { - $this->getServiceItem()->setItem($this)->activate(); - $this->setIsHidden(0); - $this->save(); - return $this; - } - - /** - * Load Item Model by Product - * - * @param Mage_Catalog_Model_Product $product - * @return Mage_GoogleBase_Model_Item - */ - public function loadByProduct($product) - { - if (!$this->getProduct()) { - $this->setProduct($product); - } - $this->getResource()->loadByProduct($this); - return $this; - } - - /** - * Product Setter - * - * @param Mage_Catalog_Model_Product - * @return Mage_GoogleBase_Model_Item - */ - public function setProduct($product) - { - if (!($product instanceof Mage_Catalog_Model_Product)) { - Mage::throwException(Mage::helper('googlebase')->__('Invalid Product Model for Google Base Item')); - } - $this->setData('product', $product); - $this->setProductId($product->getId()); - $this->setStoreId($product->getStoreId()); - return $this; - } - - /** - * Check product instance - * - * @return Mage_GoogleBase_Model_Item - */ - protected function _checkProduct() - { - if (!($this->getProduct() instanceof Mage_Catalog_Model_Product)) { - Mage::throwException(Mage::helper('googlebase')->__('Invalid Product Model for Google Base Item')); - } - return $this; - } - - /** - * Copy Product object and assign additional data to the copy - * - * @return Mage_GoogleBase_Model_Item - */ - protected function _prepareProductObject() - { - $product = clone $this->getProduct(); - /* @var $product Mage_Catalog_Model_Product */ - $url = $product->getProductUrl(false); - if (!Mage::getStoreConfigFlag('web/url/use_store')) { - $urlInfo = parse_url($url); - $store = $product->getStore()->getCode(); - if (isset($urlInfo['query']) && $urlInfo['query'] != '') { - $url .= '&___store=' . $store; - } else { - $url .= '?___store=' . $store; - } - } - $product->setUrl($url) - ->setQuantity( $this->getProduct()->getStockItem()->getQty() ) - ->setImageUrl( Mage::helper('catalog/product')->getImageUrl($product) ); - $this->setProduct($product); - return $this; - } - - /** - * Return Product attribute values array - * - * @return array Product attribute values - */ - protected function _getAttributeValues() - { - $result = array(); - $productAttributes = $this->_getProductAttributes(); - - foreach ($this->_getAttributesCollection() as $attribute) { - - $attributeId = $attribute->getAttributeId(); - - if (isset($productAttributes[$attributeId])) { - $productAttribute = $productAttributes[$attributeId]; - - if ($attribute->getGbaseAttribute()) { - $name = $attribute->getGbaseAttribute(); - } else { - $name = $this->_getAttributeLabel($productAttribute, $this->getProduct()->getStoreId()); - } - - $value = $productAttribute->getGbaseValue(); - $type = Mage::getSingleton('googlebase/attribute')->getGbaseAttributeType($productAttribute); - - if ($name && $value && $type) { - $result[$name] = array( - 'value' => $value, - 'type' => $type - ); - } - } - } - return $result; - } - - /** - * Return Product Attribute Store Label - * - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @param int $storeId Store View Id - * @return string Attribute Store View Label or Attribute code - */ - protected function _getAttributeLabel($attribute, $storeId) - { - $frontendLabel = $attribute->getFrontend()->getLabel(); - if (is_array($frontendLabel)) { - $frontendLabel = array_shift($frontendLabel); - } - if (!$this->_translations) { - $moduleName = Mage_Catalog_Model_Entity_Attribute::MODULE_NAME; - $separator = Mage_Core_Model_Translate::SCOPE_SEPARATOR; - $this->_translations = Mage::getModel('core/translate_string') - ->load($moduleName . $separator . $frontendLabel) - ->getStoreTranslations(); - } - if (isset($this->_translations[$storeId])) { - return $this->_translations[$storeId]; - } else { - return $attribute->getAttributeCode(); - } - } - - /** - * Return Google Base Item Type Model for current Product Attribute Set - * - * @return Mage_GoogleBase_Model_Type - */ - protected function _getTypeModel() - { - $registry = Mage::registry(self::TYPES_REGISTRY_KEY); - $attributeSetId = $this->getProduct()->getAttributeSetId(); - if (is_array($registry) && isset($registry[$attributeSetId])) { - return $registry[$attributeSetId]; - } - $model = Mage::getModel('googlebase/type')->loadByAttributeSetId($attributeSetId, $this->getTargetCountry()); - $registry[$attributeSetId] = $model; - Mage::unregister(self::TYPES_REGISTRY_KEY); - Mage::register(self::TYPES_REGISTRY_KEY, $registry); - return $model; - } - - /** - * Return Product attributes array - * - * @return array Product attributes - */ - protected function _getProductAttributes() - { - $product = $this->getProduct(); - $attributes = $product->getAttributes(); - $result = array(); - foreach ($attributes as $attribute) { - $value = $attribute->getFrontend()->getValue($product); - if (is_string($value) && strlen($value) && $product->hasData($attribute->getAttributeCode())) { - $attribute->setGbaseValue($value); - $result[$attribute->getAttributeId()] = $attribute; - } - } - return $result; - } - - /** - * Get Product Media files info - * - * @return array Media files info - */ - protected function _getProductImages() - { - $product = $this->getProduct(); - $galleryData = $product->getData('media_gallery'); - - if (!isset($galleryData['images']) || !is_array($galleryData['images'])) { - return array(); - } - - $result = array(); - foreach ($galleryData['images'] as $image) { - $image['url'] = Mage::getSingleton('catalog/product_media_config') - ->getMediaUrl($image['file']); - $result[] = $image; - } - return $result; - } - - /** - * Return attribute collection for current Product Attribute Set - * - * @return Mage_GoogleBase_Model_Mysql4_Attribute_Collection - */ - protected function _getAttributesCollection() - { - $registry = Mage::registry(self::ATTRIBUTES_REGISTRY_KEY); - $attributeSetId = $this->getProduct()->getAttributeSetId(); - if (is_array($registry) && isset($registry[$attributeSetId])) { - return $registry[$attributeSetId]; - } - $collection = Mage::getResourceModel('googlebase/attribute_collection') - ->addAttributeSetFilter($attributeSetId, $this->getTargetCountry()) - ->load(); - $registry[$attributeSetId] = $collection; - Mage::unregister(self::ATTRIBUTES_REGISTRY_KEY); - Mage::register(self::ATTRIBUTES_REGISTRY_KEY, $registry); - return $collection; - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute.php deleted file mode 100644 index a3bd76bf789..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Mysql4_Attribute extends Mage_GoogleBase_Model_Resource_Attribute -{ -} diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute/Collection.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute/Collection.php deleted file mode 100644 index 0e002fe2c76..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute/Collection.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Mysql4_Attribute_Collection extends Mage_GoogleBase_Model_Resource_Attribute_Collection -{ -} diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Item.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Item.php deleted file mode 100644 index b96374e67f7..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Item.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Mysql4_Item extends Mage_GoogleBase_Model_Resource_Item -{ -} diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Item/Collection.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Item/Collection.php deleted file mode 100644 index 39c35a610f7..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Item/Collection.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Mysql4_Item_Collection extends Mage_GoogleBase_Model_Resource_Item_Collection -{ -} diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Type.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Type.php deleted file mode 100644 index 585b5d386ec..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Type.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Mysql4_Type extends Mage_GoogleBase_Model_Resource_Type -{ -} diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Type/Collection.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Type/Collection.php deleted file mode 100644 index 9f2f2e3ceb7..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Type/Collection.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Mysql4_Type_Collection extends Mage_GoogleBase_Model_Resource_Type_Collection -{ -} diff --git a/app/code/core/Mage/GoogleBase/Model/Observer.php b/app/code/core/Mage/GoogleBase/Model/Observer.php deleted file mode 100644 index 69b4cad4dcd..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Observer.php +++ /dev/null @@ -1,99 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Observer -{ - /** - * Update product item in Google Base - * - * @param Varien_Object $observer - * @return Mage_GoogleBase_Model_Observer - */ - public function saveProductItem($observer) - { - try { - $product = $observer->getEvent()->getProduct(); - if (Mage::getStoreConfigFlag('google/googlebase/observed', $product->getStoreId())) { - $collection = Mage::getResourceModel('googlebase/item_collection') - ->addProductFilterId($product->getId()) - ->load(); - foreach ($collection as $item) { - $product = Mage::getSingleton('catalog/product') - ->setStoreId($item->getStoreId()) - ->load($item->getProductId()); - Mage::getModel('googlebase/item')->setProduct($product)->updateItem(); - } - } - } catch (Exception $e) { - if (Mage::app()->getStore()->isAdmin()) { - Mage::getSingleton('adminhtml/session')->addNotice( - Mage::helper('googlebase')->__("Cannot update Google Base Item for Store '%s'", Mage::app()->getStore($item->getStoreId())->getName()) - ); - } else { - throw $e; - } - } - return $this; - } - - /** - * Delete product item from Google Base - * - * @param Varien_Object $observer - * @return Mage_GoogleBase_Model_Observer - */ - public function deleteProductItem($observer) - { - try { - $product = $observer->getEvent()->getProduct(); - if (Mage::getStoreConfigFlag('google/googlebase/observed', $product->getStoreId())) { - $collection = Mage::getResourceModel('googlebase/item_collection') - ->addProductFilterId($product->getId()) - ->load(); - foreach ($collection as $item) { - $item->deleteItem()->delete(); - } - } - } catch (Exception $e) { - if (Mage::app()->getStore()->isAdmin()) { - Mage::getSingleton('adminhtml/session')->addNotice( - Mage::helper('googlebase')->__("Cannot update Google Base Item for Store '%s'", Mage::app()->getStore($item->getStoreId())->getName()) - ); - } else { - throw $e; - } - } - return $this; - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Attribute.php b/app/code/core/Mage/GoogleBase/Model/Resource/Attribute.php deleted file mode 100644 index 5569dfaeb15..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Resource/Attribute.php +++ /dev/null @@ -1,46 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Resource_Attribute extends Mage_Core_Model_Resource_Db_Abstract -{ - /** - * Resource initialization - * - */ - protected function _construct() - { - $this->_init('googlebase/attributes', 'id'); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Attribute/Collection.php b/app/code/core/Mage/GoogleBase/Model/Resource/Attribute/Collection.php deleted file mode 100644 index 17d5ddd6749..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Resource/Attribute/Collection.php +++ /dev/null @@ -1,140 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Resource_Attribute_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract -{ - /** - * Whether to join attribute_set_id to attributes or not - * - * @var boolean - */ - protected $_joinAttributeSetFlag = true; - - /** - * Resource collection initialization - * - */ - protected function _construct() - { - $this->_init('googlebase/attribute'); - } - - /** - * Filter collection by attribute set id - * - * @param int $attributeSetId - * @param string $targetCountry - * @return Mage_GoogleBase_Model_Resource_Attribute_Collection - */ - public function addAttributeSetFilter($attributeSetId, $targetCountry) - { - if (!$this->getJoinAttributeSetFlag()) { - return $this; - } - $select = $this->getSelect(); - $select->where('attribute_set_id = ?', $attributeSetId); - $select->where('target_country = ?', $targetCountry); - return $this; - } - - /** - * Add type filter - * - * @param int $type_id - * @return Mage_GoogleBase_Model_Resource_Attribute_Collection - */ - public function addTypeFilter($type_id) - { - $this->getSelect()->where('main_table.type_id = ?', $type_id); - return $this; - } - - /** - * Load data - * - * @param boolean $printQuery - * @param boolean $logQuery - * @return Mage_GoogleBase_Model_Resource_Attribute_Collection - */ - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - if ($this->getJoinAttributeSetFlag()) { - $this->_joinAttributeSet(); - } - parent::load($printQuery, $logQuery); - return $this; - } - - /** - * Join attribute set - * - * @return Mage_GoogleBase_Model_Resource_Attribute_Collection - */ - protected function _joinAttributeSet() - { - $this->getSelect() - ->joinInner( - array('types'=>$this->getTable('googlebase/types')), - 'main_table.type_id=types.type_id', - array('attribute_set_id' => 'types.attribute_set_id', - 'target_country' => 'types.target_country') - ); - return $this; - } - - /** - * retrieve Flag - * - * @return boolean - */ - public function getJoinAttributeSetFlag() - { - return $this->_joinAttributeSetFlag; - } - - /** - * Set flag - * - * @param unknown_type $flag - * @return boolean - */ - public function setJoinAttributeSetFlag($flag) - { - return $this->_joinAttributeSetFlag = (bool)$flag; - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Item.php b/app/code/core/Mage/GoogleBase/Model/Resource/Item.php deleted file mode 100644 index 19582b8c3c1..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Resource/Item.php +++ /dev/null @@ -1,77 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Resource_Item extends Mage_Core_Model_Resource_Db_Abstract -{ - /** - * Resource initialization - * - */ - protected function _construct() - { - $this->_init('googlebase/items', 'item_id'); - } - - /** - * Load Item model by product - * - * @param Mage_GoogleBase_Model_Item $model - * @return Mage_GoogleBase_Model_Resource_Item - */ - public function loadByProduct($model) - { - if (!($model->getProduct() instanceof Varien_Object)) { - return $this; - } - - $product = $model->getProduct(); - $productId = $product->getId(); - $storeId = $model->getStoreId() ? $model->getStoreId() : $product->getStoreId(); - - $adapter = $this->_getReadAdapter(); - $select = $adapter->select(); - - if ($productId !== null) { - $select->from($this->getMainTable()) - ->where('product_id = ?', $productId) - ->where('store_id = ?', (int)$storeId); - - $data = $adapter->fetchRow($select); - $data = is_array($data) ? $data : array(); - $model->addData($data); - } - return $this; - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Item/Collection.php b/app/code/core/Mage/GoogleBase/Model/Resource/Item/Collection.php deleted file mode 100644 index b7303369d1e..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Resource/Item/Collection.php +++ /dev/null @@ -1,160 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Resource_Item_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract -{ - /** - * Resource collection initialization - * - */ - protected function _construct() - { - $this->_init('googlebase/item'); - } - - /** - * Init collection select - * - * @return Mage_GoogleBase_Model_Resource_Item_Collection - */ - protected function _initSelect() - { - parent::_initSelect(); - $this->_joinTables(); - return $this; - } - - /** - * @deprecated - * - * @param int $storeId - * @return Mage_GoogleBase_Model_Resource_Item_Collection - */ - public function addStoreFilterId($storeId) - { - return $this->addStoreFilter($storeId); - } - - /** - * Filter collection by specified store ids - * - * @param array|int $storeIds - * @return Mage_GoogleBase_Model_Resource_Item_Collection - */ - public function addStoreFilter($storeIds) - { - $this->getSelect()->where('main_table.store_id IN (?)', $storeIds); - return $this; - } - - /** - * Filter collection by product id - * - * @param int $productId - * @return Mage_GoogleBase_Model_Resource_Item_Collection - */ - public function addProductFilterId($productId) - { - $this->getSelect()->where('main_table.product_id=?', $productId); - return $this; - } - - /** - * Add field filter to collection - * - * @param string $field - * @param null|string|array $condition - * @return Mage_GoogleBase_Model_Resource_Item_Collection - */ - public function addFieldToFilter($field, $condition = null) - { - if ($field == 'name') { - $codeExpr = $this->getConnection()->getCheckSql('p.value IS NOT NULL', 'p.value', 'p_d.value'); - $conditionSql = $this->_getConditionSql($codeExpr, $condition); - $this->getSelect()->where($conditionSql, null, Varien_Db_Select::TYPE_CONDITION); - } else { - parent::addFieldToFilter($field, $condition); - } - return $this; - } - - /** - * Join product and type data - * - * @return Mage_GoogleBase_Model_Resource_Item_Collection - */ - protected function _joinTables() - { - $adapter = $this->getConnection(); - $entityType = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY); - $attribute = Mage::getModel('eav/config')->getAttribute($entityType->getEntityTypeId(), 'name'); - - $joinConditionDefault = $adapter->quoteInto('p_d.attribute_id=?', $attribute->getAttributeId()) . - $adapter->quoteInto(' AND p_d.store_id=?', 0) . ' AND main_table.product_id=p_d.entity_id'; - - $joinCondition = $adapter->quoteInto('p.attribute_id=?', $attribute->getAttributeId()) . - ' AND p.store_id=main_table.store_id AND main_table.product_id=p.entity_id'; - - $this->getSelect() - ->joinLeft( - array('p_d' => $attribute->getBackend()->getTable()), - $joinConditionDefault, - array() - ); - - $codeExpr = $adapter->getCheckSql('p.value IS NOT NULL', 'p.value', 'p_d.value'); - $this->getSelect() - ->joinLeft( - array('p' => $attribute->getBackend()->getTable()), - $joinCondition, - array('name' => $codeExpr) - ); - - $codeExpr = $adapter->getCheckSql( - 'types.gbase_itemtype IS NOT NULL', - 'types.gbase_itemtype', - $adapter->quote(Mage_GoogleBase_Model_Service_Item::DEFAULT_ITEM_TYPE) - ); - - $this->getSelect() - ->joinLeft( - array('types' => $this->getTable('googlebase/types')), - 'main_table.type_id=types.type_id', - array('gbase_itemtype' => $codeExpr) - ); - - return $this; - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Type.php b/app/code/core/Mage/GoogleBase/Model/Resource/Type.php deleted file mode 100644 index 0b78fdca025..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Resource/Type.php +++ /dev/null @@ -1,64 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Resource_Type extends Mage_Core_Model_Resource_Db_Abstract -{ - /** - * Resource initialization - * - */ - protected function _construct() - { - $this->_init('googlebase/types', 'type_id'); - } - - /** - * Return Type ID by Attribute Set Id and target country - * - * @param int $attributeSetId Attribute Set - * @param string $targetCountry Two-letters country ISO code - * @return int - */ - public function getTypeIdByAttributeSetId($attributeSetId, $targetCountry) - { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->from($this->getMainTable(), 'type_id') - ->where('attribute_set_id=?', $attributeSetId) - ->where('target_country=?', $targetCountry); - - return $adapter->fetchOne($select); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Type/Collection.php b/app/code/core/Mage/GoogleBase/Model/Resource/Type/Collection.php deleted file mode 100644 index c55a902a5e1..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Resource/Type/Collection.php +++ /dev/null @@ -1,108 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Resource_Type_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract -{ - /** - * Resource collection initialization - * - */ - protected function _construct() - { - $this->_init('googlebase/type'); - } - - /** - * Init collection select - * - * @return Mage_GoogleBase_Model_Resource_Type_Collection - */ - protected function _initSelect() - { - parent::_initSelect(); - $this->_joinAttributeSet(); - return $this; - } - - /** - * Add total count of Items for each type - * - * @return Mage_GoogleBase_Model_Resource_Type_Collection - */ - public function addItemsCount() - { - $innerSelect = $this->getConnection()->select() - ->from( - array('inner_items' => $this->getTable('googlebase/items')), - array('type_id', 'cnt' => new Zend_Db_Expr('COUNT(inner_items.item_id)')) - ) - ->group('inner_items.type_id'); - - $this->getSelect() - ->joinLeft( - array('items' => $innerSelect), - 'main_table.type_id=items.type_id', - array('items_total' => 'items.cnt')); - - return $this; - } - - /** - * Add country ISO filter to collection - * - * @param string $iso Two-letter country ISO code - * @return Mage_GoogleBase_Model_Resource_Type_Collection - */ - public function addCountryFilter($iso) - { - $this->getSelect()->where('target_country=?', $iso); - return $this; - } - - /** - * Join Attribute Set data - * - * @return Mage_GoogleBase_Model_Resource_Type_Collection - */ - protected function _joinAttributeSet() - { - $this->getSelect() - ->join( - array('a_set'=>$this->getTable('eav/attribute_set')), - 'main_table.attribute_set_id=a_set.attribute_set_id', - array('attribute_set_name' => 'a_set.attribute_set_name')); - return $this; - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Service.php b/app/code/core/Mage/GoogleBase/Model/Service.php deleted file mode 100644 index 8f24d138d55..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Service.php +++ /dev/null @@ -1,137 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Service extends Varien_Object -{ - /** - * Client instance identifier in registry - * - * @var string - */ - protected $_clientRegistryId = 'GBASE_HTTP_CLIENT'; - - /** - * Retutn Google Base Client Instance - * - * @return Zend_Http_Client - */ - public function getClient($storeId = null, $loginToken = null, $loginCaptcha = null) - { - $user = $this->getConfig()->getAccountLogin($storeId); - $pass = $this->getConfig()->getAccountPassword($storeId); - $type = $this->getConfig()->getAccountType($storeId); - - // Create an authenticated HTTP client - $errorMsg = Mage::helper('googlebase')->__('Unable to connect to Google Base. Please, check Account settings in configuration.'); - try { - if (! Mage::registry($this->_clientRegistryId)) { - $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, - Zend_Gdata_Gbase::AUTH_SERVICE_NAME, - null, - '', - $loginToken, $loginCaptcha, - Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, - $type - ); - $configTimeout = array('timeout' => 60); - $client->setConfig($configTimeout); - Mage::register($this->_clientRegistryId, $client); - } - } catch (Zend_Gdata_App_CaptchaRequiredException $e) { - throw $e; - } catch (Zend_Gdata_App_HttpException $e) { - Mage::throwException($errorMsg . Mage::helper('googlebase')->__('Error: %s', $e->getMessage())); - } catch (Zend_Gdata_App_AuthException $e) { - Mage::throwException($errorMsg . Mage::helper('googlebase')->__('Error: %s', $e->getMessage())); - } - - return Mage::registry($this->_clientRegistryId); - } - - /** - * Retutn Google Base Service Instance - * - * @return Zend_Gdata_Gbase - */ - public function getService($storeId = null) - { - if (!$this->_service) { - $service = $this->_connect($storeId); - $this->_service = $service; - } - return $this->_service; - } - - /** - * Retutn Google Base Anonymous Client Instance - * - * @return Zend_Gdata_Gbase - */ - public function getGuestService() - { - return new Zend_Gdata_Gbase(new Zend_Http_Client()); - } - - /** - * Google Base Config - * - * @return Mage_GoogleBase_Model_Config - */ - public function getConfig() - { - return Mage::getSingleton('googlebase/config'); - } - - /** - * Authorize Google Account - * - * @return Zend_Gdata_Gbase - */ - protected function _connect($storeId = null) - { - $client = $this->getClient($storeId); - $service = new Zend_Gdata_Gbase($client); - return $service; - } - - /** - * Get Dry Run mode - * - * @return boolean - */ - public function getDryRun() - { - return $this->getDataSetDefault('dry_run', false); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Service/Feed.php b/app/code/core/Mage/GoogleBase/Model/Service/Feed.php deleted file mode 100644 index fba54022e31..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Service/Feed.php +++ /dev/null @@ -1,192 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Service_Feed extends Mage_GoogleBase_Model_Service -{ - const ITEM_TYPES_LOCATION = 'http://www.google.com/base/feeds/itemtypes'; - const ITEMS_LOCATION = 'http://www.google.com/base/feeds/items'; - - /** - * Google Base Feed Instance - * - * @param string $location - * @param int $storeId Store Id - * @return Zend_Gdata_Feed - */ - public function getFeed($location = null, $storeId = null) - { - $query = new Zend_Gdata_Query($location); - return $this->getService($storeId)->getFeed($query); - } - - /** - * Retrieve Items Statistics - * - * @param string $id Google Base item ID - * (e.g. http://www.google.com/base/feeds/items/3613244304072139222 or 3613244304072139222) - * - * @param int $storeId Store Id - * @return array - */ - public function getItemStats($id, $storeId = null) - { - if (!stristr($id, 'http://')) { - $id = self::ITEMS_LOCATION . '/' . $id; - } - if (!strstr($id, '?')) { - $id = $id . '?content=attributes,meta'; - } elseif (!stristr($id, 'content=')) { - $id = $id . '&content=attributes,meta'; - } - try { - $entry = $this->getService($storeId)->getGbaseItemEntry($id); - return $this->_getEntryStats($entry); - } catch (Exception $e) { - return null; - } - } - - /** - * Return item stats array based on Zend Gdata Entry object - * - * @param Zend_Gdata_Gbase_ItemEntry $entry - * @return array - */ - protected function _getEntryStats($entry) - { - $result = $_stats = array(); - - $draft = 'no'; - if (is_object($entry->getControl()) && is_object($entry->getControl()->getDraft())) { - $draft = $entry->getControl()->getDraft()->getText(); - } - $result['draft'] = ($draft == 'yes' ? 1 : 0); - - $expirationDate = $entry->getGbaseAttribute('expiration_date'); - if (isset($expirationDate[0]) && is_object($expirationDate[0])) { - $result['expires'] = Mage::getSingleton('googlebase/service_item') - ->gBaseDate2DateTime($expirationDate[0]->getText()); - } - - $allAttributes = $entry->getExtensionElements(); - $elementsCount = count($allAttributes); - if($elementsCount) { - $statsElement = null; - for ($i = 0; $i < $elementsCount; $i++) { - /** - * @var $extAttribute Zend_Gdata_App_Extension_Element - */ - $extAttribute = $allAttributes[$i]; - if ((string)$extAttribute->rootElement == 'stats') { - $statsElement = $extAttribute; - break; - } - } - if ($statsElement) { - $_stats = $statsElement->getExtensionElements(); - } - $statsCount = count($_stats); - for ($i = 0; $i < $statsCount; $i++) { - /** - * @var $_currentElement Zend_Gdata_App_Extension_Element - */ - $_currentElement = $_stats[$i]; - $_currentAttributes = $_currentElement->getExtensionAttributes(); - if (isset($_currentAttributes['total']) && isset($_currentAttributes['total']['value'])) { - $result[(string)$_currentElement->rootElement] = $_currentAttributes['total']['value']; - } - } - } - return $result; - } - - /** - * Returns Google Base recommended Item Types - * - * @param string $targetCountry Two-letters country ISO code - * @return array - */ - public function getItemTypes($targetCountry) - { - $locale = Mage::getSingleton('googlebase/config')->getCountryInfo($targetCountry, 'locale'); - $location = self::ITEM_TYPES_LOCATION . '/' . $locale; - - $itemTypes = array(); - foreach ($this->getGuestService()->getFeed($location)->entries as $entry) { - if (isset($entry->extensionElements[1])) { // has attributes node? - $typeAttributes = $entry->extensionElements[1]->extensionElements; - if (is_array($typeAttributes) && !empty($typeAttributes)) { // only items with attributes allowed - $type = $entry->extensionElements[0]->text; - $item = new Varien_Object(); - $item->setId($type); - $item->setName($entry->title->text); - $item->setLocation($entry->id->text); - $itemTypes[$type] = $item; - - $attributes = array(); - foreach($typeAttributes as $attr) { - $name = $attr->extensionAttributes['name']['value']; - $type = $attr->extensionAttributes['type']['value']; - $attribute = new Varien_Object(); - $attribute->setId($name); - $attribute->setName($name); - $attribute->setType($type); - $attributes[$name] = $attribute; - } - ksort($attributes); - $item->setAttributes($attributes); - } - } - } - ksort($itemTypes); - $this->_itemTypes = $itemTypes; - return $itemTypes; - } - - /** - * Returns Google Base Attributes - * - * @param string $type Google Base Item Type - * @param string $targetCountry Two-letters country ISO code - * @return array - */ - public function getAttributes($type, $targetCountry) - { - $itemTypes = $this->getItemTypes($targetCountry); - if (isset($itemTypes[$type]) && $itemTypes[$type] instanceof Varien_Object) { - return $itemTypes[$type]->getAttributes(); - } - return array(); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Service/Item.php b/app/code/core/Mage/GoogleBase/Model/Service/Item.php deleted file mode 100644 index 5c85cf32b18..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Service/Item.php +++ /dev/null @@ -1,447 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Service_Item extends Mage_GoogleBase_Model_Service -{ - const DEFAULT_ITEM_TYPE = 'products'; - const DEFAULT_ATTRIBUTE_TYPE = 'text'; - - /** - * Object instance to populate entry data - * - * @var Varien_Object - */ - protected $_object = null; - - /** - * Item instance to update entry data - * - * @var Mage_GoogleBase_Model_Item - */ - protected $_item = null; - - /** - * $_object Setter - * - * @param Varien_Object $object - * @return Mage_GoogleBase_Model_Service_Item - */ - public function setObject($object) - { - $this->_object = $object; - return $this; - } - - /** - * $_object Getter - * - * @return Varien_Object - */ - public function getObject() - { - return $this->_object; - } - - /** - * $_item Setter - * - * @param Mage_GoogleBase_Model_Item $item - * @return Mage_GoogleBase_Model_Service_Item - */ - public function setItem($item) - { - $this->_item = $item; - return $this; - } - - /** - * $_item Getter - * - * @return Mage_GoogleBase_Model_Item - */ - public function getItem() - { - return $this->_item; - } - - /** - * Return Store level Service Instance - * - * @return Zend_Gdata_Gbase - */ - public function getService($storeId = null) - { - if ($storeId === null) { - $storeId = $this->getStoreId(); - } - return parent::getService($storeId); - } - - /** - * Insert Item into Google Base - * - * @return Zend_Gdata_Gbase_ItemEntry - */ - public function insert() - { - $this->_checkItem(); - $service = $this->getService(); - $entry = $service->newItemEntry(); - $this->setEntry($entry); - $this->_prepareEnrtyForSave(); - $this->getEntry()->setItemType($this->_getItemType()); - $entry = $service->insertGbaseItem($this->getEntry()); - $this->setEntry($entry); - $entryId = $this->getEntry()->getId(); - $published = $this->gBaseDate2DateTime($this->getEntry()->getPublished()->getText()); - $this->getItem() - ->setGbaseItemId($entryId) - ->setPublished($published); - - if ($expires = $this->_getAttributeValue('expiration_date')) { - $expires = $this->gBaseDate2DateTime($expires); - $this->getItem()->setExpires($expires); - } - } - - /** - * Update Item data in Google Base - * - * @return Zend_Gdata_Gbase_ItemEntry - */ - public function update() - { - $this->_checkItem(); - $service = $this->getService(); - $entry = $service->getGbaseItemEntry( $this->getItem()->getGbaseItemId() ); - $this->setEntry($entry); - $this->_prepareEnrtyForSave(); - $entry = $service->updateGbaseItem($this->getEntry()); - - } - - /** - * Delete Item from Google Base - * - * @return Zend_Gdata_Gbase_ItemFeed - */ - public function delete() - { - $this->_checkItem(); - - $service = $this->getService(); - $entry = $service->getGbaseItemEntry( $this->getItem()->getGbaseItemId() ); - return $service->deleteGbaseItem($entry, $this->getDryRun()); - } - - /** - * Hide item in Google Base - * - * @return Mage_GoogleBase_Model_Service_Item - */ - public function hide() - { - $this->_saveDraft(true); - return $this; - } - - /** - * Publish item in Google Base - * - * @return Mage_GoogleBase_Model_Service_Item - */ - public function activate() - { - $this->_saveDraft(false); - return $this; - } - - /** - * Update item Control property - * - * @param boolean Save as draft or not - * @return Mage_GoogleBase_Model_Service_Item - */ - protected function _saveDraft($yes = true) - { - $this->_checkItem(); - - $service = $this->getService(); - $entry = $service->getGbaseItemEntry( $this->getItem()->getGbaseItemId() ); - - $draftText = $yes ? 'yes' : 'no'; - $draft = $service->newDraft($draftText); - $control = $service->newControl($draft); - - $entry->setControl($control); - $entry->save(); - return $this; - } - - /** - * Prepare Entry data and attributes before saving in Google Base - * - * @return Mage_GoogleBase_Model_Service_Item - */ - protected function _prepareEnrtyForSave() - { - $object = $this->getObject(); - if (!($object instanceof Varien_Object)) { - Mage::throwException(Mage::helper('googlebase')->__('Object model is not specified to save Google Base entry.')); - } - - $this->_setUniversalData(); - - $attributes = $this->getAttributeValues(); - if (is_array($attributes) && count($attributes)) { - foreach ($attributes as $name => $data) { - - $name = $this->_normalizeString($name); - $value = isset($data['value']) ? $data['value'] : ''; - $type = isset($data['type']) && $data['type'] ? $data['type'] : self::DEFAULT_ATTRIBUTE_TYPE; - - $customSetter = '_setAttribute' . ucfirst($name); - if (method_exists($this, $customSetter)) { - $this->$customSetter($name, $value, $type); - } else { - $this->_setAttribute($name, $value, $type); - } - } - } - return $this; - } - - /** - * Remove characters and words not allowed by Google Base in title and content (description). - * - * (to avoid "Expected response code 200, got 400. - * Reason: There is a problem with the character encoding of this attribute") - * - * @param string $string - * @return string - */ - protected function _cleanAtomAttribute($string) - { - return Mage::helper('core/string') - ->substr(preg_replace('/[\pC¢€•—™°½]|shipping/ui', '', $string), 0, 3500); - } - - /** - * Assign values to universal attribute of entry - * - * @return Mage_GoogleBase_Model_Service_Item - */ - protected function _setUniversalData() - { - $service = $this->getService(); - $object = $this->getObject(); - $entry = $this->getEntry(); - $attributeValues = $this->getAttributeValues(); - - $this->_setAttribute('id', $object->getId() . '_' . $this->getStoreId(), 'text'); - - if (isset($attributeValues['title']['value'])) { - $titleText = $attributeValues['title']['value']; - unset($attributeValues['title']); // to prevent "Reason: Duplicate title" error - } elseif ($object->getName()) { - $titleText = $object->getName(); - } else { - $titleText = 'no title'; - } - $entry->setTitle($service->newTitle()->setText($this->_cleanAtomAttribute($titleText))); - - if ($object->getUrl()) { - $links = $entry->getLink(); - if (!is_array($links)) { - $links = array(); - } - $link = $service->newLink(); - $link->setHref($object->getUrl()); - $link->setRel('alternate'); - $link->setType('text/html'); - if ($object->getName()) { - $link->setTitle($object->getName()); - } - $links[0] = $link; - $entry->setLink($links); - } - - if (isset($attributeValues['description']['value'])) { - $descrText = $attributeValues['description']['value']; - unset($attributeValues['description']); // to prevent "Reason: Duplicate description" error - } elseif ($object->getDescription()) { - $descrText = $object->getDescription(); - } else { - $descrText = 'no description'; - } - $entry->setContent($service->newContent()->setText($this->_cleanAtomAttribute($descrText))); - - if (isset($attributeValues['price']['value']) && floatval($attributeValues['price']['value']) > 0) { - $price = $attributeValues['price']['value']; - } else { - $price = $object->getPrice(); - } - - $this->_setAttributePrice(false, $price); - - if ($object->getQuantity()) { - $quantity = $object->getQuantity() ? max(1, (int)$object->getQuantity()) : 1; - $this->_setAttribute('quantity', $quantity, 'int'); - } - - $targetCountry = $this->getConfig()->getTargetCountry($this->getStoreId()); - - if ($object->getData('image_url')) { - $this->_setAttribute('image_link', $object->getData('image_url'), 'url'); - } - - $this->_setAttribute('condition', 'new', 'text'); - $this->_setAttribute('target_country', $targetCountry, 'text'); - $this->_setAttribute('item_language', $this->getConfig()->getCountryInfo($targetCountry, 'language'), 'text'); - // set new 'attribute_values' with removed 'title' and/or 'description' keys to avoid 'duplicate' errors - $this->setAttributeValues($attributeValues); - - return $this; - } - - /** - * Set Google Base Item Attribute - * - * @param string $attribute Google Base attribute name - * @param string $value Google Base attribute value - * @param string $type Google Base attribute type - * - * @return Mage_GoogleBase_Model_Service_Item - */ - protected function _setAttribute($attribute, $value, $type = 'text') - { - $entry = $this->getEntry(); - $gBaseAttribute = $entry->getGbaseAttribute($attribute); - if (isset($gBaseAttribute[0]) && is_object($gBaseAttribute[0])) { - $gBaseAttribute[0]->text = $value; - } else { - $entry->addGbaseAttribute($attribute, $value, $type); - } - return $this; - } - - /** - * Custom setter for 'price' attribute - * - * @param string $attribute Google Base attribute name - * @param mixed $value Fload price value - * @param string $type Google Base attribute type - * - * @return Mage_GoogleBase_Model_Service_Item - */ - protected function _setAttributePrice($attribute, $value, $type = 'text') - { - if (!$this->getData('price_assigned')) { - $targetCountry = $this->getConfig()->getTargetCountry($this->getStoreId()); - $this->_setAttribute( - $this->getConfig()->getCountryInfo($targetCountry, 'price_attribute_name', $this->getStoreId()), - sprintf('%.2f', $value), - 'floatUnit' - ); - $this->setData('price_assigned', true); - } - } - - /** - * Return Google Base Item Attribute Value - * - * @param string $attribute Google Base attribute name - * @return string|null Attribute value - */ - protected function _getAttributeValue($attribute) - { - $entry = $this->getEntry(); - $attributeArr = $entry->getGbaseAttribute($attribute); - if (is_array($attributeArr) && is_object($attributeArr[0])) { - return $attributeArr[0]->getText(); - } - return null; - } - - /** - * Return assign item type or default item type - * - * @return string Google Base Item Type - */ - protected function _getItemType() - { - return $this->getItemType() - ? $this->getItemType() - : $this->getConfig()->getDefaultItemType($this->getStoreId()); - } - - /** - * Check Item Instance - * - * @return void - */ - protected function _checkItem() - { - if (!($this->getItem() instanceof Mage_GoogleBase_Model_Item)) { - Mage::throwException(Mage::helper('googlebase')->__('Item model is not specified to delete Google Base entry.')); - } - } - - /** - * Prepare Google Base attribute name before save - * - * @param string Attribute name - * @return string Normalized attribute name - */ - protected function _normalizeString($string) - { - return preg_replace('/\s+/', '_', $string); - -// $string = preg_replace('/([^a-z^0-9^_])+/','_',strtolower($string)); -// $string = preg_replace('/_{2,}/','_',$string); -// return trim($string,'_'); - } - - /** - * Convert Google Base date format to unix timestamp - * Ex. 2008-12-08T16:57:23Z -> 2008-12-08 16:57:23 - * - * @param string Google Base datetime - * @return int - */ - public function gBaseDate2DateTime($gBaseDate) - { - return Mage::getSingleton('core/date')->date(null, $gBaseDate); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Source/Accounttype.php b/app/code/core/Mage/GoogleBase/Model/Source/Accounttype.php deleted file mode 100644 index fc1b4ad9ce3..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Source/Accounttype.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Source_Accounttype -{ - public function toOptionArray() - { - return array( - array('value' => 'HOSTED_OR_GOOGLE', 'label' => Mage::helper('googlebase')->__('Hosted or Google')), - array('value' => 'GOOGLE', 'label' => Mage::helper('googlebase')->__('Google')), - array('value' => 'HOSTED', 'label' => Mage::helper('googlebase')->__('Hosted')) - ); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Source/Authtype.php b/app/code/core/Mage/GoogleBase/Model/Source/Authtype.php deleted file mode 100644 index cf71b7f75a3..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Source/Authtype.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Source_Authtype -{ - public function toOptionArray() - { - return array( - array('value' => 'authsub', 'label' => Mage::helper('googlebase')->__('AuthSub')), - array('value' => 'clientlogin', 'label' => Mage::helper('googlebase')->__('ClientLogin')) - ); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Source/Country.php b/app/code/core/Mage/GoogleBase/Model/Source/Country.php deleted file mode 100644 index 7a17c36faae..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Source/Country.php +++ /dev/null @@ -1,46 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Source_Country -{ - public function toOptionArray() - { - $_allowed = Mage::getSingleton('googlebase/config')->getAllowedCountries(); - $result = array(); - foreach ($_allowed as $iso => $info) { - $result[] = array('value' => $iso, 'label' => $info['name']); - } - return $result; - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Source/Statuses.php b/app/code/core/Mage/GoogleBase/Model/Source/Statuses.php deleted file mode 100644 index aff64ed9087..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Source/Statuses.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Source_Statuses -{ - public function getStatuses() - { - return array( - '0' => Mage::helper('googlebase')->__('Yes'), - '1' => Mage::helper('googlebase')->__('No') - ); - } -} diff --git a/app/code/core/Mage/GoogleBase/Model/Type.php b/app/code/core/Mage/GoogleBase/Model/Type.php deleted file mode 100644 index f80e6beb951..00000000000 --- a/app/code/core/Mage/GoogleBase/Model/Type.php +++ /dev/null @@ -1,63 +0,0 @@ - - */ -class Mage_GoogleBase_Model_Type extends Mage_Core_Model_Abstract -{ - protected function _construct() - { - $this->_init('googlebase/type'); - } - - /** - * Load type model by Attribute Set Id - * - * @param int $attributeSetId Attribute Set - * @param string $targetCountry Two-letters country ISO code - * @return Mage_GoogleBase_Model_Type - */ - public function loadByAttributeSetId($attributeSetId, $targetCountry) - { - $typeId = $this->getResource()->getTypeIdByAttributeSetId($attributeSetId, $targetCountry); - return $this->load($typeId); - } -} diff --git a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/ItemsController.php b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/ItemsController.php deleted file mode 100644 index 8f38a0ece71..00000000000 --- a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/ItemsController.php +++ /dev/null @@ -1,399 +0,0 @@ - -*/ -class Mage_GoogleBase_Adminhtml_Googlebase_ItemsController extends Mage_Adminhtml_Controller_Action -{ - protected function _initAction() - { - $this->loadLayout() - ->_setActiveMenu('catalog/googlebase/items') - ->_addBreadcrumb(Mage::helper('adminhtml')->__('Catalog'), Mage::helper('adminhtml')->__('Catalog')) - ->_addBreadcrumb(Mage::helper('adminhtml')->__('Google Base'), Mage::helper('adminhtml')->__('Google Base')); - return $this; - } - - public function indexAction() - { - $this->_title($this->__('Catalog')) - ->_title($this->__('Google base')) - ->_title($this->__('Manage Items')); - - if (0 === (int)$this->getRequest()->getParam('store')) { - $this->_redirect('*/*/', array('store' => Mage::app()->getAnyStoreView()->getId(), '_current' => true)); - return; - } - $contentBlock = $this->getLayout()->createBlock('googlebase/adminhtml_items')->setStore($this->_getStore()); - - if ($this->getRequest()->getParam('captcha_token') && $this->getRequest()->getParam('captcha_url')) { - $contentBlock->setGbaseCaptchaToken( - Mage::helper('core')->urlDecodeAndEscape($this->getRequest()->getParam('captcha_token')) - ); - $contentBlock->setGbaseCaptchaUrl( - Mage::helper('core')->urlDecodeAndEscape($this->getRequest()->getParam('captcha_url')) - ); - } - - if (!$this->_getConfig()->isValidBaseCurrencyCode($this->_getStore()->getId())) { - $_countryInfo = $this->_getConfig()->getTargetCountryInfo($this->_getStore()->getId()); - $this->_getSession()->addNotice( - $this->__("Base Currency should be set to %s for %s in system configuration. Otherwise item prices won't be correct in Google Base.",$_countryInfo['currency_name'],$_countryInfo['name']) - ); - } - - $this->_initAction() - ->_addBreadcrumb(Mage::helper('googlebase')->__('Items'), Mage::helper('googlebase')->__('Items')) - ->_addContent($contentBlock) - ->renderLayout(); - } - - public function gridAction() - { - $this->loadLayout(); - return $this->getResponse()->setBody( - $this->getLayout() - ->createBlock('googlebase/adminhtml_items_item') - ->setIndex($this->getRequest()->getParam('index')) - ->toHtml() - ); - } - - public function massAddAction() - { - $storeId = $this->_getStore()->getId(); - $productIds = $this->getRequest()->getParam('product', null); - - $totalAdded = 0; - - try { - if (is_array($productIds)) { - foreach ($productIds as $productId) { - $product = Mage::getSingleton('catalog/product') - ->setStoreId($storeId) - ->load($productId); - - if ($product->getId()) { - Mage::getModel('googlebase/item') - ->setProduct($product) - ->insertItem() - ->save(); - - $totalAdded++; - } - } - } - - if ($totalAdded > 0) { - $this->_getSession()->addSuccess( - $this->__('Total of %d product(s) have been added to Google Base.', $totalAdded) - ); - } elseif (is_null($productIds)) { - $this->_getSession()->addError($this->__('Session expired during export. Please revise exported products and repeat the process if necessary.')); - } else { - $this->_getSession()->addError($this->__('No products were added to Google Base')); - } - } catch (Zend_Gdata_App_CaptchaRequiredException $e) { - $this->_getSession()->addError($e->getMessage()); - $this->_redirectToCaptcha($e); - return; - } catch (Zend_Gdata_App_Exception $e) { - $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) ); - } catch (Exception $e) { - $this->_getSession()->addError($e->getMessage()); - } - - $this->_redirect('*/*/index', array('store'=>$storeId)); - } - - public function massDeleteAction() - { - $storeId = $this->_getStore()->getId(); - $itemIds = $this->getRequest()->getParam('item'); - - $totalDeleted = 0; - - try { - foreach ($itemIds as $itemId) { - $item = Mage::getModel('googlebase/item')->load($itemId); - if ($item->getId()) { - $item->deleteItem(); - $item->delete(); - $totalDeleted++; - } - } - if ($totalDeleted > 0) { - $this->_getSession()->addSuccess( - $this->__('Total of %d items(s) have been removed from Google Base.', $totalDeleted) - ); - } else { - $this->_getSession()->addError($this->__('No items were deleted from Google Base')); - } - } catch (Zend_Gdata_App_CaptchaRequiredException $e) { - $this->_getSession()->addError($e->getMessage()); - $this->_redirectToCaptcha($e); - return; - } catch (Zend_Gdata_App_Exception $e) { - $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) ); - } catch (Exception $e) { - $this->_getSession()->addError($e->getMessage()); - } - - $this->_redirect('*/*/index', array('store'=>$storeId)); - } - - public function massPublishAction() - { - $storeId = $this->_getStore()->getId(); - $itemIds = $this->getRequest()->getParam('item'); - - $totalPublished = 0; - - try { - if (!empty($itemIds) && is_array($itemIds)) { - foreach ($itemIds as $itemId) { - $item = Mage::getModel('googlebase/item')->load($itemId); - if ($item->getId()) { - $item->activateItem(); - $totalPublished++; - } - } - } - if ($totalPublished > 0) { - $this->_getSession()->addSuccess( - $this->__('Total of %d items(s) have been published.', $totalPublished) - ); - } else { - $this->_getSession()->addError($this->__('No items were published')); - } - } catch (Zend_Gdata_App_CaptchaRequiredException $e) { - $this->_getSession()->addError($e->getMessage()); - $this->_redirectToCaptcha($e); - return; - } catch (Zend_Gdata_App_Exception $e) { - $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) ); - } catch (Exception $e) { - $this->_getSession()->addError($e->getMessage()); - } - - $this->_redirect('*/*/index', array('store'=>$storeId)); - } - - public function massHideAction() - { - $storeId = $this->_getStore()->getId(); - $itemIds = $this->getRequest()->getParam('item'); - - $totalHidden = 0; - - try { - foreach ($itemIds as $itemId) { - $item = Mage::getModel('googlebase/item')->load($itemId); - if ($item->getId()) { - $item->hideItem(); - $totalHidden++; - } - } - if ($totalHidden > 0) { - $this->_getSession()->addSuccess( - $this->__('Total of %d items(s) have been saved as inactive items.', $totalHidden) - ); - } else { - $this->_getSession()->addError($this->__('No items were saved as inactive items')); - } - } catch (Zend_Gdata_App_CaptchaRequiredException $e) { - $this->_getSession()->addError($e->getMessage()); - $this->_redirectToCaptcha($e); - return; - } catch (Zend_Gdata_App_Exception $e) { - $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) ); - } catch (Exception $e) { - $this->_getSession()->addError($e->getMessage()); - } - - $this->_redirect('*/*/index', array('store'=>$storeId)); - } - - /** - * Update items statistics and remove the items which are not available in Google Base - */ - public function refreshAction() - { - $storeId = $this->_getStore()->getId(); - $totalUpdated = 0; - $totalDeleted = 0; - - try { - $itemIds = $this->getRequest()->getParam('item'); - foreach ($itemIds as $itemId) { - $item = Mage::getModel('googlebase/item')->load($itemId); - - $stats = Mage::getSingleton('googlebase/service_feed')->getItemStats($item->getGbaseItemId(), $storeId); - if ($stats === null) { - $item->delete(); - $totalDeleted++; - continue; - } - - if ($stats['draft'] != $item->getIsHidden()) { - $item->setIsHidden($stats['draft']); - } - - if (isset($stats['clicks'])) { - $item->setClicks($stats['clicks']); - } - - if (isset($stats['impressions'])) { - $item->setImpr($stats['impressions']); - } - - if (isset($stats['expires'])) { - $item->setExpires($stats['expires']); - } - - $item->save(); - $totalUpdated++; - } - - $this->_getSession()->addSuccess( - $this->__('Total of %d items(s) have been deleted; total of %d items(s) have been updated.', $totalDeleted, $totalUpdated) - ); - - } catch (Zend_Gdata_App_CaptchaRequiredException $e) { - $this->_getSession()->addError($e->getMessage()); - $this->_redirectToCaptcha($e); - return; - } catch (Zend_Gdata_App_Exception $e) { - $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) ); - } catch (Exception $e) { - $this->_getSession()->addError($e->getMessage()); - } - - $this->_redirect('*/*/index', array('store'=>$storeId)); - } - - public function confirmCaptchaAction() - { - $storeId = $this->_getStore()->getId(); - try { - Mage::getModel('googlebase/service')->getClient( - $storeId, - Mage::helper('core')->urlDecode($this->getRequest()->getParam('captcha_token')), - $this->getRequest()->getParam('user_confirm') - ); - $this->_getSession()->addSuccess($this->__('Captcha has been confirmed.')); - - } catch (Zend_Gdata_App_CaptchaRequiredException $e) { - $this->_getSession()->addError($this->__('Captcha confirmation error: %s', $e->getMessage())); - $this->_redirectToCaptcha($e); - return; - } catch (Zend_Gdata_App_Exception $e) { - $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) ); - } catch (Exception $e) { - $this->_getSession()->addError($this->__('Captcha confirmation error: %s', $e->getMessage())); - } - - $this->_redirect('*/*/index', array('store'=>$storeId)); - } - - /** - * Redirect user to Google Captcha challenge - * - * @param Zend_Gdata_App_CaptchaRequiredException $e - */ - protected function _redirectToCaptcha($e) - { - $this->_redirect('*/*/index', - array('store' => $this->_getStore()->getId(), - 'captcha_token' => Mage::helper('core')->urlEncode($e->getCaptchaToken()), - 'captcha_url' => Mage::helper('core')->urlEncode($e->getCaptchaUrl()) - ) - ); - } - - /** - * Get store object, basing on request - * - * @return Mage_Core_Model_Store - * @throws Mage_Core_Exception - */ - public function _getStore() - { - $store = Mage::app()->getStore((int)$this->getRequest()->getParam('store', 0)); - if ((!$store) || 0 == $store->getId()) { - Mage::throwException($this->__('Unable to select a Store View.')); - } - return $store; - } - - protected function _getConfig() - { - return Mage::getSingleton('googlebase/config'); - } - - protected function _isAllowed() - { - return Mage::getSingleton('admin/session')->isAllowed('catalog/googlebase/items'); - } - - /** - * Parse Exception Response Body - * - * @param string $message Exception message to parse - * @return string - */ - protected function _parseGdataExceptionMessage($message) - { - $result = array(); - foreach (explode("\n", $message) as $row) { - if (strip_tags($row) == $row) { - $result[] = $row; - continue; - } - - // parse not well-formatted xml - preg_match_all('/(reason|field|type)=\"([^\"]+)\"/', $row, $matches); - - if (is_array($matches) && count($matches) == 3) { - if (is_array($matches[1]) && count($matches[1]) > 0) { - $c = count($matches[1]); - for ($i = 0; $i < $c; $i++) { - if (isset($matches[2][$i])) { - $result[] = ucfirst($matches[1][$i]) . ': ' . $matches[2][$i]; - } - } - } - } - } - return implode(". ", $result); - } -} diff --git a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/SelectionController.php b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/SelectionController.php deleted file mode 100644 index 5852911792e..00000000000 --- a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/SelectionController.php +++ /dev/null @@ -1,57 +0,0 @@ - - */ -class Mage_GoogleBase_Adminhtml_Googlebase_SelectionController extends Mage_Adminhtml_Controller_Action -{ - public function searchAction() - { - return $this->getResponse()->setBody( - $this->getLayout() - ->createBlock('googlebase/adminhtml_items_product') - ->setIndex($this->getRequest()->getParam('index')) - ->setFirstShow(true) - ->toHtml() - ); - } - - public function gridAction() - { - $this->loadLayout(); - return $this->getResponse()->setBody( - $this->getLayout() - ->createBlock('googlebase/adminhtml_items_product') - ->setIndex($this->getRequest()->getParam('index')) - ->toHtml() - ); - } -} diff --git a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/TypesController.php b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/TypesController.php deleted file mode 100644 index 9a8f301c9ce..00000000000 --- a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/TypesController.php +++ /dev/null @@ -1,265 +0,0 @@ - -*/ -class Mage_GoogleBase_Adminhtml_Googlebase_TypesController extends Mage_Adminhtml_Controller_Action -{ - /** - * Dispatches controller_action_postdispatch_adminhtml Event (as not Adminhtml router) - */ - public function postDispatch() - { - parent::postDispatch(); - if ($this->getFlag('', self::FLAG_NO_POST_DISPATCH)) { - return; - } - Mage::dispatchEvent('controller_action_postdispatch_adminhtml', array('controller_action' => $this)); - } - - protected function _initItemType() - { - $this->_title($this->__('Catalog')) - ->_title($this->__('Google Base')) - ->_title($this->__('Manage Attributes')); - - Mage::register('current_item_type', Mage::getModel('googlebase/type')); - $typeId = $this->getRequest()->getParam('id'); - if (!is_null($typeId)) { - Mage::registry('current_item_type')->load($typeId); - } - } - - protected function _initAction() - { - $this->loadLayout() - ->_setActiveMenu('catalog/googlebase/types') - ->_addBreadcrumb(Mage::helper('adminhtml')->__('Catalog'), Mage::helper('adminhtml')->__('Catalog')) - ->_addBreadcrumb(Mage::helper('adminhtml')->__('Google Base'), Mage::helper('adminhtml')->__('Google Base')); - return $this; - } - - public function indexAction() - { - $this->_title($this->__('Catalog')) - ->_title($this->__('Google base')) - ->_title($this->__('Manage Attributes')); - - $this->_initAction() - ->_addBreadcrumb(Mage::helper('googlebase')->__('Item Types'), Mage::helper('googlebase')->__('Item Types')) - ->_addContent($this->getLayout()->createBlock('googlebase/adminhtml_types')) - ->renderLayout(); - } - - /** - * Grid for AJAX request - */ - public function gridAction() - { - $this->getResponse()->setBody( - $this->getLayout()->createBlock('googlebase/adminhtml_types_grid')->toHtml() - ); - } - - public function newAction() - { - try { - $this->_initItemType(); - - $this->_title($this->__('New ItemType')); - - $this->_initAction() - ->_addBreadcrumb(Mage::helper('googlebase')->__('New Item Type'), Mage::helper('adminhtml')->__('New Item Type')) - ->_addContent($this->getLayout()->createBlock('googlebase/adminhtml_types_edit')) - ->renderLayout(); - } catch (Exception $e) { - $this->_getSession()->addError($e->getMessage()); - $this->_redirect('*/*/index', array('store' => $this->_getStore()->getId())); - } - } - - public function editAction() - { - $this->_title($this->__('Catalog')) - ->_title($this->__('Google base')) - ->_title($this->__('Manage Attributes')); - - $id = $this->getRequest()->getParam('id'); - $model = Mage::getModel('googlebase/type'); - - try { - $result = array(); - if ($id) { - $model->load($id); - $collection = Mage::getResourceModel('googlebase/attribute_collection') - ->addTypeFilter($model->getTypeId()) - ->load(); - foreach ($collection as $attribute) { - $result[] = $attribute->getData(); - } - } - - $this->_title($this->__('Edit Item Type')); - - Mage::register('current_item_type', $model); - Mage::register('attributes', $result); - - $this->_initAction() - ->_addBreadcrumb($id ? Mage::helper('googlebase')->__('Edit Item Type') : Mage::helper('googlebase')->__('New Item Type'), $id ? Mage::helper('googlebase')->__('Edit Item Type') : Mage::helper('googlebase')->__('New Item Type')) - ->_addContent($this->getLayout()->createBlock('googlebase/adminhtml_types_edit')) - ->renderLayout(); - } catch (Exception $e) { - $this->_getSession()->addError($e->getMessage()); - $this->_redirect('*/*/index'); - } - } - - public function saveAction() - { - $typeModel = Mage::getModel('googlebase/type'); - $id = $this->getRequest()->getParam('type_id'); - if (!is_null($id)) { - $typeModel->load($id); - } - - try { - if ($typeModel->getId()) { - $collection = Mage::getResourceModel('googlebase/attribute_collection') - ->addTypeFilter($typeModel->getId()) - ->load(); - foreach ($collection as $attribute) { - $attribute->delete(); - } - } - $typeModel->setAttributeSetId($this->getRequest()->getParam('attribute_set_id')) - ->setGbaseItemtype($this->getRequest()->getParam('gbase_itemtype')) - ->setTargetCountry($this->getRequest()->getParam('target_country')) - ->save(); - - - $attributes = $this->getRequest()->getParam('attributes'); - if (is_array($attributes)) { - $typeId = $typeModel->getId(); - foreach ($attributes as $attrInfo) { - if (isset($attrInfo['delete']) && $attrInfo['delete'] == 1) { - continue; - } - Mage::getModel('googlebase/attribute') - ->setAttributeId($attrInfo['attribute_id']) - ->setGbaseAttribute($attrInfo['gbase_attribute']) - ->setTypeId($typeId) - ->save(); - } - } - - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('googlebase')->__('The item type has been saved.')); - } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - } - $this->_redirect('*/*/index', array('store' => $this->_getStore()->getId())); - } - - public function deleteAction () - { - try { - $id = $this->getRequest()->getParam('id'); - $model = Mage::getModel('googlebase/type'); - $model->load($id); - if ($model->getTypeId()) { - $model->delete(); - } - $this->_getSession()->addSuccess($this->__('Item Type was deleted')); - } catch (Exception $e) { - $this->_getSession()->addError($e->getMessage()); - } - $this->_redirect('*/*/index', array('store' => $this->_getStore()->getId())); - } - - public function loadAttributesAction () - { - try { - $this->getResponse()->setBody( - $this->getLayout()->createBlock('googlebase/adminhtml_types_edit_attributes') - ->setAttributeSetId($this->getRequest()->getParam('attribute_set_id')) - ->setGbaseItemtype($this->getRequest()->getParam('gbase_itemtype')) - ->setTargetCountry($this->getRequest()->getParam('target_country')) - ->setAttributeSetSelected(true) - ->toHtml() - ); - } catch (Exception $e) { - // just need to output text with error - $this->_getSession()->addError($e->getMessage()); - } - } - - public function loadItemTypesAction() - { - try { - $this->getResponse()->setBody( - $this->getLayout()->getBlockSingleton('googlebase/adminhtml_types_edit_form') - ->getItemTypesSelectElement($this->getRequest()->getParam('target_country')) - ->toHtml() - ); - } catch (Exception $e) { - // just need to output text with error - $this->_getSession()->addError($e->getMessage()); - } - } - - protected function loadAttributeSetsAction() - { - try { - $this->getResponse()->setBody( - $this->getLayout()->getBlockSingleton('googlebase/adminhtml_types_edit_form') - ->getAttributeSetsSelectElement($this->getRequest()->getParam('target_country')) - ->toHtml() - ); - } catch (Exception $e) { - // just need to output text with error - $this->_getSession()->addError($e->getMessage()); - } - } - - public function _getStore() - { - $storeId = (int) $this->getRequest()->getParam('store', 0); - if ($storeId == 0) { - return Mage::app()->getAnyStoreView(); - } - return Mage::app()->getStore($storeId); - } - - protected function _isAllowed() - { - return Mage::getSingleton('admin/session')->isAllowed('catalog/googlebase/types'); - } -} diff --git a/app/code/core/Mage/GoogleBase/controllers/ItemsController.php b/app/code/core/Mage/GoogleBase/controllers/ItemsController.php deleted file mode 100644 index ecc8adb8416..00000000000 --- a/app/code/core/Mage/GoogleBase/controllers/ItemsController.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @deprecated after 1.4.2.0 Mage_GoogleBase_Adminhtml_Googlebase_ItemsController is used -*/ -class Mage_GoogleBase_ItemsController extends Mage_GoogleBase_Adminhtml_Googlebase_ItemsController -{ - -} diff --git a/app/code/core/Mage/GoogleBase/controllers/SelectionController.php b/app/code/core/Mage/GoogleBase/controllers/SelectionController.php deleted file mode 100644 index 3ba1b0bb17e..00000000000 --- a/app/code/core/Mage/GoogleBase/controllers/SelectionController.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @deprecated after 1.4.2.0 Mage_GoogleBase_Adminhtml_Googlebase_SelectionController is used - */ -class Mage_GoogleBase_SelectionController extends Mage_GoogleBase_Adminhtml_Googlebase_SelectionController -{ - -} diff --git a/app/code/core/Mage/GoogleBase/controllers/TypesController.php b/app/code/core/Mage/GoogleBase/controllers/TypesController.php deleted file mode 100644 index 29c43444124..00000000000 --- a/app/code/core/Mage/GoogleBase/controllers/TypesController.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @deprecated after 1.4.2.0 Mage_GoogleBase_Adminhtml_Googlebase_TypesController is used -*/ -class Mage_GoogleBase_TypesController extends Mage_GoogleBase_Adminhtml_Googlebase_TypesController -{ - -} diff --git a/app/code/core/Mage/GoogleBase/etc/adminhtml.xml b/app/code/core/Mage/GoogleBase/etc/adminhtml.xml deleted file mode 100644 index b957c659764..00000000000 --- a/app/code/core/Mage/GoogleBase/etc/adminhtml.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/code/core/Mage/GoogleBase/etc/config.xml b/app/code/core/Mage/GoogleBase/etc/config.xml deleted file mode 100644 index b1cf3995471..00000000000 --- a/app/code/core/Mage/GoogleBase/etc/config.xml +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - 1.6.0.0 - - - - - - Mage_GoogleBase_Model - googlebase_resource - - - Mage_GoogleBase_Model_Resource - googlebase_mysql4 - - - googlebase_types
-
- - googlebase_items
-
- - googlebase_attributes
-
-
-
-
- - - Mage_GoogleBase_Helper - - - - - - Mage_GoogleBase - - - - - - Mage_GoogleBase_Block - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/app/code/core/Mage/GoogleBase/etc/system.xml b/app/code/core/Mage/GoogleBase/etc/system.xml deleted file mode 100644 index 70b6651c5a1..00000000000 --- a/app/code/core/Mage/GoogleBase/etc/system.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/install-1.6.0.0.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/install-1.6.0.0.php deleted file mode 100644 index a867414f557..00000000000 --- a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/install-1.6.0.0.php +++ /dev/null @@ -1,168 +0,0 @@ - - */ -$installer = $this; -/* @var $installer Mage_Core_Model_Resource_Setup */ - -$installer->startSetup(); - -/** - * Create table 'googlebase/types' - */ -$table = $installer->getConnection() - ->newTable($installer->getTable('googlebase/types')) - ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( - 'identity' => true, - 'unsigned' => true, - 'nullable' => false, - 'primary' => true, - ), 'Type id') - ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( - 'unsigned' => true, - 'nullable' => false, - ), 'Attribute set id') - ->addColumn('gbase_itemtype', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( - 'nullable' => false, - ), 'Google base item type') - ->addColumn('target_country', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( - 'nullable' => false, - 'default' => 'US', - ), 'Target country') - ->addIndex($installer->getIdxName('googlebase/types', array('attribute_set_id')), - array('attribute_set_id')) - ->addForeignKey($installer->getFkName('googlebase/types', 'attribute_set_id', 'eav/attribute_set', 'attribute_set_id'), - 'attribute_set_id', $installer->getTable('eav/attribute_set'), 'attribute_set_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) - ->setComment('Google Base Item Types link Attribute Sets'); -$installer->getConnection()->createTable($table); - -/** - * Create table 'googlebase/items' - */ -$table = $installer->getConnection() - ->newTable($installer->getTable('googlebase/items')) - ->addColumn('item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( - 'identity' => true, - 'unsigned' => true, - 'nullable' => false, - 'primary' => true, - ), 'Item id') - ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - ), 'Type id') - ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( - 'unsigned' => true, - 'nullable' => false, - ), 'Product id') - ->addColumn('gbase_item_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( - 'nullable' => false, - ), 'Google base item id') - ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( - 'unsigned' => true, - 'nullable' => false, - ), 'Store Id') - ->addColumn('published', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( - 'nullable' => false, - ), 'Published') - ->addColumn('expires', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( - 'nullable' => false, - ), 'Expires') - ->addColumn('impr', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - ), 'Google impressions') - ->addColumn('clicks', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - ), 'Google clicks') - ->addColumn('views', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - ), 'Google views') - ->addColumn('is_hidden', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( - 'nullable' => false, - 'default' => '0', - ), 'Hidden flag') - ->addIndex($installer->getIdxName('googlebase/items', array('product_id')), - array('product_id')) - ->addIndex($installer->getIdxName('googlebase/items', array('store_id')), - array('store_id')) - ->addForeignKey($installer->getFkName('googlebase/items', 'product_id', 'catalog/product', 'entity_id'), - 'product_id', $installer->getTable('catalog/product'), 'entity_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) - ->addForeignKey($installer->getFkName('googlebase/items', 'store_id', 'core/store', 'store_id'), - 'store_id', $installer->getTable('core/store'), 'store_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) - ->setComment('Google Base Items Products'); -$installer->getConnection()->createTable($table); - -/** - * Create table 'googlebase/attributes' - */ -$table = $installer->getConnection() - ->newTable($installer->getTable('googlebase/attributes')) - ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( - 'identity' => true, - 'unsigned' => true, - 'nullable' => false, - 'primary' => true, - ), 'Id') - ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( - 'unsigned' => true, - 'nullable' => false, - ), 'Attribute id') - ->addColumn('gbase_attribute', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( - ), 'Google base attribute') - ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( - 'unsigned' => true, - 'nullable' => false, - ), 'Type id') - ->addIndex($installer->getIdxName('googlebase/attributes', array('attribute_id')), - array('attribute_id')) - ->addIndex($installer->getIdxName('googlebase/attributes', array('type_id')), - array('type_id')) - ->addForeignKey($installer->getFkName('googlebase/attributes', 'attribute_id', 'eav/attribute', 'attribute_id'), - 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) - ->addForeignKey($installer->getFkName('googlebase/attributes', 'type_id', 'googlebase/types', 'type_id'), - 'type_id', $installer->getTable('googlebase/types'), 'type_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) - ->setComment('Google Base Attributes link Product Attributes'); -$installer->getConnection()->createTable($table); - -$installer->endSetup(); diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-install-0.1.0.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-install-0.1.0.php deleted file mode 100644 index 45cd3b67bd4..00000000000 --- a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-install-0.1.0.php +++ /dev/null @@ -1,74 +0,0 @@ -startSetup(); - -$installer->run(" - --- DROP TABLE IF EXISTS {$this->getTable('googlebase/types')}; -CREATE TABLE {$this->getTable('googlebase/types')} ( - `type_id` int(10) unsigned not null auto_increment , - `attribute_set_id` smallint(5) unsigned not null , - `gbase_itemtype` varchar(255) not null , - PRIMARY KEY (`type_id`), - CONSTRAINT `GOOGLEBASE_TYPES_ATTRIBUTE_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `{$this->getTable('eav/attribute_set')}` (`attribute_set_id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Google Base Item Types link Attribute Sets'; - --- DROP TABLE IF EXISTS {$this->getTable('googlebase/items')}; -CREATE TABLE {$this->getTable('googlebase/items')} ( - `item_id` int(10) unsigned not null auto_increment , - `type_id` int(10) unsigned not null default '0', - `product_id` int(10) unsigned not null , - `gbase_item_id` varchar(255) not null , - `store_id` smallint(5) unsigned not null , - `published` datetime NOT NULL default '0000-00-00 00:00:00', - `expires` datetime NOT NULL default '0000-00-00 00:00:00', - `impr` smallint(5) unsigned not null default '0', - `clicks` smallint(5) unsigned not null default '0', - `views` smallint(5) unsigned not null default '0', - `is_hidden` tinyint not null default '0', - PRIMARY KEY (`item_id`), - CONSTRAINT `GOOGLEBASE_ITEMS_PRODUCT_ID` FOREIGN KEY (`product_id`) REFERENCES `{$this->getTable('catalog/product')}` (`entity_id`) ON DELETE CASCADE, - CONSTRAINT `GOOGLEBASE_ITEMS_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `{$this->getTable('core/store')}` (`store_id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Google Base Items Products'; - --- DROP TABLE IF EXISTS {$this->getTable('googlebase/attributes')}; -CREATE TABLE {$this->getTable('googlebase/attributes')} ( - `id` int(10) unsigned not null auto_increment , - `attribute_id` smallint(5) unsigned not null , - `gbase_attribute` varchar(255) not null , - `type_id` int(10) unsigned not null , - PRIMARY KEY (`id`), - CONSTRAINT `GOOGLEBASE_ATTRIBUTES_ATTRIBUTE_ID` FOREIGN KEY (`attribute_id`) REFERENCES `{$this->getTable('eav/attribute')}` (`attribute_id`) ON DELETE CASCADE, - CONSTRAINT `GOOGLEBASE_ATTRIBUTES_TYPE_ID` FOREIGN KEY (`type_id`) REFERENCES `{$this->getTable('googlebase/types')}` (`type_id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Google Base Attributes link Product Attributes'; - -"); - -$installer->endSetup(); diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.0-0.1.1.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.0-0.1.1.php deleted file mode 100644 index 75402316285..00000000000 --- a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.0-0.1.1.php +++ /dev/null @@ -1,30 +0,0 @@ -getConnection()->addColumn($this->getTable('googlebase/types'), 'target_country', "varchar(2) not null default 'US'"); diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.1-0.1.2.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.1-0.1.2.php deleted file mode 100644 index be82157cbdc..00000000000 --- a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.1-0.1.2.php +++ /dev/null @@ -1,43 +0,0 @@ -getConnection()->select() - ->from($installer->getTable('core/config_data')) - ->where('path LIKE ?', 'google/googlebase/password'); -foreach ($installer->getConnection()->fetchAll($select) as $row) { - $bind = array( - 'value' => Mage::helper('core')->encrypt($row['value']) - ); - $where = array( - 'config_id=?' => $row['config_id'] - ); - $installer->getConnection()->update($installer->getTable('core/config_data'), $bind, $where); -} diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php deleted file mode 100644 index d70660b4f00..00000000000 --- a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php +++ /dev/null @@ -1,322 +0,0 @@ -startSetup(); - -/** - * Drop foreign keys - */ -$installer->getConnection()->dropForeignKey( - $installer->getTable('googlebase/attributes'), - 'GOOGLEBASE_ATTRIBUTES_ATTRIBUTE_ID' -); - -$installer->getConnection()->dropForeignKey( - $installer->getTable('googlebase/attributes'), - 'GOOGLEBASE_ATTRIBUTES_TYPE_ID' -); - -$installer->getConnection()->dropForeignKey( - $installer->getTable('googlebase/items'), - 'GOOGLEBASE_ITEMS_PRODUCT_ID' -); - -$installer->getConnection()->dropForeignKey( - $installer->getTable('googlebase/items'), - 'GOOGLEBASE_ITEMS_STORE_ID' -); - -$installer->getConnection()->dropForeignKey( - $installer->getTable('googlebase/types'), - 'GOOGLEBASE_TYPES_ATTRIBUTE_SET_ID' -); - - -/** - * Drop indexes - */ -$installer->getConnection()->dropIndex( - $installer->getTable('googlebase/attributes'), - 'GOOGLEBASE_ATTRIBUTES_ATTRIBUTE_ID' -); - -$installer->getConnection()->dropIndex( - $installer->getTable('googlebase/attributes'), - 'GOOGLEBASE_ATTRIBUTES_TYPE_ID' -); - -$installer->getConnection()->dropIndex( - $installer->getTable('googlebase/items'), - 'GOOGLEBASE_ITEMS_PRODUCT_ID' -); - -$installer->getConnection()->dropIndex( - $installer->getTable('googlebase/items'), - 'GOOGLEBASE_ITEMS_STORE_ID' -); - -$installer->getConnection()->dropIndex( - $installer->getTable('googlebase/types'), - 'GOOGLEBASE_TYPES_ATTRIBUTE_SET_ID' -); - - -/** - * Change columns - */ -$tables = array( - $installer->getTable('googlebase/types') => array( - 'columns' => array( - 'type_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, - 'identity' => true, - 'unsigned' => true, - 'nullable' => false, - 'primary' => true, - 'comment' => 'Type id' - ), - 'attribute_set_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'comment' => 'Attribute set id' - ), - 'gbase_itemtype' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => false, - 'comment' => 'Google base item type' - ), - 'target_country' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, - 'length' => 2, - 'nullable' => false, - 'default' => 'US', - 'comment' => 'Target country' - ) - ), - 'comment' => 'Google Base Item Types link Attribute Sets' - ), - $installer->getTable('googlebase/items') => array( - 'columns' => array( - 'item_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, - 'identity' => true, - 'unsigned' => true, - 'nullable' => false, - 'primary' => true, - 'comment' => 'Item id' - ), - 'type_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Type id' - ), - 'product_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, - 'unsigned' => true, - 'nullable' => false, - 'comment' => 'Product id' - ), - 'gbase_item_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => false, - 'comment' => 'Google base item id' - ), - 'store_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'comment' => 'Store Id' - ), - 'published' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, - 'nullable' => false, - 'comment' => 'Published' - ), - 'expires' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, - 'nullable' => false, - 'comment' => 'Expires' - ), - 'impr' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Google impressions' - ), - 'clicks' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Google clicks' - ), - 'views' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Google views' - ), - 'is_hidden' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Hidden flag' - ) - ), - 'comment' => 'Google Base Items Products' - ), - $installer->getTable('googlebase/attributes') => array( - 'columns' => array( - 'id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, - 'identity' => true, - 'unsigned' => true, - 'nullable' => false, - 'primary' => true, - 'comment' => 'Id' - ), - 'attribute_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'comment' => 'Attribute id' - ), - 'gbase_attribute' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, - 'length' => 255, - 'comment' => 'Google base attribute' - ), - 'type_id' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, - 'unsigned' => true, - 'nullable' => false, - 'comment' => 'Type id' - ) - ), - 'comment' => 'Google Base Attributes link Product Attributes' - ) -); - -$installer->getConnection()->modifyTables($tables); - - -/** - * Add indexes - */ -$installer->getConnection()->addIndex( - $installer->getTable('googlebase/attributes'), - $installer->getIdxName('googlebase/attributes', array('attribute_id')), - array('attribute_id') -); - -$installer->getConnection()->addIndex( - $installer->getTable('googlebase/attributes'), - $installer->getIdxName('googlebase/attributes', array('type_id')), - array('type_id') -); - -$installer->getConnection()->addIndex( - $installer->getTable('googlebase/items'), - $installer->getIdxName('googlebase/items', array('product_id')), - array('product_id') -); - -$installer->getConnection()->addIndex( - $installer->getTable('googlebase/items'), - $installer->getIdxName('googlebase/items', array('store_id')), - array('store_id') -); - -$installer->getConnection()->addIndex( - $installer->getTable('googlebase/types'), - $installer->getIdxName('googlebase/types', array('attribute_set_id')), - array('attribute_set_id') -); - - -/** - * Add foreign keys - */ -$installer->getConnection()->addForeignKey( - $installer->getFkName('googlebase/attributes', 'attribute_id', 'eav/attribute', 'attribute_id'), - $installer->getTable('googlebase/attributes'), - 'attribute_id', - $installer->getTable('eav/attribute'), - 'attribute_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, - Varien_Db_Ddl_Table::ACTION_NO_ACTION -); - -$installer->getConnection()->addForeignKey( - $installer->getFkName('googlebase/attributes', 'type_id', 'googlebase/types', 'type_id'), - $installer->getTable('googlebase/attributes'), - 'type_id', - $installer->getTable('googlebase/types'), - 'type_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, - Varien_Db_Ddl_Table::ACTION_NO_ACTION -); - -$installer->getConnection()->addForeignKey( - $installer->getFkName('googlebase/items', 'product_id', 'catalog/product', 'entity_id'), - $installer->getTable('googlebase/items'), - 'product_id', - $installer->getTable('catalog/product'), - 'entity_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, - Varien_Db_Ddl_Table::ACTION_NO_ACTION -); - -$installer->getConnection()->addForeignKey( - $installer->getFkName('googlebase/items', 'store_id', 'core/store', 'store_id'), - $installer->getTable('googlebase/items'), - 'store_id', - $installer->getTable('core/store'), - 'store_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, - Varien_Db_Ddl_Table::ACTION_NO_ACTION -); - -$installer->getConnection()->addForeignKey( - $installer->getFkName('googlebase/types', 'attribute_set_id', 'eav/attribute_set', 'attribute_set_id'), - $installer->getTable('googlebase/types'), - 'attribute_set_id', - $installer->getTable('eav/attribute_set'), - 'attribute_set_id', - Varien_Db_Ddl_Table::ACTION_CASCADE, - Varien_Db_Ddl_Table::ACTION_NO_ACTION -); - -$installer->endSetup();