Mage_GoogleBase_ItemsController Class Reference

Inheritance diagram for Mage_GoogleBase_ItemsController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 indexAction ()
 gridAction ()
 massAddAction ()
 massDeleteAction ()
 massPublishAction ()
 massHideAction ()
 refreshAction ()
 confirmCaptchaAction ()
 _getStore ()

Protected Member Functions

 _initAction ()
 _redirectToCaptcha ($e)
 _getConfig ()
 _isAllowed ()
 _parseGdataExceptionMessage ($message)


Detailed Description

Definition at line 35 of file ItemsController.php.


Member Function Documentation

_getConfig (  )  [protected]

Definition at line 343 of file ItemsController.php.

00344     {
00345         return Mage::getSingleton('googlebase/config');
00346     }

_getStore (  ) 

Get store object, basing on request

Returns:
Mage_Core_Model_Store
Exceptions:
Mage_Core_Exception 

Definition at line 334 of file ItemsController.php.

00335     {
00336         $store = Mage::app()->getStore((int)$this->getRequest()->getParam('store', 0));
00337         if ((!$store) || 0 == $store->getId()) {
00338             Mage::throwException($this->__('Unable to select a Store View'));
00339         }
00340         return $store;
00341     }

_initAction (  )  [protected]

Definition at line 37 of file ItemsController.php.

00038     {
00039         $this->loadLayout()
00040             ->_setActiveMenu('catalog/googlebase/items')
00041             ->_addBreadcrumb(Mage::helper('adminhtml')->__('Catalog'), Mage::helper('adminhtml')->__('Catalog'))
00042             ->_addBreadcrumb(Mage::helper('adminhtml')->__('Google Base'), Mage::helper('adminhtml')->__('Google Base'));
00043         return $this;
00044     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 348 of file ItemsController.php.

00349     {
00350         return Mage::getSingleton('admin/session')->isAllowed('catalog/googlebase/items');
00351     }

_parseGdataExceptionMessage ( message  )  [protected]

Parse Exception Response Body

Parameters:
string $message Exception message to parse
Returns:
string

Definition at line 359 of file ItemsController.php.

00360     {
00361         $result = array();
00362         foreach (explode("\n", $message) as $row) {
00363             if (strip_tags($row) == $row) {
00364                 $result[] = $row;
00365                 continue;
00366             }
00367             try {
00368                 $xml = new Varien_Simplexml_Element($row);
00369                 $error = $xml->getAttribute('reason');
00370                 $result[] = $error;
00371             } catch (Exception $e) {
00372                 continue;
00373             }
00374         }
00375         return implode(" ", $result);
00376     }

_redirectToCaptcha ( e  )  [protected]

Redirect user to Google Captcha challenge

Parameters:
Zend_Gdata_App_CaptchaRequiredException $e

Definition at line 318 of file ItemsController.php.

00319     {
00320         $this->_redirect('*/*/index',
00321             array('store' => $this->_getStore()->getId(),
00322                 'captcha_token' => Mage::helper('core')->urlEncode($e->getCaptchaToken()),
00323                 'captcha_url' => Mage::helper('core')->urlEncode($e->getCaptchaUrl())
00324             )
00325         );
00326     }

confirmCaptchaAction (  ) 

Definition at line 289 of file ItemsController.php.

00290     {
00291         $storeId = $this->_getStore()->getId();
00292         try {
00293             Mage::getModel('googlebase/service')->getClient(
00294                 $storeId,
00295                 Mage::helper('core')->urlDecode($this->getRequest()->getParam('captcha_token')),
00296                 $this->getRequest()->getParam('user_confirm')
00297             );
00298             $this->_getSession()->addSuccess($this->__('Captcha confirmed successfully'));
00299 
00300         } catch (Zend_Gdata_App_CaptchaRequiredException $e) {
00301             $this->_getSession()->addError($this->__('Captcha confirmation error: %s', $e->getMessage()));
00302             $this->_redirectToCaptcha($e);
00303             return;
00304         } catch (Zend_Gdata_App_Exception $e) {
00305             $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) );
00306         } catch (Exception $e) {
00307             $this->_getSession()->addError($this->__('Captcha confirmation error: %s', $e->getMessage()));
00308         }
00309 
00310         $this->_redirect('*/*/index', array('store'=>$storeId));
00311     }

gridAction (  ) 

Definition at line 80 of file ItemsController.php.

00081     {
00082         $this->loadLayout();
00083         return $this->getResponse()->setBody(
00084             $this->getLayout()
00085                 ->createBlock('googlebase/adminhtml_items_item')
00086                 ->setIndex($this->getRequest()->getParam('index'))
00087                 ->toHtml()
00088            );
00089     }

indexAction (  ) 

Definition at line 46 of file ItemsController.php.

00047     {
00048         if (0 === (int)$this->getRequest()->getParam('store')) {
00049             $this->_redirect('*/*/', array('store' => Mage::app()->getAnyStoreView()->getId(), '_current' => true));
00050             return;
00051         }
00052         $contentBlock = $this->getLayout()->createBlock('googlebase/adminhtml_items')->setStore($this->_getStore());
00053 
00054         if ($this->getRequest()->getParam('captcha_token') && $this->getRequest()->getParam('captcha_url')) {
00055             $contentBlock->setGbaseCaptchaToken(
00056                 Mage::helper('core')->urlDecode($this->getRequest()->getParam('captcha_token'))
00057             );
00058             $contentBlock->setGbaseCaptchaUrl(
00059                 Mage::helper('core')->urlDecode($this->getRequest()->getParam('captcha_url'))
00060             );
00061         }
00062 
00063         if (!$this->_getConfig()->isValidBaseCurrencyCode($this->_getStore()->getId())) {
00064             $_countryInfo = $this->_getConfig()->getTargetCountryInfo($this->_getStore()->getId());
00065             $this->_getSession()->addNotice(
00066                 $this->__(
00067                     "Base Currency should be set to %s for %s in system configuration. Otherwise item prices won't be correct in Google Base.",
00068                     $_countryInfo['currency_name'],
00069                     $_countryInfo['name']
00070                 )
00071             );
00072         }
00073 
00074         $this->_initAction()
00075             ->_addBreadcrumb(Mage::helper('googlebase')->__('Items'), Mage::helper('googlebase')->__('Items'))
00076             ->_addContent($contentBlock)
00077             ->renderLayout();
00078     }

massAddAction (  ) 

Definition at line 91 of file ItemsController.php.

00092     {
00093         $storeId = $this->_getStore()->getId();
00094         $productIds = $this->getRequest()->getParam('product');
00095 
00096         $totalAdded = 0;
00097 
00098         try {
00099             foreach ($productIds as $productId) {
00100                 $product = Mage::getSingleton('catalog/product')
00101                     ->setStoreId($storeId)
00102                     ->load($productId);
00103 
00104                 if ($product->getId()) {
00105                     Mage::getModel('googlebase/item')
00106                         ->setProduct($product)
00107                         ->insertItem()
00108                         ->save();
00109 
00110                     $totalAdded++;
00111                 }
00112             }
00113             if ($totalAdded > 0) {
00114                 $this->_getSession()->addSuccess(
00115                     $this->__('Total of %d product(s) were successfully added to Google Base', $totalAdded)
00116                 );
00117             } else {
00118                 $this->_getSession()->addError($this->__('No products were added to Google Base'));
00119             }
00120         } catch (Zend_Gdata_App_CaptchaRequiredException $e) {
00121             $this->_getSession()->addError($e->getMessage());
00122             $this->_redirectToCaptcha($e);
00123             return;
00124         } catch (Zend_Gdata_App_Exception $e) {
00125             $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) );
00126         } catch (Exception $e) {
00127             $this->_getSession()->addError($e->getMessage());
00128         }
00129 
00130         $this->_redirect('*/*/index', array('store'=>$storeId));
00131     }

massDeleteAction (  ) 

Definition at line 133 of file ItemsController.php.

00134     {
00135         $storeId = $this->_getStore()->getId();
00136         $itemIds = $this->getRequest()->getParam('item');
00137 
00138         $totalDeleted = 0;
00139 
00140         try {
00141             foreach ($itemIds as $itemId) {
00142                 $item = Mage::getModel('googlebase/item')->load($itemId);
00143                 if ($item->getId()) {
00144                     $item->deleteItem();
00145                     $item->delete();
00146                     $totalDeleted++;
00147                 }
00148             }
00149             if ($totalDeleted > 0) {
00150                 $this->_getSession()->addSuccess(
00151                     $this->__('Total of %d items(s) were successfully removed from Google Base', $totalDeleted)
00152                 );
00153             } else {
00154                 $this->_getSession()->addError($this->__('No items were deleted from Google Base'));
00155             }
00156         } catch (Zend_Gdata_App_CaptchaRequiredException $e) {
00157             $this->_getSession()->addError($e->getMessage());
00158             $this->_redirectToCaptcha($e);
00159             return;
00160         } catch (Zend_Gdata_App_Exception $e) {
00161             $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) );
00162         } catch (Exception $e) {
00163             $this->_getSession()->addError($e->getMessage());
00164         }
00165 
00166         $this->_redirect('*/*/index', array('store'=>$storeId));
00167     }

massHideAction (  ) 

Definition at line 204 of file ItemsController.php.

00205     {
00206         $storeId = $this->_getStore()->getId();
00207         $itemIds = $this->getRequest()->getParam('item');
00208 
00209         $totalHidden = 0;
00210 
00211         try {
00212             foreach ($itemIds as $itemId) {
00213                 $item = Mage::getModel('googlebase/item')->load($itemId);
00214                 if ($item->getId()) {
00215                     $item->hideItem();
00216                     $totalHidden++;
00217                 }
00218             }
00219             if ($totalHidden > 0) {
00220                 $this->_getSession()->addSuccess(
00221                     $this->__('Total of %d items(s) were successfully saved as Inactive items', $totalHidden)
00222                 );
00223             } else {
00224                 $this->_getSession()->addError($this->__('No items were saved as Inactive items'));
00225             }
00226         } catch (Zend_Gdata_App_CaptchaRequiredException $e) {
00227             $this->_getSession()->addError($e->getMessage());
00228             $this->_redirectToCaptcha($e);
00229             return;
00230         } catch (Zend_Gdata_App_Exception $e) {
00231             $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) );
00232         } catch (Exception $e) {
00233             $this->_getSession()->addError($e->getMessage());
00234         }
00235 
00236         $this->_redirect('*/*/index', array('store'=>$storeId));
00237     }

massPublishAction (  ) 

Definition at line 169 of file ItemsController.php.

00170     {
00171         $storeId = $this->_getStore()->getId();
00172         $itemIds = $this->getRequest()->getParam('item');
00173 
00174         $totalPublished = 0;
00175 
00176         try {
00177             foreach ($itemIds as $itemId) {
00178                 $item = Mage::getModel('googlebase/item')->load($itemId);
00179                 if ($item->getId()) {
00180                     $item->activateItem();
00181                     $totalPublished++;
00182                 }
00183             }
00184             if ($totalPublished > 0) {
00185                 $this->_getSession()->addSuccess(
00186                     $this->__('Total of %d items(s) were successfully published', $totalPublished)
00187                 );
00188             } else {
00189                 $this->_getSession()->addError($this->__('No items were published'));
00190             }
00191         } catch (Zend_Gdata_App_CaptchaRequiredException $e) {
00192             $this->_getSession()->addError($e->getMessage());
00193             $this->_redirectToCaptcha($e);
00194             return;
00195         } catch (Zend_Gdata_App_Exception $e) {
00196             $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) );
00197         } catch (Exception $e) {
00198             $this->_getSession()->addError($e->getMessage());
00199         }
00200 
00201         $this->_redirect('*/*/index', array('store'=>$storeId));
00202     }

refreshAction (  ) 

Update items statistics and remove the items which are not available in Google Base

Definition at line 242 of file ItemsController.php.

00243     {
00244         $storeId = $this->_getStore()->getId();
00245         $totalUpdated = 0;
00246         $totalDeleted = 0;
00247 
00248         try {
00249             $itemIds = $this->getRequest()->getParam('item');
00250             foreach ($itemIds as $itemId) {
00251                 $item = Mage::getModel('googlebase/item')->load($itemId);
00252 
00253                 $stats = Mage::getSingleton('googlebase/service_feed')->getItemStats($item->getGbaseItemId(), $storeId);
00254                 if ($stats === null) {
00255                     $item->delete();
00256                     $totalDeleted++;
00257                     continue;
00258                 }
00259 
00260                 if ($stats['draft'] != $item->getIsHidden()) {
00261                     $item->setIsHidden($stats['draft']);
00262                 }
00263 
00264                 if (isset($stats['expires'])) {
00265                     $item->setExpires($stats['expires']);
00266                 }
00267 
00268                 $item->save();
00269                 $totalUpdated++;
00270             }
00271 
00272             $this->_getSession()->addSuccess(
00273                 $this->__('Total of %d items(s) were successfully deleted, Total of %d items(s) were successfully updated', $totalDeleted, $totalUpdated)
00274             );
00275 
00276         } catch (Zend_Gdata_App_CaptchaRequiredException $e) {
00277             $this->_getSession()->addError($e->getMessage());
00278             $this->_redirectToCaptcha($e);
00279             return;
00280         } catch (Zend_Gdata_App_Exception $e) {
00281             $this->_getSession()->addError( $this->_parseGdataExceptionMessage($e->getMessage()) );
00282         } catch (Exception $e) {
00283             $this->_getSession()->addError($e->getMessage());
00284         }
00285 
00286         $this->_redirect('*/*/index', array('store'=>$storeId));
00287     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:14 2009 for Magento by  doxygen 1.5.8