diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 8099958f98..957065aadd 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,3 +1,192 @@ +==== 1.5.0.0-beta2 ===== + +=== Improvements === +Implemented Environment emulation in core email class +- Added Emulation model. +- Added Email Info and Email Template Mailer models. +- Re-factored sendEmail() and sendUpdateEmail() methods of order, credit memo, invoice and shipment models. +Added App Previewer for Android and iPad in XmlConenect + +=== Fixes === +Fixed Labels for composite products (backend) are shown incorrect +Fixed Ability to Refund the already refunded item in Patial Invoice +- added qty`s limits into creating creditmemo functionality +Fixed Performance issue with big amount of tax rates +Fixed Notice error in system.xml after saving PayPal configuration +Fixed No Qty column in the Wishlist sideblock +Fixed Export functionality doesn't work +Fixed Maestro International CC number has no validation +- use "Switch/Maestro" instead of "Maestro (International)" +Fixed No transactions is created, no ability to perform Invoice, when Order, which contains Gift Options, is placed from backend with Authorize.net Direct Post payment method +Fixed Moving Grouped product from Order and Shopping cart to the Wishlist does not work +Fixed Added advice block hiding on synchronize process +Fixed Database as cache backend +- fix for MySQL 4. Shorten field lengthes +Fixed Improvemets for MCM and Magento Extension Packager after MCMUP +Fixed PayPal Standard with specific tax settings for shop cart item with qty >= 2 +Fixed Wrong tax calculation for bundle products +Fixed Export Filters are not working correctly during export of customers +Fixed Unable to complete several partial online refunds with Authorize.net Direct Post +Fixed Disable Mage_Checkout did not remove My Cart & Checkout links in the Top Link +Fixed An error occurs with using Payflo Link payment method and IE8 +- just small fixture of strange for user popup in IE - "Do you want to see only secure content?" +Fixed Price for composite products in a products grid on Order creation page +Fixed No error message appears if execute synchronization with non-existing DB +Fixed "Configure" link in Product grid (backend) does not work (only IE) +Fixed "Void" button must not be active on the invoice with amount captured on-line +- redefined methods canVoid for Express and Direct Paypal models - hiding button void for invoice and creditmemo +- redefined methods cancel for Express and Direct Paypal models - no checking for invoices for order to decide void it or not at cancel. +Fixed Dropdown for Amount is absent (only IE) +- create new JS method that preserves visibility states of selects in pop-up block +Fixed Status of Order is now doesn't ignore the setting in Config. +Fixed Incorrect behavior of AJAX-popup for Gift Options (Individual Item) in IE8 +Fixed to show full review for the iPad device +- added checking the current app's device type is not iPad and in this case the text of the review is truncated; +- replaced TABs on spaces in helper's class +- Re-factored XmlConnect helperfor unknown device type +Fixed xmlconnect/catalog/product action returns invalid html for product's description +- added an "xml" tag before DOCTYPE definition +Fixed wrong using of translation in method getElementHtml() +Fixed update Preview Area for iPad +Fixed Missed active/Inactive tabs logic added for a preview +Fixed Selecting catalog as a price rule condition redirects you on dashboard +- check if post array values are integers > 0 +Fixed "Go to notifications" link works improperly +Fixed Unable to complete several partial online refunds with Authorize.net Direct Post +Fixed "Set Products as New to Date" is not working in Catalog New Products List widget +Fixed Mage_Adminhtml_Block_Media_Uploader::getUploaderUrl() generates incorrect path if magento is installed in a sub-directory within the root one +Fixed Now in Admin in System->TransactionalEmails all filters are saved to session. +Fixed Tax discrepancy between Tax Report and Order Report +Fixed PayPal Standard with specific tax settings for shop cart item with qty >= 2 +Fixed Incorrect hint for non-configured product in Order on backend +Fixed Flush Cache Storage alert text is now changed to: "Cache storage may contain additional data. Are you sure that you want flush it?" +Fixed "Read Details" link is present in the message about synchronization status +- removed read details link from rows which have not url +Fixed Mage_Catalog_Model_Product::setFinalPrice() doesn't return its class instance for chaining purposes. +- fixed interface erroneously changed in 1.4.1.0 +- fixed erroneous phpDoc +Fixed First Checkout by registered Customer: First Name and Last name fields are empty +Fixed Error with addlisttype.phtml in system log +- Removed not deleted layout block that was forgotten after rev 90337 with fix for MAGE-1955 +Fixed Changes in UI for Order Status Management +Fixed Catalog Price Rule is not applied +- Added Mage_CatalogRule_Model_Rule::applyAllRulesToProduct() +Fixed Admin order creation - Unable to delete product from the cart +- fixed showing giftmessage options template, when no grid items are present +- fixed updating quote items and giftmessage items when backend receives wrong item id - now it doesn't fail with exception, but process it gracefully +Fixed With IE6 impossible to configure a Composite product in Backend +Fixed Message for non-configured composite product is changed after pressing "Update Items and Qty's" +Fixed Option "Order" on Payment Action dropdown must be available only for Express Checkout method +- Removed extra spaces in system.xml. +Fixed With IE8 an error occurs after applying the second time Credit Card in Admin panel with 3D Secure and patrial authorization (Authorize.net) +- moved embedded gift options FORM tag out of other main FORM tag (such invalid layout broke DOM in IE) +- refactored JS-scripts, moved static to static files +- removed not used old js-file +Fixed Products are erased from "Product Ordered" report after deleting them +Fixed Incorrect behavior of ReOrder action applied to Order, that contains Gift Options +Fixed When adding several configurable products at one time to Items Ordered from product grid, only last remains specified configuration (admin Order creation) +- restored JS-initing for controls on each popup show (was erroneously removed at rev 86017) +- fixed Configurable javascript so it won't interfere with other products controls on page +Fixed Incorrect transaction and Partial Refunds behavior with WPP Hosted Solution, when Order is partially invoiced +Fixed Hint for "View Details" in the Wishlist is located incorrectly +Fixed Onepage checkout - Shipping address issues +Fixed Tax Rate = 0% displayed in Cart +- display (0%) in rate title +Fixed Magento Backend performance optimization +Fixed Creating Purchase orders from backend works incorrect (IE) +Fixed Moving simple products (part of grouped) from shopping cart to order does not work +Fixed Payment Applicable From = "Specific Countries" option does not work for Express Checkout (Payflow Edition) +Fixed Cannot place Order in backend with Authorize.net Direct Post, when settings for payment method is applied on a Website scope level +Fixed SOAP don't use store for select products collection +- Change setting the store into filter +Fixed "Synchronize" button is disabled if select native database twice +- modified storage full name generation and button state check +Fixed Wrong algorithm to determine whether product can be configured (Composite Products feature) +- removed used method isComposite() from canConfigure() method +Fixed Missing nobr around date in Customer Product Reviews table +Fixed Status of Order, which is paced with Authorize.net Direct Post (Payment Action = Authorization) is incorrect +Fixed Added base_total_refunded field to invoice table +Fixed "Flush External Page Cache" does not work +Fixed Database as cache backend +Fixed Selecting products in Wishlist (backend) redirects you on dashboard +- Fixed searching by product names and days in wishlist +- Removed 'Visible In' column, because it showed same values as 'Added from' +- Fixed 'Added from' column to show real values, not some erroneous 'All Visible Stores' +- Fixed sorting by product name and days in wishlist + + +==== 1.5.x-devel-92027 ==== + +=== Fixes === +Fixed Selecting catalog as a price rule condition redirects you on dashboard +- check if post array values are integers > 0 +Fixed "Go to notifications" link works improperly +Fixed Unable to complete several partial online refunds with Authorize.net Direct Post +Fixed "Set Products as New to Date" is not working in Catalog New Products List widget +Fixed Mage_Adminhtml_Block_Media_Uploader::getUploaderUrl() generates incorrect path if magento is installed in a sub-directory within the root one +Fixed Now in Admin in System->TransactionalEmails all filters are saved to session. +Fixed Tax discrepancy between Tax Report and Order Report +Fixed PayPal Standard with specific tax settings for shop cart item with qty >= 2 +Fixed Incorrect hint for non-configured product in Order on backend +Fixed Flush Cache Storage alert text is now changed to: "Cache storage may contain additional data. Are you sure that you want flush it?" +Fixed "Read Details" link is present in the message about synchronization status +- removed read details link from rows which have not url +Fixed Mage_Catalog_Model_Product::setFinalPrice() doesn't return its class instance for chaining purposes. +- fixed interface erroneously changed in 1.4.1.0 +- fixed erroneous phpDoc +Fixed First Checkout by registered Customer: First Name and Last name fields are empty +CR Change First Checkout by registered Customer: First Name and Last name fields are empty +- reverted Billing.php to the its previous state +- copied logic of determine customer name from customer address template base/default/template/customer/address/edit.phtml +Fixed CRIT error with addlisttype.phtml in system log +- Removed not deleted layout block that was forgotten after rev 90337 with fix for MAGE-1955 +Fixed Changes in UI for Order Status Management +Fixed Catalog Price Rule is not applied +- Added Mage_CatalogRule_Model_Rule::applyAllRulesToProduct() +Fixed Admin order creation - Unable to delete product from the cart +- fixed showing giftmessage options template, when no grid items are present +- fixed updating quote items and giftmessage items when backend receives wrong item id - now it doesn't fail with exception, but process it gracefully +Fixed With IE6 impossible to configure a Composite product in Backend +Fixed Message for non-configured composite product is changed after pressing "Update Items and Qty's" +Fixed Option "Order" on Payment Action dropdown must be available only for Express Checkout method +- Removed extra spaces in system.xml. +Fixed With IE8 an error occurs after applying the second time Credit Card in Admin panel with 3D Secure and patrial authorization (Authorize.net) +- moved embedded gift options FORM tag out of other main FORM tag (such invalid layout broke DOM in IE) +- refactored JS-scripts, moved static to static files +- removed not used old js-file +Fixed Products are erased from "Product Ordered" report after deleting them +Fixed Incorrect behavior of ReOrder action applied to Order, that contains Gift Options +Fixed When adding several configurable products at one time to Items Ordered from product grid, only last remains specified configuration (admin Order creation) +- restored JS-initing for controls on each popup show (was erroneously removed at rev 86017) +- fixed Configurable javascript so it won't interfere with other products controls on page +Fixed Incorrect transaction and Partial Refunds behavior with WPP Hosted Solution, when Order is partially invoiced +Fixed Hint for "View Details" in the Wishlist is located incorrectly +Fixed Onepage checkout - Shipping address issues +Fixed Tax Rate = 0% displayed in Cart +- display (0%) in rate title +Fixed Magento Backend performance optimization +Fixed Creating Purchase orders from backend works incorrect (IE) +Fixed Moving simple products (part of grouped) from shopping cart to order does not work +Fixed Payment Applicable From = "Specific Countries" option does not work for Express Checkout (Payflow Edition) +Fixed Cannot place Order in backend with Authorize.net Direct Post, when settings for payment method is applied on a Website scope level +Fixed SOAP don't use store for select products collection +- Change setting the store into filter +Fixed "Synchronize" button is disabled if select native database twice +- modified storage full name generation and button state check +Fixed Wrong algorithm to determine whether product can be configured (Composite Products feature) +- removed used method isComposite() from canConfigure() method +Fixed Missing nobr around date in Customer Product Reviews table +Fixed Status of Order, which is paced with Authorize.net Direct Post (Payment Action = Authorization) is incorrect +Fixed Added base_total_refunded field to invoice table +Fixed "Flush External Page Cache" does not work +Fixed Database as cache backend +Fixed Selecting products in Wishlist (backend) redirects you on dashboard +- Fixed searching by product names and days in wishlist +- Removed 'Visible In' column, because it showed same values as 'Added from' +- Fixed 'Added from' column to show real values, not some erroneous 'All Visible Stores' +- Fixed sorting by product name and days in wishlist + + ==== 1.5.0.0-beta1 ===== === Improvements === diff --git a/app/Mage.php b/app/Mage.php index acd71a3782..448f16e177 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -155,7 +155,7 @@ public static function getVersionInfo() 'revision' => '0', 'patch' => '0', 'stability' => 'beta', - 'number' => '1', + 'number' => '2', ); } diff --git a/app/code/community/Phoenix/Moneybookers/Model/Mae.php b/app/code/community/Phoenix/Moneybookers/Model/Mae.php index e985454a2f..253f02d3fd 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Mae.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Mae.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2010 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Mae extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Obt.php b/app/code/community/Phoenix/Moneybookers/Model/Obt.php index 558d2f8dba..f299d857f8 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Obt.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Obt.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2010 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Obt extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/core/Mage/Adminhtml/Block/Cache.php b/app/code/core/Mage/Adminhtml/Block/Cache.php index 130f38319f..c8d82dd12c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cache.php +++ b/app/code/core/Mage/Adminhtml/Block/Cache.php @@ -41,7 +41,7 @@ public function __construct() 'class' => 'delete', )); - $message = Mage::helper('core')->__('Cache storage may contain another data. Are you sure that you want flush it?'); + $message = Mage::helper('core')->__('Cache storage may contain additional data. Are you sure that you want flush it?'); $this->_addButton('flush_system', array( 'label' => Mage::helper('core')->__('Flush Cache Storage'), 'onclick' => 'confirmSetLocation(\''.$message.'\', \'' . $this->getFlushStorageUrl() .'\')', diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Config.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Config.php index 4704f958b0..0ad8caa290 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Config.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Config.php @@ -40,10 +40,14 @@ class Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Config extends Varien_Dat */ public function getElementHtml() { + $value = $this->getValue(); + if ($value == '') { + $this->setValue($this->_getValueFromConfig()); + } $html = parent::getElementHtml(); $htmlId = 'use_config_' . $this->getHtmlId(); - $checked = ($this->getValue() == '') ? ' checked="checked"' : ''; + $checked = ($value == '') ? ' checked="checked"' : ''; $disabled = ($this->getReadonly()) ? ' disabled="disabled"' : ''; $html .= 'isSingleStoreMode()) { $this->addColumn('store', array( 'header' => Mage::helper('wishlist')->__('Added From'), - 'index' => 'store_name', - 'type' => 'store' + 'index' => 'store_id', + 'type' => 'store', + 'width' => '160px' )); } - $this->addColumn('visible_in', array( - 'header' => Mage::helper('wishlist')->__('Visible In'), - 'index' => 'item_store_id', - 'type' => 'store' - )); - $this->addColumn('added_at', array( 'header' => Mage::helper('wishlist')->__('Date Added'), 'index' => 'added_at', @@ -193,15 +188,47 @@ public function getGridUrl() */ protected function _addColumnFilterToCollection($column) { - if($column->getId()=='store') { - $this->getCollection()->addFieldToFilter('item_store_id', $column->getFilter()->getCondition()); - return $this; + /* @var $collection Mage_Wishlist_Model_Mysql4_Item_Collection */ + $collection = $this->getCollection(); + $value = $column->getFilter()->getValue(); + if ($collection && $value) { + switch ($column->getId()) { + case 'product_name': + $collection->addProductNameFilter($value); + break; + case 'store': + $collection->addStoreFilter($value); + break; + case 'days': + $collection->addDaysFilter($value); + break; + default: + $collection()->addFieldToFilter($column->getIndex(), $column->getFilter()->getCondition()); + break; + } } + return $this; + } - if ($this->getCollection() && $column->getFilter()->getValue()) { - $this->getCollection()->addFieldToFilter($column->getIndex(), $column->getFilter()->getCondition()); + /** + * Sets sorting order by some column + * + * @param Mage_Adminhtml_Block_Widget_Grid_Column $column + * @return Mage_Adminhtml_Block_Customer_Edit_Tab_Wishlist + */ + protected function _setCollectionOrder($column) + { + $collection = $this->getCollection(); + if ($collection) { + switch ($column->getId()) { + case 'product_name': + $collection->setOrderByProductName($column->getDir()); + break; + default: + parent::_setCollectionOrder($column); + break; + } } - return $this; } diff --git a/app/code/core/Mage/Adminhtml/Block/Media/Uploader.php b/app/code/core/Mage/Adminhtml/Block/Media/Uploader.php index 51b071bcb7..42d2f630b6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Media/Uploader.php +++ b/app/code/core/Mage/Adminhtml/Block/Media/Uploader.php @@ -212,7 +212,7 @@ public function getUploaderUrl($url) if (empty($url) || !$design->validateFile($url, array('_type' => 'skin', '_theme' => $theme))) { $theme = $design->getDefaultTheme(); } - return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . 'skin/' . + return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . $design->getArea() . '/' . $design->getPackageName() . '/' . $theme . '/' . $url; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview/Form.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview/Form.php index 088d31758a..c059d74119 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview/Form.php @@ -1,69 +1,69 @@ - - */ -class Mage_Adminhtml_Block_Newsletter_Queue_Preview_Form extends Mage_Adminhtml_Block_Widget_Form -{ - - /** - * Preparing from for revision page - * - * @return Mage_Adminhtml_Block_Widget_Form - */ - protected function _prepareForm() - { - $form = new Varien_Data_Form(array( - 'id' => 'preview_form', - 'action' => $this->getUrl('*/*/drop', array('_current' => true)), - 'method' => 'post' - )); - - if ($data = $this->getFormData()) { - - $mapper = array('preview_store_id' => 'store_id'); - - foreach ($data as $key => $value) { - if(array_key_exists($key, $mapper)) { - $name = $mapper[$key]; - } else { - $name = $key; - } - $form->addField($key, 'hidden', array('name' => $name)); - } - $form->setValues($data); - } - - $form->setUseContainer(true); - $this->setForm($form); - return parent::_prepareForm(); - } -} + + */ +class Mage_Adminhtml_Block_Newsletter_Queue_Preview_Form extends Mage_Adminhtml_Block_Widget_Form +{ + + /** + * Preparing from for revision page + * + * @return Mage_Adminhtml_Block_Widget_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(array( + 'id' => 'preview_form', + 'action' => $this->getUrl('*/*/drop', array('_current' => true)), + 'method' => 'post' + )); + + if ($data = $this->getFormData()) { + + $mapper = array('preview_store_id' => 'store_id'); + + foreach ($data as $key => $value) { + if(array_key_exists($key, $mapper)) { + $name = $mapper[$key]; + } else { + $name = $key; + } + $form->addField($key, 'hidden', array('name' => $name)); + } + $form->setValues($data); + } + + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Actions.php b/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Actions.php index e9bd5cf3a3..d583045f3e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Actions.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Actions.php @@ -43,25 +43,22 @@ class Mage_Adminhtml_Block_Notification_Grid_Renderer_Actions */ public function render(Varien_Object $row) { - if (!$row->getIsRead()) { - return sprintf('%s | %s | %s', - $row->getUrl(), - Mage::helper('adminnotification')->__('Read Details'), - $this->getUrl('*/*/markAsRead/', array('_current'=>true, 'id' => $row->getId())), - Mage::helper('adminnotification')->__('Mark as Read'), - $this->getUrl('*/*/remove/', array('_current'=>true, 'id' => $row->getId())), - Mage::helper('adminnotification')->__('Are you sure?'), - Mage::helper('adminnotification')->__('Remove') - ); - } - else { - return sprintf('%s | %s', - $row->getUrl(), - Mage::helper('adminnotification')->__('Read Details'), - $this->getUrl('*/*/remove/', array('_current'=>true, 'id' => $row->getId())), - Mage::helper('adminnotification')->__('Are you sure?'), - Mage::helper('adminnotification')->__('Remove') - ); - } + $readDetailsHtml = ($row->getUrl()) + ? '' . + Mage::helper('adminnotification')->__('Read Details') .' | ' + : ''; + + $markAsReadHtml = (!$row->getIsRead()) + ? '' . + Mage::helper('adminnotification')->__('Mark as Read') .' | ' + : ''; + + return sprintf('%s%s%s', + $readDetailsHtml, + $markAsReadHtml, + $this->getUrl('*/*/remove/', array('_current' => true, 'id' => $row->getId())), + Mage::helper('adminnotification')->__('Are you sure?'), + Mage::helper('adminnotification')->__('Remove') + ); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Footer.php b/app/code/core/Mage/Adminhtml/Block/Page/Footer.php index 5babf55b56..dfc76a9667 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Footer.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Footer.php @@ -34,19 +34,14 @@ */ class Mage_Adminhtml_Block_Page_Footer extends Mage_Adminhtml_Block_Template { - const CACHE_LIFETIME = 7200; - const CACHE_KEY = 'footer'; - const CACHE_TAG = 'adminhtml'; + const LOCALE_CACHE_LIFETIME = 7200; + const LOCALE_CACHE_KEY = 'footer_locale'; + const LOCALE_CACHE_TAG = 'adminhtml'; protected function _construct() { $this->setTemplate('page/footer.phtml'); $this->setShowProfiler(true); - $this->addData(array( - 'cache_lifetime' => self::CACHE_LIFETIME, - 'cache_tags' => array(self::CACHE_TAG), - 'cache_key' => self::CACHE_KEY - )); } public function getChangeLocaleUrl() @@ -66,14 +61,21 @@ public function getRefererParamName() public function getLanguageSelect() { - $html = $this->getLayout()->createBlock('adminhtml/html_select') - ->setName('locale') - ->setId('interface_locale') - ->setTitle(Mage::helper('page')->__('Interface Language')) - ->setExtraParams('style="width:200px"') - ->setValue(Mage::app()->getLocale()->getLocaleCode()) - ->setOptions(Mage::app()->getLocale()->getTranslatedOptionLocales()) - ->getHtml(); + $locale = Mage::app()->getLocale(); + $cacheId = self::LOCALE_CACHE_KEY . $locale->getLocaleCode(); + $html = Mage::app()->loadCache($cacheId); + + if (!$html) { + $html = $this->getLayout()->createBlock('adminhtml/html_select') + ->setName('locale') + ->setId('interface_locale') + ->setTitle(Mage::helper('page')->__('Interface Language')) + ->setExtraParams('style="width:200px"') + ->setValue($locale->getLocaleCode()) + ->setOptions($locale->getTranslatedOptionLocales()) + ->getHtml(); + Mage::app()->saveCache($html, $cacheId, array(self::LOCALE_CACHE_TAG), self::LOCALE_CACHE_LIFETIME); + } return $html; } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php index 6d59c66253..7889b7bb1c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php @@ -73,7 +73,7 @@ protected function _prepareColumns() { $this->addColumn('name', array( 'header' =>Mage::helper('reports')->__('Product Name'), - 'index' =>'name' + 'index' =>'order_items_name' )); $this->addColumn('ordered_qty', array( diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Wishlist.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Wishlist.php index 0029ab2026..4349215e55 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Wishlist.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Wishlist.php @@ -108,4 +108,14 @@ public function getIdentifierId($item) { return $item->getId(); } + + /** + * Retrieve possibility to display quantity column in grid of wishlist block + * + * @return bool + */ + public function canDisplayItemQty() + { + return true; + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php index f3433b14de..9b37860351 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php @@ -75,6 +75,7 @@ public function __construct() if ($this->_isAllowedAction('creditmemo') && $this->getInvoice()->getOrder()->canCreditmemo()) { if (($orderPayment->canRefundPartialPerInvoice() + && $this->getInvoice()->canRefund() && $orderPayment->getAmountPaid() > $orderPayment->getAmountRefunded()) || ($orderPayment->canRefund() && !$this->getInvoice()->getIsUsedForRefund())) { $this->_addButton('capture', array( // capture? diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign/Form.php index 66d280c46a..6fd9e15c24 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign/Form.php @@ -61,7 +61,7 @@ protected function _prepareForm() $fieldset->addField('status', 'select', array( 'name' => 'status', - 'label' => Mage::helper('sales')->__('Assign Order Status'), + 'label' => Mage::helper('sales')->__('Order Status'), 'class' => 'required-entry', 'values' => $statuses, 'required' => true, @@ -71,7 +71,7 @@ protected function _prepareForm() $fieldset->addField('state', 'select', array( 'name' => 'state', - 'label' => Mage::helper('sales')->__('To Order State'), + 'label' => Mage::helper('sales')->__('Order State'), 'class' => 'required-entry', 'values' => $states, 'required' => true, @@ -81,7 +81,7 @@ protected function _prepareForm() $fieldset->addField('is_default', 'checkbox', array( 'name' => 'is_default', - 'label' => Mage::helper('sales')->__('And Use As Default'), + 'label' => Mage::helper('sales')->__('Use Order Status As Default'), 'value' => 1, ) ); diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php index fa38669acf..3fc586096f 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php @@ -323,11 +323,25 @@ public function initFields($fieldset, $group, $section, $fieldPrefix='', $labelP if ($e->depends) { foreach ($e->depends->children() as $dependent) { $dependentId = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $dependent->getName(); - $dependentValue = (string) $dependent; - $this->_getDependence() - ->addFieldMap($id, $id) - ->addFieldMap($dependentId, $dependentId) - ->addFieldDependence($id, $dependentId, $dependentValue); + $shouldBeAddedDependence = true; + $dependentValue = (string) $dependent; + $dependentFieldName = $fieldPrefix . $dependent->getName(); + $dependentField = $group->fields->$dependentFieldName; + /* + * If dependent field can't be shown in current scope and real dependent config value + * is not equal to preferred one, then hide dependence fields by adding dependence + * based on not shown field (not rendered field) + */ + if (!$this->_canShowField($dependentField)) { + $dependentFullPath = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $dependent->getName(); + $shouldBeAddedDependence = $dependentValue != Mage::getStoreConfig($dependentFullPath, $this->getStoreCode()); + } + if($shouldBeAddedDependence) { + $this->_getDependence() + ->addFieldMap($id, $id) + ->addFieldMap($dependentId, $dependentId) + ->addFieldDependence($id, $dependentId, $dependentValue); + } } } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php index 38038cd371..ede1780c5a 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php @@ -37,6 +37,9 @@ class Mage_Adminhtml_Block_System_Email_Template_Grid extends Mage_Adminhtml_Blo protected function _construct() { $this->setEmptyText(Mage::helper('adminhtml')->__('No Templates Found')); + $this->setId('systemEmailTemplateGrid'); + $this->setUseAjax(true); + $this->setSaveParametersInSession(true); } protected function _prepareCollection() diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index c1e648dd44..faea3ad36e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -449,6 +449,23 @@ protected function _addColumnFilterToCollection($column) return $this; } + /** + * Sets sorting order by some column + * + * @param Mage_Adminhtml_Block_Widget_Grid_Column $column + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _setCollectionOrder($column) + { + $collection = $this->getCollection(); + if ($collection) { + $columnIndex = $column->getFilterIndex() ? + $column->getFilterIndex() : $column->getIndex(); + $collection->setOrder($columnIndex, $column->getDir()); + } + return $this; + } + /** * Prepare grid collection object * @@ -482,9 +499,7 @@ protected function _prepareCollection() if (isset($this->_columns[$columnId]) && $this->_columns[$columnId]->getIndex()) { $dir = (strtolower($dir)=='desc') ? 'desc' : 'asc'; $this->_columns[$columnId]->setDir($dir); - $column = $this->_columns[$columnId]->getFilterIndex() ? - $this->_columns[$columnId]->getFilterIndex() : $this->_columns[$columnId]->getIndex(); - $this->getCollection()->setOrder($column , $dir); + $this->_setCollectionOrder($this->_columns[$columnId]); } if (!$this->_isExport) { diff --git a/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php b/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php index d36aef1a34..625c276669 100644 --- a/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php +++ b/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php @@ -84,6 +84,7 @@ public function saveAllInOrder() * @return Mage_Adminhtml_Model_Giftmessage_Save */ protected function _saveOne($entityId, $giftmessage) { + /* @var $giftmessageModel Mage_Giftmessage_Model_Message */ $giftmessageModel = Mage::getModel('giftmessage/message'); $entityType = $this->_getMappedType($giftmessage['type']); @@ -102,6 +103,10 @@ protected function _saveOne($entityId, $giftmessage) { break; } + if (!$entityModel) { + return $this; + } + if ($entityModel->getGiftMessageId()) { $giftmessageModel->load($entityModel->getGiftMessageId()); } diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php index c8736c6d13..ed000b0466 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php @@ -141,7 +141,7 @@ public function getIsValidate() /** * Retrieve quote item * - * @param mixed $item + * @param int|Mage_Sales_Model_Quote_Item $item * @return Mage_Sales_Model_Quote_Item */ protected function _getQuoteItem($item) @@ -385,20 +385,15 @@ public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = ->load($orderItem->getProductId()); if ($product->getId()) { - $info = $orderItem->getProductOptionByCode('info_buyRequest'); - $info = new Varien_Object($info); $product->setSkipCheckRequiredOption(true); - $item = $this->getQuote()->addProduct($product, $info); + $buyRequest = $orderItem->getBuyRequest(); + if (is_numeric($qty)) { + $buyRequest->setQty($qty); + } + $item = $this->getQuote()->addProduct($product, $buyRequest); if (is_string($item)) { return $item; } - if (is_numeric($qty)) { - if ($parentItem = $item->getParentItem()) { - $parentItem->setQty($qty); - } else { - $item->setQty($qty); - } - } if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) { $item->addOption(new Varien_Object( @@ -410,13 +405,6 @@ public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = )); } - Mage::helper('core')->copyFieldset( - 'sales_copy_order_item', - 'to_edit_item', - $orderItem, - $item - ); - Mage::dispatchEvent('sales_convert_order_item_to_quote_item', array( 'order_item' => $orderItem, 'quote_item' => $item @@ -506,45 +494,35 @@ public function getCustomerGroupId() } /** - * Move quote item to another items store + * Move quote item to another items list * - * @param mixed $item - * @param string $mogeTo + * @param int|Mage_Sales_Model_Quote_Item $item + * @param string $moveTo + * @param int $qty * @return Mage_Adminhtml_Model_Sales_Order_Create */ public function moveQuoteItem($item, $moveTo, $qty) { - if ($item = $this->_getQuoteItem($item)) { + $item = $this->_getQuoteItem($item); + if ($item) { switch ($moveTo) { case 'order': - $info = $item->getOptionByCode('info_buyRequest'); - if ($info) { - $info = new Varien_Object( - unserialize($info->getValue()) - ); - $info->setOptions($this->_prepareOptionsForRequest($item)); - } + $info = $item->getBuyRequest(); + $info->setOptions($this->_prepareOptionsForRequest($item)) + ->setQty($qty); $product = Mage::getModel('catalog/product') ->setStoreId($this->getQuote()->getStoreId()) ->load($item->getProduct()->getId()); $product->setSkipCheckRequiredOption(true); - $newItem = $this->getQuote()->addProduct($product, $info); - $this->removeItem($item->getId(), 'cart'); - if (is_string($newItem)) { Mage::throwException($newItem); } $product->unsSkipCheckRequiredOption(); $newItem->checkData(); - if ($parentItem = $newItem->getParentItem()) { - $parentItem->setQty($qty); - } else { - $newItem->setQty($qty); - } $this->_needCollectCart = true; break; case 'cart': @@ -591,14 +569,13 @@ public function moveQuoteItem($item, $moveTo, $qty) } $wishlist->addNewItem($item->getProduct(), $info); } - break; - case 'comparelist': - break; default: break; } - $this->getQuote()->removeItem($item->getId()); + if ($moveTo != 'order') { + $this->getQuote()->removeItem($item->getId()); + } $this->setRecollect(true); } return $this; @@ -612,30 +589,21 @@ public function moveQuoteItem($item, $moveTo, $qty) */ public function applySidebarData($data) { - // skip item duplicates based on info_buyRequest option - $infoBuyRequests = array(); - if (isset($data['add_order_item'])) { foreach ($data['add_order_item'] as $orderItemId => $value) { + /* @var $orderItem Mage_Sales_Model_Order_Item */ $orderItem = Mage::getModel('sales/order_item')->load($orderItemId); $item = $this->initFromOrderItem($orderItem); if (is_string($item)) { Mage::throwException($item); } - $infobuyRequest = $item->getOptionByCode('info_buyRequest'); - if ($infobuyRequest !== null) { - $infoBuyRequests[] = $infobuyRequest->getValue(); - } } } if (isset($data['add_cart_item'])) { foreach ($data['add_cart_item'] as $itemId => $qty) { $item = $this->getCustomerCart()->getItemById($itemId); if ($item) { - $infobuyRequest = $item->getOptionByCode('info_buyRequest'); - if ($infobuyRequest === null || !in_array($infobuyRequest->getValue(), $infoBuyRequests)) { - $this->moveQuoteItem($item, 'order', $qty); - } + $this->moveQuoteItem($item, 'order', $qty); $this->removeItem($itemId, 'cart'); } } @@ -808,32 +776,33 @@ public function updateQuoteItems($data) $itemQty = (float)$info['qty']; } - if ($item && $item->getProduct()->getStockItem()) { - if (!$item->getProduct()->getStockItem()->getIsQtyDecimal()) { - $itemQty = (int)$itemQty; + if ($item) { + if ($item->getProduct()->getStockItem()) { + if (!$item->getProduct()->getStockItem()->getIsQtyDecimal()) { + $itemQty = (int)$itemQty; + } else { + $item->setIsQtyDecimal(1); + } + } + $itemQty = $itemQty > 0 ? $itemQty : 1; + if (isset($info['custom_price'])) { + $itemPrice = $this->_parseCustomPrice($info['custom_price']); } else { - $item->setIsQtyDecimal(1); + $itemPrice = null; } - } - $itemQty = $itemQty > 0 ? $itemQty : 1; - if (isset($info['custom_price'])) { - $itemPrice = $this->_parseCustomPrice($info['custom_price']); - } else { - $itemPrice = null; - } - $noDiscount = !isset($info['use_discount']); + $noDiscount = !isset($info['use_discount']); - if (empty($info['action']) || !empty($info['configured'])) { - if ($item) { + if (empty($info['action']) || !empty($info['configured'])) { $item->setQty($itemQty); $item->setCustomPrice($itemPrice); $item->setOriginalCustomPrice($itemPrice); $item->setNoDiscount($noDiscount); $item->getProduct()->setIsSuperMode(true); + $item->getProduct()->unsSkipCheckRequiredOption(); $item->checkData(); + } else { + $this->moveQuoteItem($item->getId(), $info['action'], $itemQty); } - } else { - $this->moveQuoteItem($item->getId(), $info['action'], $itemQty); } } } catch (Mage_Core_Exception $e) { diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Translate.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Translate.php index 1ba0542f02..904f3dee63 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Translate.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Translate.php @@ -1,57 +1,57 @@ - - */ -class Mage_Adminhtml_Model_System_Config_Backend_Translate extends Mage_Core_Model_Config_Data -{ - /** - * Path to config node with list of caches - * - * @var string - */ - const XML_PATH_INVALID_CACHES = 'dev/translate_inline/invalid_caches'; - - /** - * Set status 'invalidate' for blocks and other output caches - * - * @return Mage_Adminhtml_Model_System_Config_Backend_Translate - */ - protected function _afterSave() - { - $types = array_keys(Mage::getStoreConfig(self::XML_PATH_INVALID_CACHES)); - if ($this->isValueChanged()) { - Mage::app()->getCacheInstance()->invalidateType($types); - } - - return $this; - } -} + + */ +class Mage_Adminhtml_Model_System_Config_Backend_Translate extends Mage_Core_Model_Config_Data +{ + /** + * Path to config node with list of caches + * + * @var string + */ + const XML_PATH_INVALID_CACHES = 'dev/translate_inline/invalid_caches'; + + /** + * Set status 'invalidate' for blocks and other output caches + * + * @return Mage_Adminhtml_Model_System_Config_Backend_Translate + */ + protected function _afterSave() + { + $types = array_keys(Mage::getStoreConfig(self::XML_PATH_INVALID_CACHES)); + if ($this->isValueChanged()) { + Mage::app()->getCacheInstance()->invalidateType($types); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php index 189c04a8c9..40e059896e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php @@ -688,7 +688,7 @@ public function saveAction() } } - Mage::getModel('catalogrule/rule')->applyToProduct($productId); + Mage::getModel('catalogrule/rule')->applyAllRulesToProduct($productId); $this->_getSession()->addSuccess($this->__('The product has been saved.')); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php index 2e32d96c57..a2dd39859d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php @@ -27,26 +27,52 @@ class Mage_Adminhtml_Promo_WidgetController extends Mage_Adminhtml_Controller_Action { + /** + * Prepare block for chooser + * + * @return void + */ public function chooserAction() { - $block = false; - switch ($this->getRequest()->getParam('attribute')) { + $request = $this->getRequest(); + + switch ($request->getParam('attribute')) { case 'sku': $block = $this->getLayout()->createBlock( 'adminhtml/promo_widget_chooser_sku', 'promo_widget_chooser_sku', - array('js_form_object' => $this->getRequest()->getParam('form'), + array('js_form_object' => $request->getParam('form'), )); break; case 'category_ids': + $ids = $request->getParam('selected', array()); + if (is_array($ids)) { + foreach ($ids as $key => &$id) { + $id = (int) $id; + if ($id <= 0) { + unset($ids[$key]); + } + } + + $ids = array_unique($ids); + } else { + $ids = array(); + } + + $block = $this->getLayout()->createBlock( 'adminhtml/catalog_category_checkboxes_tree', 'promo_widget_chooser_category_ids', - array('js_form_object' => $this->getRequest()->getParam('form')) + array('js_form_object' => $request->getParam('form')) ) - ->setCategoryIds($this->getRequest()->getParam('selected', array())) + ->setCategoryIds($ids) ; break; + + default: + $block = false; + break; } + if ($block) { $this->getResponse()->setBody($block->toHtml()); } @@ -83,10 +109,9 @@ public function categoriesJsonAction() protected function _initCategory() { $categoryId = (int) $this->getRequest()->getParam('id',false); - $storeId = (int) $this->getRequest()->getParam('store'); - $category = Mage::getModel('catalog/category'); + $category = Mage::getModel('catalog/category'); $category->setStoreId($storeId); if ($categoryId) { @@ -102,6 +127,7 @@ protected function _initCategory() Mage::register('category', $category); Mage::register('current_category', $category); + return $category; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php index d10be9d214..1d16d14429 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php @@ -238,7 +238,8 @@ protected function _processData($action = null) /** * Saving of giftmessages */ - if ($giftmessages = $this->getRequest()->getPost('giftmessage')) { + $giftmessages = $this->getRequest()->getPost('giftmessage'); + if ($giftmessages) { $this->_getGiftmessageSaveModel()->setGiftmessages($giftmessages) ->saveAllInQuote(); } diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php index 376af71c88..ba2938af65 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php @@ -87,13 +87,14 @@ public function synchronizeAction() $this->_getSyncSingleton()->synchronize($storage); } catch (Exception $e) { Mage::logException($e); + $flag->passError($e); } $flag->setState(Mage_Core_Model_File_Storage_Flag::STATE_FINISHED)->save(); } /** - * Retrieve synchronize process state and it's parameters in json format + * Retrieve synchronize process state and it's parameters in json format * * @return void */ diff --git a/app/code/core/Mage/Authorizenet/Helper/Data.php b/app/code/core/Mage/Authorizenet/Helper/Data.php index 544b5a604a..aacbb22165 100755 --- a/app/code/core/Mage/Authorizenet/Helper/Data.php +++ b/app/code/core/Mage/Authorizenet/Helper/Data.php @@ -45,7 +45,7 @@ public function getAdminUrl($route, $params) return Mage::getModel('adminhtml/url')->getUrl($route, $params); } - /** + /** * Set secure url checkout is secure for current store. * * @param string $route diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost.php b/app/code/core/Mage/Authorizenet/Model/Directpost.php index 427e73247a..a36da2e754 100644 --- a/app/code/core/Mage/Authorizenet/Model/Directpost.php +++ b/app/code/core/Mage/Authorizenet/Model/Directpost.php @@ -132,7 +132,7 @@ public function canRefund() return $this->_canRefund; } - /** + /** * Check void availability * * @param Varien_Object $invoicePayment @@ -143,7 +143,7 @@ public function canVoid(Varien_Object $payment) return $this->_canVoid; } - /** + /** * Void the payment through gateway * * @param Varien_Object $payment @@ -168,9 +168,10 @@ public function void(Varien_Object $payment) if ($result->getTransactionId() != $payment->getParentTransactionId()) { $payment->setTransactionId($result->getTransactionId()); } + $shouldCloseCaptureTransaction = !(bool)$payment->getOrder()->canCreditmemo(); $payment ->setIsTransactionClosed(1) - ->setShouldCloseParentTransaction(1) + ->setShouldCloseParentTransaction($shouldCloseCaptureTransaction) ->setTransactionAdditionalInfo($this->_realTransactionIdKey, $result->getTransactionId()); return $this; } @@ -258,9 +259,10 @@ protected function _refund(Varien_Object $payment, $amount) if ($result->getTransactionId() != $payment->getParentTransactionId()) { $payment->setTransactionId($result->getTransactionId()); } + $shouldCloseCaptureTransaction = $payment->getOrder()->canCreditmemo() ? 0 : 1; $payment ->setIsTransactionClosed(1) - ->setShouldCloseParentTransaction(1) + ->setShouldCloseParentTransaction($shouldCloseCaptureTransaction) ->setTransactionAdditionalInfo($this->_realTransactionIdKey, $result->getTransactionId()); return $this; } @@ -537,7 +539,13 @@ protected function _authOrder(Mage_Sales_Model_Order $order) $response->getXTransId() ); - $order->setState(Mage_Sales_Model_Order::STATE_NEW, true, $message, false) + $orderState = Mage_Sales_Model_Order::STATE_PROCESSING; + $orderStatus = $this->getConfigData('order_status'); + if (!$orderStatus || $order->getIsVirtual()) { + $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState); + } + + $order->setState($orderState, $orderStatus ? $orderStatus : true, $message, false) ->save(); //match amounts. should be equals for authorization. diff --git a/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php b/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php index 4ffa63a85c..9c35b15617 100644 --- a/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php +++ b/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php @@ -114,8 +114,8 @@ public function placeAction() $requestToPaygate = $payment->getMethodInstance()->generateRequestFromOrder($order); $requestToPaygate->setControllerActionName($controller); - $requestToPaygate->setOrderSendConfirmation($sendConfirmationFlag); + $requestToPaygate->setStoreId($this->_getOrderCreateModel()->getQuote()->getStoreId()); $adminUrl = Mage::getSingleton('adminhtml/url'); if ($adminUrl->useSecretKey()) { diff --git a/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php b/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php index e4ab650249..b4b9308922 100644 --- a/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php +++ b/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php @@ -77,6 +77,9 @@ public function responseAction() } try { + if (!empty($data['store_id'])) { + $paymentMethod->setStore($data['store_id']); + } $paymentMethod->process($data); $result['success'] = 1; } diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php index 053eb865b0..c74aa5662b 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php @@ -19,7 +19,7 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Adminhtml + * @package Mage_Bundle * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php index db5aca9e25..3bed1be09f 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php @@ -1,82 +1,83 @@ -getAttribute('catalog_product', 'price_type'); -$taxClassAttribute = $installer->getAttribute('catalog_product', 'tax_class_id'); - -$productTable = $installer->getTable('catalog/product'); -$priceTypeTable = $productTable ."_". $priceTypeAttribute['backend_type']; -$taxClassTable = $productTable ."_". $taxClassAttribute['backend_type']; - -$db = $installer->getConnection(); -$db->beginTransaction(); -try { - // select bundle product ids with dynamic price - $select = $db->select() - ->from(array('attr' => $priceTypeTable), 'attr.entity_id') - ->joinLeft(array('e' => $productTable), 'attr.entity_id = e.entity_id', '') - ->where('attr.attribute_id = ?', $priceTypeAttribute['attribute_id']) - ->where('e.type_id = ?', 'bundle') - ->where('attr.value = ?', 0); - - $isDataChanged = false; - $stmt = $db->query($select); - // set "None" tax class attribute for bundles with dynamic price - while ($row = $stmt->fetch()) { - $data = array('value' => 0); - $where = array( - 'attribute_id = ?' => $taxClassAttribute['attribute_id'], - 'entity_id = ?' => $row['entity_id'] - ); - $count = $db->update($taxClassTable, $data, $where); - if ($count > 0) { - $isDataChanged = true; - } - } - - // set "Requere Reindex" status for some indexes if attributes data has been modified - if ($isDataChanged) { - $indexerCodes = array( - 'catalog_product_attribute', - 'catalog_product_price', - 'catalog_product_flat' - ); - - $indexer = Mage::getModel('index/process'); - foreach ($indexerCodes as $code) { - $indexer->load($code, 'indexer_code') - ->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX); - } - } - $db->commit(); - -} catch (Exception $e) { - $db->rollback(); - throw $e; -} +getAttribute('catalog_product', 'price_type'); +$taxClassAttribute = $installer->getAttribute('catalog_product', 'tax_class_id'); + +$productTable = $installer->getTable('catalog/product'); +$priceTypeTable = $productTable ."_". $priceTypeAttribute['backend_type']; +$taxClassTable = $productTable ."_". $taxClassAttribute['backend_type']; + +$db = $installer->getConnection(); +$db->beginTransaction(); +try { + // select bundle product ids with dynamic price + $select = $db->select() + ->from(array('attr' => $priceTypeTable), 'attr.entity_id') + ->joinLeft(array('e' => $productTable), 'attr.entity_id = e.entity_id', '') + ->where('attr.attribute_id = ?', $priceTypeAttribute['attribute_id']) + ->where('e.type_id = ?', 'bundle') + ->where('attr.value = ?', 0); + + $isDataChanged = false; + $stmt = $db->query($select); + // set "None" tax class attribute for bundles with dynamic price + while ($row = $stmt->fetch()) { + $data = array('value' => 0); + $where = array( + 'attribute_id = ?' => $taxClassAttribute['attribute_id'], + 'entity_id = ?' => $row['entity_id'] + ); + $count = $db->update($taxClassTable, $data, $where); + if ($count > 0) { + $isDataChanged = true; + } + } + + // set "Require Reindex" status for some indexes if attributes data has been modified + if ($isDataChanged) { + $indexerCodes = array( + 'catalog_product_attribute', + 'catalog_product_price', + 'catalog_product_flat' + ); + + $indexer = Mage::getModel('index/process'); + foreach ($indexerCodes as $code) { + $indexer->load($code, 'indexer_code') + ->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX); + } + } + $db->commit(); + +} catch (Exception $e) { + $db->rollback(); + throw $e; +} + diff --git a/app/code/core/Mage/Catalog/Block/Product/New.php b/app/code/core/Mage/Catalog/Block/Product/New.php index 439789c73f..cd2b3461d7 100644 --- a/app/code/core/Mage/Catalog/Block/Product/New.php +++ b/app/code/core/Mage/Catalog/Block/Product/New.php @@ -88,11 +88,20 @@ protected function _beforeToHtml() $collection = $this->_addProductAttributesAndPrices($collection) ->addStoreFilter() - ->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate)) + ->addAttributeToFilter('news_from_date', array('or'=> array( + 0 => array('date' => true, 'to' => $todayDate), + 1 => array('is' => new Zend_Db_Expr('null'))) + ), 'left') ->addAttributeToFilter('news_to_date', array('or'=> array( 0 => array('date' => true, 'from' => $todayDate), 1 => array('is' => new Zend_Db_Expr('null'))) ), 'left') + ->addAttributeToFilter( + array( + array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')), + array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null')) + ) + ) ->addAttributeToSort('news_from_date', 'desc') ->setPageSize($this->getProductsCount()) ->setCurPage(1) diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php index a8d83a717f..cd0143a578 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php @@ -125,6 +125,7 @@ public function getMaxPriceInt() $maxPrice = floor($maxPrice); $this->setData('max_price_int', $maxPrice); } + return $maxPrice; } @@ -142,6 +143,7 @@ public function getRangeItemCounts($range) $items = $this->_getResource()->getCount($this, $range); $this->setData($rangeKey, $items); } + return $items; } @@ -157,6 +159,7 @@ protected function _renderItemLabel($range, $value) $store = Mage::app()->getStore(); $fromPrice = $store->formatPrice(($value-1)*$range); $toPrice = $store->formatPrice($value*$range); + return Mage::helper('catalog')->__('%s - %s', $fromPrice, $toPrice); } @@ -175,6 +178,7 @@ protected function _getCacheKey() ; $taxReq = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false); $key.= implode('_', $taxReq->getData()); + return $key; } diff --git a/app/code/core/Mage/Catalog/Model/Product.php b/app/code/core/Mage/Catalog/Model/Product.php index c8a0afc0ab..e9391a733f 100644 --- a/app/code/core/Mage/Catalog/Model/Product.php +++ b/app/code/core/Mage/Catalog/Model/Product.php @@ -647,13 +647,14 @@ public function getFormatedPrice() * Sets final price of product * * This func is equal to magic 'setFinalPrice()', but added as a separate func, because in cart with bundle products it's called - * very often in Item->getProduct(). So removing chaing of magic with more cpu consuming algorithms gives nice optimization boost. + * very often in Item->getProduct(). So removing chain of magic with more cpu consuming algorithms gives nice optimization boost. * - * @return array + * @return Mage_Catalog_Model_Product */ public function setFinalPrice($price) { $this->_data['final_price'] = $price; + return $this; } /** @@ -1394,7 +1395,7 @@ public function isComposite() public function canConfigure() { $options = $this->getOptions(); - return $this->isComposite() || !empty($options) || $this->getTypeInstance(true)->canConfigure($this); + return !empty($options) || $this->getTypeInstance(true)->canConfigure($this); } /** diff --git a/app/code/core/Mage/Catalog/Model/Product/Api.php b/app/code/core/Mage/Catalog/Model/Product/Api.php index 4af35ff11c..870609f19e 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Api.php @@ -56,7 +56,7 @@ public function __construct() public function items($filters = null, $store = null) { $collection = Mage::getModel('catalog/product')->getCollection() - ->setStoreId($this->_getStoreId($store)) + ->addStoreFilter($this->_getStoreId($store)) ->addAttributeToSelect('name'); if (is_array($filters)) { diff --git a/app/code/core/Mage/Catalog/Model/Product/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Api/V2.php index 59db16024b..22bc9b48d7 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Api/V2.php @@ -44,7 +44,7 @@ class Mage_Catalog_Model_Product_Api_V2 extends Mage_Catalog_Model_Product_Api public function items($filters = null, $store = null) { $collection = Mage::getModel('catalog/product')->getCollection() - ->setStoreId($this->_getStoreId($store)) + ->addStoreFilter($this->_getStoreId($store)) ->addAttributeToSelect('name'); $preparedFilters = array(); diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Sku.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Sku.php index 135884a5e0..7e69c4bef2 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Sku.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Sku.php @@ -1,62 +1,62 @@ - - */ -class Mage_Catalog_Model_Product_Attribute_Backend_Sku extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract -{ - /** - * Maximum SKU string length - * - * @var string - */ - const SKU_MAX_LENGTH = 64; - - /** - * Validate SKU - * - * @param Mage_Catalog_Model_Product $object - * @throws Mage_Core_Exception - * @return bool - */ - public function validate($object) - { - $helper = Mage::helper('core/string'); - - if ($helper->strlen($object->getSku()) > self::SKU_MAX_LENGTH) { - Mage::throwException( - Mage::helper('catalog')->__('SKU length should be %s characters maximum.', self::SKU_MAX_LENGTH) - ); - } - return parent::validate($object); - } -} + + */ +class Mage_Catalog_Model_Product_Attribute_Backend_Sku extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Maximum SKU string length + * + * @var string + */ + const SKU_MAX_LENGTH = 64; + + /** + * Validate SKU + * + * @param Mage_Catalog_Model_Product $object + * @throws Mage_Core_Exception + * @return bool + */ + public function validate($object) + { + $helper = Mage::helper('core/string'); + + if ($helper->strlen($object->getSku()) > self::SKU_MAX_LENGTH) { + Mage::throwException( + Mage::helper('catalog')->__('SKU length should be %s characters maximum.', self::SKU_MAX_LENGTH) + ); + } + return parent::validate($object); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php index 2bc23a64e7..fe1a65d28f 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php @@ -473,16 +473,18 @@ public function isSalable($product = null) */ public function getProductByAttributes($attributesInfo, $product = null) { - foreach ($this->getUsedProducts(null, $product) as $productObject) { - $checkRes = true; - foreach ($attributesInfo as $attributeId => $attributeValue) { - $code = $this->getAttributeById($attributeId, $product)->getAttributeCode(); - if ($productObject->getData($code) != $attributeValue) { - $checkRes = false; + if (is_array($attributesInfo) && !empty($attributesInfo)) { + foreach ($this->getUsedProducts(null, $product) as $productObject) { + $checkRes = true; + foreach ($attributesInfo as $attributeId => $attributeValue) { + $code = $this->getAttributeById($attributeId, $product)->getAttributeCode(); + if ($productObject->getData($code) != $attributeValue) { + $checkRes = false; + } + } + if ($checkRes) { + return $productObject; } - } - if ($checkRes) { - return $productObject; } } return null; @@ -555,7 +557,8 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process /** * $attributes = array($attributeId=>$attributeValue) */ - if ($subProduct = $this->getProductByAttributes($attributes, $product)) { + $subProduct = $this->getProductByAttributes($attributes, $product); + if ($subProduct) { $product->addCustomOption('attributes', serialize($attributes)); $product->addCustomOption('product_qty_'.$subProduct->getId(), 1, $subProduct); $product->addCustomOption('simple_product', $subProduct->getId(), $subProduct); @@ -590,6 +593,8 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process } $result[] = $_result[0]; return $result; + } else if (!$this->_isStrictProcessMode($processMode)) { + return $result; } } } diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.42-1.4.0.0.43.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.42-1.4.0.0.43.php index 56966a3b7f..d0ffeba93b 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.42-1.4.0.0.43.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.42-1.4.0.0.43.php @@ -1,31 +1,31 @@ -getEntityTypeId('catalog_product'); -$installer->updateAttribute($productEntityTypeId, 'sku', 'backend_model', 'catalog/product_attribute_backend_sku'); +getEntityTypeId('catalog_product'); +$installer->updateAttribute($productEntityTypeId, 'sku', 'backend_model', 'catalog/product_attribute_backend_sku'); diff --git a/app/code/core/Mage/CatalogRule/Model/Rule.php b/app/code/core/Mage/CatalogRule/Model/Rule.php index 3b6fbd805f..abf7e493fc 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule.php @@ -257,6 +257,22 @@ public function applyAll() } } + /** + * Apply all price rules to product + * + * @param int|Mage_Catalog_Model_Product $product + * @return Mage_CatalogRule_Model_Rule + */ + public function applyAllRulesToProduct($product) + { + $this->_getResource()->applyAllRulesForDateRange(NULL, NULL, $product); + $this->_invalidateCache(); + $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price'); + if ($indexProcess) { + $indexProcess->reindexAll(); + } + } + /** * Calculate price using catalog price rule of product * diff --git a/app/code/core/Mage/Checkout/Block/Links.php b/app/code/core/Mage/Checkout/Block/Links.php index 88d05c754c..f6600778b5 100644 --- a/app/code/core/Mage/Checkout/Block/Links.php +++ b/app/code/core/Mage/Checkout/Block/Links.php @@ -41,7 +41,8 @@ class Mage_Checkout_Block_Links extends Mage_Core_Block_Template */ public function addCartLink() { - if ($parentBlock = $this->getParentBlock()) { + $parentBlock = $this->getParentBlock(); + if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) { $count = $this->helper('checkout/cart')->getSummaryCount(); if( $count == 1 ) { @@ -67,7 +68,9 @@ public function addCheckoutLink() if (!$this->helper('checkout')->canOnepageCheckout()) { return $this; } - if ($parentBlock = $this->getParentBlock()) { + + $parentBlock = $this->getParentBlock(); + if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) { $text = $this->__('Checkout'); $parentBlock->addLink($text, 'checkout', $text, true, array(), 60, null, 'class="top-link-checkout"'); } diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource.php b/app/code/core/Mage/Checkout/Model/Api/Resource.php index 4229c3b8e5..b683b95f66 100644 --- a/app/code/core/Mage/Checkout/Model/Api/Resource.php +++ b/app/code/core/Mage/Checkout/Model/Api/Resource.php @@ -1,236 +1,236 @@ - - */ -class Mage_Checkout_Model_Api_Resource extends Mage_Api_Model_Resource_Abstract -{ - /** - * Attributes map array per entity type - * - * @var array - */ - protected $_attributesMap = array( - 'global' => array(), - ); - - /** - * Default ignored attribute codes per entity type - * - * @var array - */ - protected $_ignoredAttributeCodes = array( - 'global' => array('entity_id', 'attribute_set_id', 'entity_type_id') - ); - - /** - * Field name in session for saving store id - * @var string - */ - protected $_storeIdSessionField = 'store_id'; - - - /** - * Check if quote already exist with provided quoteId for creating - * - * @param int $quoteId - * @return bool - */ - protected function _isQuoteExist($quoteId) - { - if (empty($quoteId)) { - return false; - } - - try { - $quote = $this->_getQuote($quoteId); - } catch (Mage_Api_Exception $e) { - return false; - } - - if (!is_null($quote->getId())) { - $this->_fault('quote_already_exist'); - } - - return false; - } - - /** - * Retrieves store id from store code, if no store id specified, - * it use set session or admin store - * - * @param string|int $store - * @return int - */ - protected function _getStoreId($store = null) - { - if (is_null($store)) { - $store = ($this->_getSession()->hasData($this->_storeIdSessionField) - ? $this->_getSession()->getData($this->_storeIdSessionField) : 0); - } - - try { - $storeId = Mage::app()->getStore($store)->getId(); - - } catch (Mage_Core_Model_Store_Exception $e) { - $this->_fault('store_not_exists'); - } - - return $storeId; - } - - /** - * Retrieves quote by quote identifier and store code or by quote identifier - * - * @param int $quoteId - * @param string|int $store - * @return Mage_Sales_Model_Quote - */ - protected function _getQuote($quoteId, $store = null) - { - /** @var $quote Mage_Sales_Model_Quote */ - $quote = Mage::getModel("sales/quote"); - - if (!(is_string($store) && is_integer($store))) { - $quote->loadByIdWithoutStore($quoteId); - } else { - $storeId = $this->_getStoreId($store); - - $quote->setStoreId($storeId) - ->load($quoteId); - } - if (is_null($quote->getId())) { - $this->_fault('quote_not_exists'); - } - - return $quote; - } - - /** - * Get store identifier by quote identifier - * - * @param int $quoteId - * @return int - */ - protected function _getStoreIdFromQuote($quoteId) - { - /** @var $quote Mage_Sales_Model_Quote */ - $quote = Mage::getModel('sales/quote') - ->loadByIdWithoutStore($quoteId); - - return $quote->getStoreId(); - } - - /** - * Update attributes for entity - * - * @param array $data - * @param Mage_Core_Model_Abstract $object - * @param array $attributes - * @return Mage_Checkout_Model_Api_Resource - */ - protected function _updateAttributes($data, $object, $type, array $attributes = null) - { - foreach ($data as $attribute=>$value) { - if ($this->_isAllowedAttribute($attribute, $type, $attributes)) { - $object->setData($attribute, $value); - } - } - - return $this; - } - - /** - * Retrieve entity attributes values - * - * @param Mage_Core_Model_Abstract $object - * @param array $attributes - * @return Mage_Checkout_Model_Api_Resource - */ - protected function _getAttributes($object, $type, array $attributes = null) - { - $result = array(); - - if (!is_object($object)) { - return $result; - } - - foreach ($object->getData() as $attribute=>$value) { - if (is_object($value)) { - continue; - } - - if ($this->_isAllowedAttribute($attribute, $type, $attributes)) { - $result[$attribute] = $value; - } - } - - foreach ($this->_attributesMap['global'] as $alias=>$attributeCode) { - $result[$alias] = $object->getData($attributeCode); - } - - if (isset($this->_attributesMap[$type])) { - foreach ($this->_attributesMap[$type] as $alias=>$attributeCode) { - $result[$alias] = $object->getData($attributeCode); - } - } - - return $result; - } - - /** - * Check is attribute allowed to usage - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param string $entityType - * @param array $attributes - * @return bool - */ - protected function _isAllowedAttribute($attributeCode, $type, array $attributes = null) - { - if (!empty($attributes) - && !(in_array($attributeCode, $attributes))) { - return false; - } - - if (in_array($attributeCode, $this->_ignoredAttributeCodes['global'])) { - return false; - } - - if (isset($this->_ignoredAttributeCodes[$type]) - && in_array($attributeCode, $this->_ignoredAttributeCodes[$type])) { - return false; - } - - return true; - } - -} + + */ +class Mage_Checkout_Model_Api_Resource extends Mage_Api_Model_Resource_Abstract +{ + /** + * Attributes map array per entity type + * + * @var array + */ + protected $_attributesMap = array( + 'global' => array(), + ); + + /** + * Default ignored attribute codes per entity type + * + * @var array + */ + protected $_ignoredAttributeCodes = array( + 'global' => array('entity_id', 'attribute_set_id', 'entity_type_id') + ); + + /** + * Field name in session for saving store id + * @var string + */ + protected $_storeIdSessionField = 'store_id'; + + + /** + * Check if quote already exist with provided quoteId for creating + * + * @param int $quoteId + * @return bool + */ + protected function _isQuoteExist($quoteId) + { + if (empty($quoteId)) { + return false; + } + + try { + $quote = $this->_getQuote($quoteId); + } catch (Mage_Api_Exception $e) { + return false; + } + + if (!is_null($quote->getId())) { + $this->_fault('quote_already_exist'); + } + + return false; + } + + /** + * Retrieves store id from store code, if no store id specified, + * it use set session or admin store + * + * @param string|int $store + * @return int + */ + protected function _getStoreId($store = null) + { + if (is_null($store)) { + $store = ($this->_getSession()->hasData($this->_storeIdSessionField) + ? $this->_getSession()->getData($this->_storeIdSessionField) : 0); + } + + try { + $storeId = Mage::app()->getStore($store)->getId(); + + } catch (Mage_Core_Model_Store_Exception $e) { + $this->_fault('store_not_exists'); + } + + return $storeId; + } + + /** + * Retrieves quote by quote identifier and store code or by quote identifier + * + * @param int $quoteId + * @param string|int $store + * @return Mage_Sales_Model_Quote + */ + protected function _getQuote($quoteId, $store = null) + { + /** @var $quote Mage_Sales_Model_Quote */ + $quote = Mage::getModel("sales/quote"); + + if (!(is_string($store) && is_integer($store))) { + $quote->loadByIdWithoutStore($quoteId); + } else { + $storeId = $this->_getStoreId($store); + + $quote->setStoreId($storeId) + ->load($quoteId); + } + if (is_null($quote->getId())) { + $this->_fault('quote_not_exists'); + } + + return $quote; + } + + /** + * Get store identifier by quote identifier + * + * @param int $quoteId + * @return int + */ + protected function _getStoreIdFromQuote($quoteId) + { + /** @var $quote Mage_Sales_Model_Quote */ + $quote = Mage::getModel('sales/quote') + ->loadByIdWithoutStore($quoteId); + + return $quote->getStoreId(); + } + + /** + * Update attributes for entity + * + * @param array $data + * @param Mage_Core_Model_Abstract $object + * @param array $attributes + * @return Mage_Checkout_Model_Api_Resource + */ + protected function _updateAttributes($data, $object, $type, array $attributes = null) + { + foreach ($data as $attribute=>$value) { + if ($this->_isAllowedAttribute($attribute, $type, $attributes)) { + $object->setData($attribute, $value); + } + } + + return $this; + } + + /** + * Retrieve entity attributes values + * + * @param Mage_Core_Model_Abstract $object + * @param array $attributes + * @return Mage_Checkout_Model_Api_Resource + */ + protected function _getAttributes($object, $type, array $attributes = null) + { + $result = array(); + + if (!is_object($object)) { + return $result; + } + + foreach ($object->getData() as $attribute=>$value) { + if (is_object($value)) { + continue; + } + + if ($this->_isAllowedAttribute($attribute, $type, $attributes)) { + $result[$attribute] = $value; + } + } + + foreach ($this->_attributesMap['global'] as $alias=>$attributeCode) { + $result[$alias] = $object->getData($attributeCode); + } + + if (isset($this->_attributesMap[$type])) { + foreach ($this->_attributesMap[$type] as $alias=>$attributeCode) { + $result[$alias] = $object->getData($attributeCode); + } + } + + return $result; + } + + /** + * Check is attribute allowed to usage + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param string $entityType + * @param array $attributes + * @return bool + */ + protected function _isAllowedAttribute($attributeCode, $type, array $attributes = null) + { + if (!empty($attributes) + && !(in_array($attributeCode, $attributes))) { + return false; + } + + if (in_array($attributeCode, $this->_ignoredAttributeCodes['global'])) { + return false; + } + + if (isset($this->_ignoredAttributeCodes[$type]) + && in_array($attributeCode, $this->_ignoredAttributeCodes[$type])) { + return false; + } + + return true; + } + +} diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php index 407f589e73..c83dabea5d 100644 --- a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php +++ b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php @@ -1,213 +1,213 @@ - - */ -class Mage_Checkout_Model_Api_Resource_Customer extends Mage_Checkout_Model_Api_Resource -{ - /** - * Customer address types - */ - const ADDRESS_BILLING = Mage_Sales_Model_Quote_Address::TYPE_BILLING; - const ADDRESS_SHIPPING = Mage_Sales_Model_Quote_Address::TYPE_SHIPPING; - - /** - * Customer checkout types - */ - const MODE_CUSTOMER = Mage_Checkout_Model_Type_Onepage::METHOD_CUSTOMER; - const MODE_REGISTER = Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER; - const MODE_GUEST = Mage_Checkout_Model_Type_Onepage::METHOD_GUEST; - - - /** - * - */ - protected function _getCustomer($customerId) - { - /** @var $customer Mage_Customer_Model_Customer */ - $customer = Mage::getModel('customer/customer') - ->load($customerId); - if (!$customer->getId()) { - $this->_fault('customer_not_exists'); - } - - return $customer; - } - - /** - * Get customer address by identifier - * - * @param int $addressId - * @return Mage_Customer_Model_Address - */ - protected function _getCustomerAddress($addressId) - { - $address = Mage::getModel('customer/address')->load((int)$addressId); - if (is_null($address->getId())) { - $this->_fault('invalid_address_data'); - } - - $address->explodeStreetAddress(); - if ($address->getRegionId()) { - $address->setRegion($address->getRegionId()); - } - return $address; - } - - /** - * @param Mage_Sales_Model_Quote $quote - * @return bool - */ - public function prepareCustomerForQuote(Mage_Sales_Model_Quote $quote) - { - $isNewCustomer = false; - switch ($quote->getCheckoutMethod()) { - case self::MODE_GUEST: - $this->_prepareGuestQuote($quote); - break; - case self::MODE_REGISTER: - $this->_prepareNewCustomerQuote($quote); - $isNewCustomer = true; - break; - default: - $this->_prepareCustomerQuote($quote); - break; - } - - return $isNewCustomer; - } - - /** - * Prepare quote for guest checkout order submit - * - * @param Mage_Sales_Model_Quote $quote - * @return Mage_Checkout_Model_Api_Resource_Customer - */ - protected function _prepareGuestQuote(Mage_Sales_Model_Quote $quote) - { - $quote->setCustomerId(null) - ->setCustomerEmail($quote->getBillingAddress()->getEmail()) - ->setCustomerIsGuest(true) - ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); - return $this; - } - - /** - * Prepare quote for customer registration and customer order submit - * - * @param Mage_Sales_Model_Quote $quote - * @return Mage_Checkout_Model_Api_Resource_Customer - */ - protected function _prepareNewCustomerQuote(Mage_Sales_Model_Quote $quote) - { - $billing = $quote->getBillingAddress(); - $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); - - //$customer = Mage::getModel('customer/customer'); - $customer = $quote->getCustomer(); - /* @var $customer Mage_Customer_Model_Customer */ - $customerBilling = $billing->exportCustomerAddress(); - $customer->addAddress($customerBilling); - $billing->setCustomerAddress($customerBilling); - $customerBilling->setIsDefaultBilling(true); - if ($shipping && !$shipping->getSameAsBilling()) { - $customerShipping = $shipping->exportCustomerAddress(); - $customer->addAddress($customerShipping); - $shipping->setCustomerAddress($customerShipping); - $customerShipping->setIsDefaultShipping(true); - } else { - $customerBilling->setIsDefaultShipping(true); - } - - Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer); - $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); - $customer->setPasswordHash($customer->hashPassword($customer->getPassword())); - $quote->setCustomer($customer) - ->setCustomerId(true); - - return $this; - } - - /** - * Prepare quote for customer order submit - * - * @param Mage_Sales_Model_Quote $quote - * @return Mage_Checkout_Model_Api_Resource_Customer - */ - protected function _prepareCustomerQuote(Mage_Sales_Model_Quote $quote) - { - $billing = $quote->getBillingAddress(); - $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); - - $customer = $quote->getCustomer(); - if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) { - $customerBilling = $billing->exportCustomerAddress(); - $customer->addAddress($customerBilling); - $billing->setCustomerAddress($customerBilling); - } - if ($shipping && ((!$shipping->getCustomerId() && !$shipping->getSameAsBilling()) - || (!$shipping->getSameAsBilling() && $shipping->getSaveInAddressBook()))) { - $customerShipping = $shipping->exportCustomerAddress(); - $customer->addAddress($customerShipping); - $shipping->setCustomerAddress($customerShipping); - } - - if (isset($customerBilling) && !$customer->getDefaultBilling()) { - $customerBilling->setIsDefaultBilling(true); - } - if ($shipping && isset($customerShipping) && !$customer->getDefaultShipping()) { - $customerShipping->setIsDefaultShipping(true); - } else if (isset($customerBilling) && !$customer->getDefaultShipping()) { - $customerBilling->setIsDefaultShipping(true); - } - $quote->setCustomer($customer); - - return $this; - } - - /** - * Involve new customer to system - * - * @param Mage_Sales_Model_Quote $quote - * @return Mage_Checkout_Model_Api_Resource_Customer - */ - public function involveNewCustomer(Mage_Sales_Model_Quote $quote) - { - $customer = $quote->getCustomer(); - if ($customer->isConfirmationRequired()) { - $customer->sendNewAccountEmail('confirmation'); - } else { - $customer->sendNewAccountEmail(); - } - - return $this; - } -} + + */ +class Mage_Checkout_Model_Api_Resource_Customer extends Mage_Checkout_Model_Api_Resource +{ + /** + * Customer address types + */ + const ADDRESS_BILLING = Mage_Sales_Model_Quote_Address::TYPE_BILLING; + const ADDRESS_SHIPPING = Mage_Sales_Model_Quote_Address::TYPE_SHIPPING; + + /** + * Customer checkout types + */ + const MODE_CUSTOMER = Mage_Checkout_Model_Type_Onepage::METHOD_CUSTOMER; + const MODE_REGISTER = Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER; + const MODE_GUEST = Mage_Checkout_Model_Type_Onepage::METHOD_GUEST; + + + /** + * + */ + protected function _getCustomer($customerId) + { + /** @var $customer Mage_Customer_Model_Customer */ + $customer = Mage::getModel('customer/customer') + ->load($customerId); + if (!$customer->getId()) { + $this->_fault('customer_not_exists'); + } + + return $customer; + } + + /** + * Get customer address by identifier + * + * @param int $addressId + * @return Mage_Customer_Model_Address + */ + protected function _getCustomerAddress($addressId) + { + $address = Mage::getModel('customer/address')->load((int)$addressId); + if (is_null($address->getId())) { + $this->_fault('invalid_address_data'); + } + + $address->explodeStreetAddress(); + if ($address->getRegionId()) { + $address->setRegion($address->getRegionId()); + } + return $address; + } + + /** + * @param Mage_Sales_Model_Quote $quote + * @return bool + */ + public function prepareCustomerForQuote(Mage_Sales_Model_Quote $quote) + { + $isNewCustomer = false; + switch ($quote->getCheckoutMethod()) { + case self::MODE_GUEST: + $this->_prepareGuestQuote($quote); + break; + case self::MODE_REGISTER: + $this->_prepareNewCustomerQuote($quote); + $isNewCustomer = true; + break; + default: + $this->_prepareCustomerQuote($quote); + break; + } + + return $isNewCustomer; + } + + /** + * Prepare quote for guest checkout order submit + * + * @param Mage_Sales_Model_Quote $quote + * @return Mage_Checkout_Model_Api_Resource_Customer + */ + protected function _prepareGuestQuote(Mage_Sales_Model_Quote $quote) + { + $quote->setCustomerId(null) + ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerIsGuest(true) + ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); + return $this; + } + + /** + * Prepare quote for customer registration and customer order submit + * + * @param Mage_Sales_Model_Quote $quote + * @return Mage_Checkout_Model_Api_Resource_Customer + */ + protected function _prepareNewCustomerQuote(Mage_Sales_Model_Quote $quote) + { + $billing = $quote->getBillingAddress(); + $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); + + //$customer = Mage::getModel('customer/customer'); + $customer = $quote->getCustomer(); + /* @var $customer Mage_Customer_Model_Customer */ + $customerBilling = $billing->exportCustomerAddress(); + $customer->addAddress($customerBilling); + $billing->setCustomerAddress($customerBilling); + $customerBilling->setIsDefaultBilling(true); + if ($shipping && !$shipping->getSameAsBilling()) { + $customerShipping = $shipping->exportCustomerAddress(); + $customer->addAddress($customerShipping); + $shipping->setCustomerAddress($customerShipping); + $customerShipping->setIsDefaultShipping(true); + } else { + $customerBilling->setIsDefaultShipping(true); + } + + Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer); + $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); + $customer->setPasswordHash($customer->hashPassword($customer->getPassword())); + $quote->setCustomer($customer) + ->setCustomerId(true); + + return $this; + } + + /** + * Prepare quote for customer order submit + * + * @param Mage_Sales_Model_Quote $quote + * @return Mage_Checkout_Model_Api_Resource_Customer + */ + protected function _prepareCustomerQuote(Mage_Sales_Model_Quote $quote) + { + $billing = $quote->getBillingAddress(); + $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); + + $customer = $quote->getCustomer(); + if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) { + $customerBilling = $billing->exportCustomerAddress(); + $customer->addAddress($customerBilling); + $billing->setCustomerAddress($customerBilling); + } + if ($shipping && ((!$shipping->getCustomerId() && !$shipping->getSameAsBilling()) + || (!$shipping->getSameAsBilling() && $shipping->getSaveInAddressBook()))) { + $customerShipping = $shipping->exportCustomerAddress(); + $customer->addAddress($customerShipping); + $shipping->setCustomerAddress($customerShipping); + } + + if (isset($customerBilling) && !$customer->getDefaultBilling()) { + $customerBilling->setIsDefaultBilling(true); + } + if ($shipping && isset($customerShipping) && !$customer->getDefaultShipping()) { + $customerShipping->setIsDefaultShipping(true); + } else if (isset($customerBilling) && !$customer->getDefaultShipping()) { + $customerBilling->setIsDefaultShipping(true); + } + $quote->setCustomer($customer); + + return $this; + } + + /** + * Involve new customer to system + * + * @param Mage_Sales_Model_Quote $quote + * @return Mage_Checkout_Model_Api_Resource_Customer + */ + public function involveNewCustomer(Mage_Sales_Model_Quote $quote) + { + $customer = $quote->getCustomer(); + if ($customer->isConfirmationRequired()) { + $customer->sendNewAccountEmail('confirmation'); + } else { + $customer->sendNewAccountEmail(); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource/Product.php b/app/code/core/Mage/Checkout/Model/Api/Resource/Product.php index f67544f2bf..7adb3dc747 100644 --- a/app/code/core/Mage/Checkout/Model/Api/Resource/Product.php +++ b/app/code/core/Mage/Checkout/Model/Api/Resource/Product.php @@ -1,95 +1,94 @@ - - */ - -/** - * ${CLASS_DESCRIPTION} - */ -class Mage_Checkout_Model_Api_Resource_Product extends Mage_Checkout_Model_Api_Resource -{ - /** - * Default ignored attribute codes - * - * @var array - */ - protected $_ignoredAttributeCodes = array('entity_id', 'attribute_set_id', 'entity_type_id'); - - /** - * Return loaded product instance - * - * @param int|string $productId (SKU or ID) - * @param int|string $store - * @return Mage_Catalog_Model_Product - */ - protected function _getProduct($productId, $store = null, $identifierType = null) - { - $loadByIdOnFalse = false; - if ($identifierType == null) { - $identifierType = 'sku'; - $loadByIdOnFalse = true; - } - $product = Mage::getModel('catalog/product'); - if ($store !== null) { - $product->setStoreId($this->_getStoreId($store)); - } - /* @var $product Mage_Catalog_Model_Product */ - if ($identifierType == 'sku') { - $idBySku = $product->getIdBySku($productId); - if ($idBySku) { - $productId = $idBySku; - } - if ($idBySku || $loadByIdOnFalse) { - $product->load($productId); - } - } elseif ($identifierType == 'id') { - $product->load($productId); - } - return $product; - } - - /** - * Get request for product add to cart procedure - * - * @param mixed $requestInfo - * @return Varien_Object - */ - protected function _getProductRequest($requestInfo) - { - if ($requestInfo instanceof Varien_Object) { - $request = $requestInfo; - } elseif (is_numeric($requestInfo)) { - $request = new Varien_Object(); - $request->setQty($requestInfo); - } else { - $request = new Varien_Object($requestInfo); - } - - if (!$request->hasQty()) { - $request->setQty(1); - } - return $request; - } -} +setStoreId($this->_getStoreId($store)); + } + /* @var $product Mage_Catalog_Model_Product */ + if ($identifierType == 'sku') { + $idBySku = $product->getIdBySku($productId); + if ($idBySku) { + $productId = $idBySku; + } + if ($idBySku || $loadByIdOnFalse) { + $product->load($productId); + } + } elseif ($identifierType == 'id') { + $product->load($productId); + } + return $product; + } + + /** + * Get request for product add to cart procedure + * + * @param mixed $requestInfo + * @return Varien_Object + */ + protected function _getProductRequest($requestInfo) + { + if ($requestInfo instanceof Varien_Object) { + $request = $requestInfo; + } elseif (is_numeric($requestInfo)) { + $request = new Varien_Object(); + $request->setQty($requestInfo); + } else { + $request = new Varien_Object($requestInfo); + } + + if (!$request->hasQty()) { + $request->setQty(1); + } + return $request; + } +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php index 4bf73b0809..c64dccaff7 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php @@ -1,111 +1,111 @@ - - */ - -class Mage_Checkout_Model_Cart_Coupon_Api extends Mage_Checkout_Model_Api_Resource -{ - /** - * @param $quoteId - * @param $couponCode - * @param $storeId - * @return bool - */ - public function add($quoteId, $couponCode, $store = null) - { - return $this->_applyCoupon($quoteId, $couponCode, $store = null); - } - - /** - * @param $quoteId - * @param $storeId - * @return void - */ - public function remove($quoteId, $store = null) - { - $couponCode = ''; - return $this->_applyCoupon($quoteId, $couponCode, $store); - } - - /** - * @param $quoteId - * @param $storeId - * @return string - */ - public function get($quoteId, $store = null) - { - $quote = $this->_getQuote($quoteId, $store); - - return $quote->getCouponCode(); - } - - /** - * @param $quoteId - * @param $couponCode - * @param $store - * @return bool - */ - protected function _applyCoupon($quoteId, $couponCode, $store = null) - { - $quote = $this->_getQuote($quoteId, $store); - - if (!$quote->getItemsCount()) { - return false; - } - - $oldCouponCode = $quote->getCouponCode(); - if (!strlen($couponCode) && !strlen($oldCouponCode)) { - return false; - } - - try { - $quote->getShippingAddress()->setCollectShippingRates(true); - $quote->setCouponCode(strlen($couponCode) ? $couponCode : '') - ->collectTotals() - ->save(); - } catch (Exception $e) { - $this->_fault("cannot_apply_coupon_code", $e->getMessage()); - } - - if ($couponCode) { - if (!$couponCode == $quote->getCouponCode()) { - $this->_fault('coupon_code_is_not_valid'); - } - } else { - $this->_fault('coupon_code_was_canceled'); - } - - return true; - } - - -} + + */ + +class Mage_Checkout_Model_Cart_Coupon_Api extends Mage_Checkout_Model_Api_Resource +{ + /** + * @param $quoteId + * @param $couponCode + * @param $storeId + * @return bool + */ + public function add($quoteId, $couponCode, $store = null) + { + return $this->_applyCoupon($quoteId, $couponCode, $store = null); + } + + /** + * @param $quoteId + * @param $storeId + * @return void + */ + public function remove($quoteId, $store = null) + { + $couponCode = ''; + return $this->_applyCoupon($quoteId, $couponCode, $store); + } + + /** + * @param $quoteId + * @param $storeId + * @return string + */ + public function get($quoteId, $store = null) + { + $quote = $this->_getQuote($quoteId, $store); + + return $quote->getCouponCode(); + } + + /** + * @param $quoteId + * @param $couponCode + * @param $store + * @return bool + */ + protected function _applyCoupon($quoteId, $couponCode, $store = null) + { + $quote = $this->_getQuote($quoteId, $store); + + if (!$quote->getItemsCount()) { + return false; + } + + $oldCouponCode = $quote->getCouponCode(); + if (!strlen($couponCode) && !strlen($oldCouponCode)) { + return false; + } + + try { + $quote->getShippingAddress()->setCollectShippingRates(true); + $quote->setCouponCode(strlen($couponCode) ? $couponCode : '') + ->collectTotals() + ->save(); + } catch (Exception $e) { + $this->_fault("cannot_apply_coupon_code", $e->getMessage()); + } + + if ($couponCode) { + if (!$couponCode == $quote->getCouponCode()) { + $this->_fault('coupon_code_is_not_valid'); + } + } else { + $this->_fault('coupon_code_was_canceled'); + } + + return true; + } + + +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api/V2.php index 96df932189..f4fc3f3e46 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api/V2.php @@ -1,38 +1,38 @@ - - */ - -class Mage_Checkout_Model_Cart_Coupon_Api_V2 extends Mage_Checkout_Model_Cart_Coupon_Api -{ - -} + + */ + +class Mage_Checkout_Model_Cart_Coupon_Api_V2 extends Mage_Checkout_Model_Cart_Coupon_Api +{ + +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Customer/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Customer/Api.php index 44635ca020..d8bff99a25 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Customer/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Customer/Api.php @@ -236,4 +236,4 @@ protected function _prepareCustomerAddressData($data) } return $dataAddresses; } -} \ No newline at end of file +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php index 21050a521c..2a0236bd3d 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php @@ -1,172 +1,172 @@ - - */ - -class Mage_Checkout_Model_Cart_Payment_Api extends Mage_Checkout_Model_Api_Resource -{ - - protected function _preparePaymentData($data) - { - if (!(is_array($data) && is_null($data[0]))) { - return array(); - } - - return $data; - } - - /** - * @param $method - * @param $quote - * @return bool - */ - protected function _canUsePaymentMethod($method, $quote) - { - if ( !($method->isGateway() || $method->canUseInternal()) ) { - return false; - } - - if (!$method->canUseForCountry($quote->getBillingAddress()->getCountry())) { - return false; - } - - if (!$method->canUseForCurrency(Mage::app()->getStore($quote->getStoreId())->getBaseCurrencyCode())) { - return false; - } - - /** - * Checking for min/max order total for assigned payment method - */ - $total = $quote->getBaseGrandTotal(); - $minTotal = $method->getConfigData('min_order_total'); - $maxTotal = $method->getConfigData('max_order_total'); - - if ((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) { - return false; - } - - return true; - } - - protected function _getPaymentMethodAvailableCcTypes($method) - { - $ccTypes = Mage::getSingleton('payment/config')->getCcTypes(); - $methodCcTypes = explode(',',$method->getConfigData('cctypes')); - foreach ($ccTypes as $code=>$title) { - if (!in_array($code, $methodCcTypes)) { - unset($ccTypes[$code]); - } - } - if (empty($ccTypes)) { - return null; - } - - return $ccTypes; - } - - /** - * @param $quoteId - * @param $store - * @return array - */ - public function getPaymentMethodsList($quoteId, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - $store = $quote->getStoreId(); - - $total = $quote->getBaseSubtotal(); - - $methodsResult = array(); - $methods = Mage::helper('payment')->getStoreMethods($store, $quote); - foreach ($methods as $key=>$method) { - /** @var $method Mage_Payment_Model_Method_Abstract */ - if ($this->_canUsePaymentMethod($method, $quote) - && ($total != 0 - || $method->getCode() == 'free' - || ($quote->hasRecurringItems() && $method->canManageRecurringProfiles()))) { - $methodsResult[] = - array( - "code" => $method->getCode(), - "title" => $method->getTitle(), - "ccTypes" => $this->_getPaymentMethodAvailableCcTypes($method) - ); - } - } - - return $methodsResult; - } - - /** - * @param $quoteId - * @param $paymentData - * @param $store - * @return bool - */ - public function setPaymentMethod($quoteId, $paymentData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - - // check if billing or shipping addresses are set - if (is_null($quote->getBillingAddress()->getId()) ) { - $this->_fault('billing_address_is_not_set'); - } - if (is_null($quote->getShippingAddress()->getId()) ) { - $this->_fault('shipping_address_is_not_set'); - } - - $paymentData = $this->_preparePaymentData($paymentData); - - if ($quote->isVirtual()) { - $quote->getBillingAddress()->setPaymentMethod(isset($paymentData['method']) ? $paymentData['method'] : null); - } else { - $quote->getShippingAddress()->setPaymentMethod(isset($paymentData['method']) ? $paymentData['method'] : null); - } - - if (!$quote->isVirtual() && $quote->getShippingAddress()) { - $quote->getShippingAddress()->setCollectShippingRates(true); - } - - try { - $payment = $quote->getPayment(); - $payment->importData($paymentData); - - - $quote->setTotalsCollectedFlag(false) - ->collectTotals() - ->save(); - } catch (Mage_Core_Exception $e) { - $this->_fault('payment_method_is_not_set', $e->getMessage()); - } - return true; - } - -} + + */ + +class Mage_Checkout_Model_Cart_Payment_Api extends Mage_Checkout_Model_Api_Resource +{ + + protected function _preparePaymentData($data) + { + if (!(is_array($data) && is_null($data[0]))) { + return array(); + } + + return $data; + } + + /** + * @param $method + * @param $quote + * @return bool + */ + protected function _canUsePaymentMethod($method, $quote) + { + if ( !($method->isGateway() || $method->canUseInternal()) ) { + return false; + } + + if (!$method->canUseForCountry($quote->getBillingAddress()->getCountry())) { + return false; + } + + if (!$method->canUseForCurrency(Mage::app()->getStore($quote->getStoreId())->getBaseCurrencyCode())) { + return false; + } + + /** + * Checking for min/max order total for assigned payment method + */ + $total = $quote->getBaseGrandTotal(); + $minTotal = $method->getConfigData('min_order_total'); + $maxTotal = $method->getConfigData('max_order_total'); + + if ((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) { + return false; + } + + return true; + } + + protected function _getPaymentMethodAvailableCcTypes($method) + { + $ccTypes = Mage::getSingleton('payment/config')->getCcTypes(); + $methodCcTypes = explode(',',$method->getConfigData('cctypes')); + foreach ($ccTypes as $code=>$title) { + if (!in_array($code, $methodCcTypes)) { + unset($ccTypes[$code]); + } + } + if (empty($ccTypes)) { + return null; + } + + return $ccTypes; + } + + /** + * @param $quoteId + * @param $store + * @return array + */ + public function getPaymentMethodsList($quoteId, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + $store = $quote->getStoreId(); + + $total = $quote->getBaseSubtotal(); + + $methodsResult = array(); + $methods = Mage::helper('payment')->getStoreMethods($store, $quote); + foreach ($methods as $key=>$method) { + /** @var $method Mage_Payment_Model_Method_Abstract */ + if ($this->_canUsePaymentMethod($method, $quote) + && ($total != 0 + || $method->getCode() == 'free' + || ($quote->hasRecurringItems() && $method->canManageRecurringProfiles()))) { + $methodsResult[] = + array( + "code" => $method->getCode(), + "title" => $method->getTitle(), + "ccTypes" => $this->_getPaymentMethodAvailableCcTypes($method) + ); + } + } + + return $methodsResult; + } + + /** + * @param $quoteId + * @param $paymentData + * @param $store + * @return bool + */ + public function setPaymentMethod($quoteId, $paymentData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + + // check if billing or shipping addresses are set + if (is_null($quote->getBillingAddress()->getId()) ) { + $this->_fault('billing_address_is_not_set'); + } + if (is_null($quote->getShippingAddress()->getId()) ) { + $this->_fault('shipping_address_is_not_set'); + } + + $paymentData = $this->_preparePaymentData($paymentData); + + if ($quote->isVirtual()) { + $quote->getBillingAddress()->setPaymentMethod(isset($paymentData['method']) ? $paymentData['method'] : null); + } else { + $quote->getShippingAddress()->setPaymentMethod(isset($paymentData['method']) ? $paymentData['method'] : null); + } + + if (!$quote->isVirtual() && $quote->getShippingAddress()) { + $quote->getShippingAddress()->setCollectShippingRates(true); + } + + try { + $payment = $quote->getPayment(); + $payment->importData($paymentData); + + + $quote->setTotalsCollectedFlag(false) + ->collectTotals() + ->save(); + } catch (Mage_Core_Exception $e) { + $this->_fault('payment_method_is_not_set', $e->getMessage()); + } + return true; + } + +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php index e842d03725..1d0b311c6a 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php @@ -1,45 +1,45 @@ - - */ - - class Mage_Checkout_Model_Cart_Payment_Api_V2 extends Mage_Checkout_Model_Cart_Payment_Api -{ - protected function _preparePaymentData($data) - { - if (null !== ($_data = get_object_vars($data))) { - return parent::_preparePaymentData($_data); - } - - return array(); - } -} + + */ + + class Mage_Checkout_Model_Cart_Payment_Api_V2 extends Mage_Checkout_Model_Cart_Payment_Api +{ + protected function _preparePaymentData($data) + { + if (null !== ($_data = get_object_vars($data))) { + return parent::_preparePaymentData($_data); + } + + return array(); + } +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Product/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Product/Api.php index f6d3101ef5..99b2d28637 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Product/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Product/Api.php @@ -1,299 +1,299 @@ - - */ - -class Mage_Checkout_Model_Cart_Product_Api extends Mage_Checkout_Model_Api_Resource_Product -{ - protected function _prepareProductsData($data) - { - if (!is_array($data)) { - return null; - } - - $_data = array(); - if (is_array($data) && is_null($data[0])) { - $_data[] = $data; - } else { - $_data = $data; - } - - return $_data; - } - - /** - * @param $quoteId - * @param $productsData - * @param $store - * @return bool - */ - public function add($quoteId, $productsData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - if (empty($store)) { - $store = $quote->getStoreId(); - } - - $productsData = $this->_prepareProductsData($productsData); - if (empty($productsData)) { - $this->_fault('invalid_product_data'); - } - - $errors = array(); - foreach ($productsData as $productItem) { - if (isset($productItem['product_id'])) { - $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); - } else if (isset($productItem['sku'])) { - $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); - } else { - continue; - } - - $productRequest = $this->_getProductRequest($productItem); - try { - $result = $quote->addProduct($productByItem, $productRequest); - if (is_string($result)) { - Mage::throwException($result); - } - } catch( Exception $e) { - $errors[] = $e->getMessage(); - } - } - - if (!empty($errors)) { - $this->_fault("add_product_fault", implode(PHP_EOL, $errors)); - } - - try { - $quote->collectTotals()->save(); - } catch(Exception $e) { - $this->_fault("add_product_fault", $e->getMessage()); - } - - return true; - } - - /** - * @param $quoteId - * @param $productsData - * @param $store - * @return bool - */ - public function update($quoteId, $productsData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - if (empty($store)) { - $store = $quote->getStoreId(); - } - - $productsData = $this->_prepareProductsData($productsData); - if (empty($productsData)) { - $this->_fault('invalid_product_data'); - } - - foreach ($productsData as $productItem) { - if (isset($productItem['product_id'])) { - $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); - } else if (isset($productItem['sku'])) { - $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); - } else { - continue; - } - - /** @var $quoteItem Mage_Sales_Model_Quote_Item */ - $quoteItem = $quote->getItemByProduct($productByItem); - if ($quoteItem === false) { - continue; - } - - if ($productItem['qty'] > 0) { - $quoteItem->setQty($productItem['qty']); - } - } - - try { - $quote->save(); - } catch(Exception $e) { - $this->_fault("update_product_fault", $e->getMessage()); - } - - return true; - } - - /** - * @param $quoteId - * @param $productsData - * @param $store - * @return bool - */ - public function remove($quoteId, $productsData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - if (empty($store)) { - $store = $quote->getStoreId(); - } - - $productsData = $this->_prepareProductsData($productsData); - if (empty($productsData)) { - $this->_fault('invalid_product_data'); - } - - foreach ($productsData as $productItem) { - if (isset($productItem['product_id'])) { - $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); - } else if (isset($productItem['sku'])) { - $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); - } else { - continue; - } - - /** @var $quoteItem Mage_Sales_Model_Quote_Item */ - $quoteItem = $quote->getItemByProduct($productByItem); - if ($quoteItem === false) { - continue; - } - - $quote->removeItem($quoteItem->getId()); - } - - try { - $quote->save(); - } catch(Exception $e) { - $this->_fault("remove_product_fault", $e->getMessage()); - } - - return true; - } - - /** - * @param $quoteId - * @param $store - * @return array - */ - public function items($quoteId, $store = null) - { - $quote = $this->_getQuote($quoteId, $store); - if (empty($store)) { - $store = $quote->getStoreId(); - } - - if (!$quote->getItemsCount()) { - return array(); - } - - $productsResult = array(); - foreach ($quote->getAllItems() as $item) { - /** @var $item Mage_Sales_Model_Quote_Item */ - $product = $item->getProduct(); - $productsResult[] = array( // Basic product data - 'product_id' => $product->getId(), - 'sku' => $product->getSku(), - 'set' => $product->getAttributeSetId(), - 'type' => $product->getTypeId(), - 'categories' => $product->getCategoryIds(), - 'websites' => $product->getWebsiteIds() - ); - } - - return $productsResult; - } - - /** - * @param $quoteId - * @param $productsData - * @param $store - * @return bool - */ - public function moveToCustomerQuote($quoteId, $productsData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - - if (empty($store)) { - $store = $quote->getStoreId(); - } - - $customer = $quote->getCustomer(); - if (is_null($customer->getId())) { - $this->_fault('customer_not_set_for_quote'); - } - - /** @var $customerQuote Mage_Sales_Model_Quote */ - $customerQuote = Mage::getModel('sales/quote') - ->setStoreId($store) - ->loadByCustomer($customer); - - if (is_null($customerQuote->getId())) { - $this->_fault('customer_quote_not_exist'); - } - - if ($customerQuote->getId() == $quote->getId()) { - $this->_fault('quotes_are_similar'); - } - - $productsData = $this->_prepareProductsData($productsData); - - foreach($productsData as $key => $productItem){ - if (isset($productItem['product_id'])) { - $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); - } else if (isset($productItem['sku'])) { - $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); - } else { - continue; - } - - $quoteItem = $quote->getItemByProduct($productByItem); - if($quoteItem->getId()){ - $customerQuote->addItem($quoteItem); - $quote->removeItem($quoteItem->getId()); - unset($productsData[$key]); - } - } - - if (count($productsData)) { - $this->_fault('unable_to_move_all_products'); - } - - try { - $customerQuote - ->collectTotals() - ->save(); - - $quote - ->collectTotals() - ->save(); - } catch (Exception $e) { - $this->_fault($e->getMessage(), $e->getMessage()); - } - - return true; - } -} + + */ + +class Mage_Checkout_Model_Cart_Product_Api extends Mage_Checkout_Model_Api_Resource_Product +{ + protected function _prepareProductsData($data) + { + if (!is_array($data)) { + return null; + } + + $_data = array(); + if (is_array($data) && is_null($data[0])) { + $_data[] = $data; + } else { + $_data = $data; + } + + return $_data; + } + + /** + * @param $quoteId + * @param $productsData + * @param $store + * @return bool + */ + public function add($quoteId, $productsData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + if (empty($store)) { + $store = $quote->getStoreId(); + } + + $productsData = $this->_prepareProductsData($productsData); + if (empty($productsData)) { + $this->_fault('invalid_product_data'); + } + + $errors = array(); + foreach ($productsData as $productItem) { + if (isset($productItem['product_id'])) { + $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); + } else if (isset($productItem['sku'])) { + $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); + } else { + continue; + } + + $productRequest = $this->_getProductRequest($productItem); + try { + $result = $quote->addProduct($productByItem, $productRequest); + if (is_string($result)) { + Mage::throwException($result); + } + } catch( Exception $e) { + $errors[] = $e->getMessage(); + } + } + + if (!empty($errors)) { + $this->_fault("add_product_fault", implode(PHP_EOL, $errors)); + } + + try { + $quote->collectTotals()->save(); + } catch(Exception $e) { + $this->_fault("add_product_fault", $e->getMessage()); + } + + return true; + } + + /** + * @param $quoteId + * @param $productsData + * @param $store + * @return bool + */ + public function update($quoteId, $productsData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + if (empty($store)) { + $store = $quote->getStoreId(); + } + + $productsData = $this->_prepareProductsData($productsData); + if (empty($productsData)) { + $this->_fault('invalid_product_data'); + } + + foreach ($productsData as $productItem) { + if (isset($productItem['product_id'])) { + $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); + } else if (isset($productItem['sku'])) { + $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); + } else { + continue; + } + + /** @var $quoteItem Mage_Sales_Model_Quote_Item */ + $quoteItem = $quote->getItemByProduct($productByItem); + if ($quoteItem === false) { + continue; + } + + if ($productItem['qty'] > 0) { + $quoteItem->setQty($productItem['qty']); + } + } + + try { + $quote->save(); + } catch(Exception $e) { + $this->_fault("update_product_fault", $e->getMessage()); + } + + return true; + } + + /** + * @param $quoteId + * @param $productsData + * @param $store + * @return bool + */ + public function remove($quoteId, $productsData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + if (empty($store)) { + $store = $quote->getStoreId(); + } + + $productsData = $this->_prepareProductsData($productsData); + if (empty($productsData)) { + $this->_fault('invalid_product_data'); + } + + foreach ($productsData as $productItem) { + if (isset($productItem['product_id'])) { + $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); + } else if (isset($productItem['sku'])) { + $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); + } else { + continue; + } + + /** @var $quoteItem Mage_Sales_Model_Quote_Item */ + $quoteItem = $quote->getItemByProduct($productByItem); + if ($quoteItem === false) { + continue; + } + + $quote->removeItem($quoteItem->getId()); + } + + try { + $quote->save(); + } catch(Exception $e) { + $this->_fault("remove_product_fault", $e->getMessage()); + } + + return true; + } + + /** + * @param $quoteId + * @param $store + * @return array + */ + public function items($quoteId, $store = null) + { + $quote = $this->_getQuote($quoteId, $store); + if (empty($store)) { + $store = $quote->getStoreId(); + } + + if (!$quote->getItemsCount()) { + return array(); + } + + $productsResult = array(); + foreach ($quote->getAllItems() as $item) { + /** @var $item Mage_Sales_Model_Quote_Item */ + $product = $item->getProduct(); + $productsResult[] = array( // Basic product data + 'product_id' => $product->getId(), + 'sku' => $product->getSku(), + 'set' => $product->getAttributeSetId(), + 'type' => $product->getTypeId(), + 'categories' => $product->getCategoryIds(), + 'websites' => $product->getWebsiteIds() + ); + } + + return $productsResult; + } + + /** + * @param $quoteId + * @param $productsData + * @param $store + * @return bool + */ + public function moveToCustomerQuote($quoteId, $productsData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + + if (empty($store)) { + $store = $quote->getStoreId(); + } + + $customer = $quote->getCustomer(); + if (is_null($customer->getId())) { + $this->_fault('customer_not_set_for_quote'); + } + + /** @var $customerQuote Mage_Sales_Model_Quote */ + $customerQuote = Mage::getModel('sales/quote') + ->setStoreId($store) + ->loadByCustomer($customer); + + if (is_null($customerQuote->getId())) { + $this->_fault('customer_quote_not_exist'); + } + + if ($customerQuote->getId() == $quote->getId()) { + $this->_fault('quotes_are_similar'); + } + + $productsData = $this->_prepareProductsData($productsData); + + foreach($productsData as $key => $productItem){ + if (isset($productItem['product_id'])) { + $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); + } else if (isset($productItem['sku'])) { + $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); + } else { + continue; + } + + $quoteItem = $quote->getItemByProduct($productByItem); + if($quoteItem->getId()){ + $customerQuote->addItem($quoteItem); + $quote->removeItem($quoteItem->getId()); + unset($productsData[$key]); + } + } + + if (count($productsData)) { + $this->_fault('unable_to_move_all_products'); + } + + try { + $customerQuote + ->collectTotals() + ->save(); + + $quote + ->collectTotals() + ->save(); + } catch (Exception $e) { + $this->_fault($e->getMessage(), $e->getMessage()); + } + + return true; + } +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php index 25651fbbd4..e7a5fa0bf0 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php @@ -1,116 +1,116 @@ - - */ - -class Mage_Checkout_Model_Cart_Product_Api_V2 extends Mage_Checkout_Model_Cart_Product_Api -{ - - protected function _prepareProductsData($data) - { - if (!is_array($data) && !is_object($data)) { - return null; - } - - $_data = array(); - if (is_object($data)) { - $dataItem = $data; - $dataItem = $this->_checkBundleOptions($dataItem); - $dataItem = $this->_checkOptions($dataItem); - $_data[] = get_object_vars($data); - } else { - foreach ($data as $_dataItem) { - $dataItem = $_dataItem; - $dataItem = $this->_checkBundleOptions($dataItem); - $dataItem = $this->_checkOptions($dataItem); - $_data[] = get_object_vars($dataItem); - } - } - - return parent::_prepareProductsData($_data); - } - - protected function _checkBundleOptions($dataItem) - { - if (!isset($dataItem->bundle_options) || !isset($dataItem->bundle_options_qty)) { - return $dataItem; - } - - if (isset($dataItem->bundle_options)) { - $options = array(); - foreach($dataItem->bundle_options as $option) { - if (is_object($option)) { - $options[$option->key] = $option->value; - } else { - foreach($option as $key=>$value) { - $options[$key] = $value; - } - } - } - $dataItem->bundle_options = $options; - } - - if (isset($dataItem->bundle_options_qty)) { - $options_qty = array(); - foreach($dataItem->bundle_options_qty as $option) { - if (is_object($option)) { - $options[$option->key] = $option->value; - } else { - foreach($option as $key=>$value) { - $options[$key] = $value; - } - } - } - $dataItem->bundle_options_qty = $options_qty; - } - return $dataItem; - } - - protected function _checkOptions($dataItem) - { - if (isset($dataItem->options)) { - $options = array(); - foreach($dataItem->options as $option) { - if (is_object($option)) { - $options[$option->key] = $option->value; - } else { - foreach($option as $key=>$value) { - $options[$key] = $value; - } - } - - } - $dataItem->options = $options; - } - return $dataItem; - } -} + + */ + +class Mage_Checkout_Model_Cart_Product_Api_V2 extends Mage_Checkout_Model_Cart_Product_Api +{ + + protected function _prepareProductsData($data) + { + if (!is_array($data) && !is_object($data)) { + return null; + } + + $_data = array(); + if (is_object($data)) { + $dataItem = $data; + $dataItem = $this->_checkBundleOptions($dataItem); + $dataItem = $this->_checkOptions($dataItem); + $_data[] = get_object_vars($data); + } else { + foreach ($data as $_dataItem) { + $dataItem = $_dataItem; + $dataItem = $this->_checkBundleOptions($dataItem); + $dataItem = $this->_checkOptions($dataItem); + $_data[] = get_object_vars($dataItem); + } + } + + return parent::_prepareProductsData($_data); + } + + protected function _checkBundleOptions($dataItem) + { + if (!isset($dataItem->bundle_options) || !isset($dataItem->bundle_options_qty)) { + return $dataItem; + } + + if (isset($dataItem->bundle_options)) { + $options = array(); + foreach($dataItem->bundle_options as $option) { + if (is_object($option)) { + $options[$option->key] = $option->value; + } else { + foreach($option as $key=>$value) { + $options[$key] = $value; + } + } + } + $dataItem->bundle_options = $options; + } + + if (isset($dataItem->bundle_options_qty)) { + $options_qty = array(); + foreach($dataItem->bundle_options_qty as $option) { + if (is_object($option)) { + $options[$option->key] = $option->value; + } else { + foreach($option as $key=>$value) { + $options[$key] = $value; + } + } + } + $dataItem->bundle_options_qty = $options_qty; + } + return $dataItem; + } + + protected function _checkOptions($dataItem) + { + if (isset($dataItem->options)) { + $options = array(); + foreach($dataItem->options as $option) { + if (is_object($option)) { + $options[$option->key] = $option->value; + } else { + foreach($option as $key=>$value) { + $options[$key] = $value; + } + } + + } + $dataItem->options = $options; + } + return $dataItem; + } +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api.php index 2b839da921..cfb797cf5b 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api.php @@ -1,116 +1,116 @@ - - */ - -class Mage_Checkout_Model_Cart_Shipping_Api extends Mage_Checkout_Model_Api_Resource -{ - public function __construct() - { - $this->_ignoredAttributeCodes['quote_shipping_rate'] = array('address_id', 'created_at', 'updated_at', 'rate_id', 'carrier_sort_order'); - } - - /** - * Set an Shipping Method for Shopping Cart - * - * @param $quoteId - * @param $shippingMethod - * @param $store - * @return bool - */ - public function setShippingMethod($quoteId, $shippingMethod, $store = null) - { - $quote = $this->_getQuote($quoteId, $store); - - $quoteShippingAddress = $quote->getShippingAddress(); - if(is_null($quoteShippingAddress->getId()) ) { - $this->_fault("shipping_address_is_not_set"); - } - - $rate = $quote->getShippingAddress()->collectShippingRates()->getShippingRateByCode($shippingMethod); - if (!$rate) { - $this->_fault('shipping_method_is_not_available'); - } - - try { - $quote->getShippingAddress()->setShippingMethod($shippingMethod); - $quote->collectTotals()->save(); - } catch(Mage_Core_Exception $e) { - $this->_fault('shipping_method_is_not_set', $e->getMessage()); - } - - return true; - } - - /** - * Get list of available shipping methods - * - * @param $quoteId - * @param $store - * @return array - */ - public function getShippingMethodsList($quoteId, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - - $quoteShippingAddress = $quote->getShippingAddress(); - if (is_null($quoteShippingAddress->getId())) { - $this->_fault("shipping_address_is_not_set"); - } - - try { - $quoteShippingAddress->collectShippingRates()->save(); - $groupedRates = $quoteShippingAddress->getGroupedAllShippingRates(); - - $ratesResult = array(); - foreach ($groupedRates as $carrierCode => $rates ) { - $carrierName = $carrierCode; - if (!is_null(Mage::getStoreConfig('carriers/'.$carrierCode.'/title'))) { - $carrierName = Mage::getStoreConfig('carriers/'.$carrierCode.'/title'); - } - - foreach ($rates as $rate) { - $rateItem = $this->_getAttributes($rate, "quote_shipping_rate"); - $rateItem['carrierName'] = $carrierName; - $ratesResult[] = $rateItem; - unset($rateItem); - } - } - } catch (Mage_Core_Exception $e) { - $this->_fault('shipping_methods_list_could_not_be_retrived', $e->getMessage()); - } - - return $ratesResult; - } - - -} + + */ + +class Mage_Checkout_Model_Cart_Shipping_Api extends Mage_Checkout_Model_Api_Resource +{ + public function __construct() + { + $this->_ignoredAttributeCodes['quote_shipping_rate'] = array('address_id', 'created_at', 'updated_at', 'rate_id', 'carrier_sort_order'); + } + + /** + * Set an Shipping Method for Shopping Cart + * + * @param $quoteId + * @param $shippingMethod + * @param $store + * @return bool + */ + public function setShippingMethod($quoteId, $shippingMethod, $store = null) + { + $quote = $this->_getQuote($quoteId, $store); + + $quoteShippingAddress = $quote->getShippingAddress(); + if(is_null($quoteShippingAddress->getId()) ) { + $this->_fault("shipping_address_is_not_set"); + } + + $rate = $quote->getShippingAddress()->collectShippingRates()->getShippingRateByCode($shippingMethod); + if (!$rate) { + $this->_fault('shipping_method_is_not_available'); + } + + try { + $quote->getShippingAddress()->setShippingMethod($shippingMethod); + $quote->collectTotals()->save(); + } catch(Mage_Core_Exception $e) { + $this->_fault('shipping_method_is_not_set', $e->getMessage()); + } + + return true; + } + + /** + * Get list of available shipping methods + * + * @param $quoteId + * @param $store + * @return array + */ + public function getShippingMethodsList($quoteId, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + + $quoteShippingAddress = $quote->getShippingAddress(); + if (is_null($quoteShippingAddress->getId())) { + $this->_fault("shipping_address_is_not_set"); + } + + try { + $quoteShippingAddress->collectShippingRates()->save(); + $groupedRates = $quoteShippingAddress->getGroupedAllShippingRates(); + + $ratesResult = array(); + foreach ($groupedRates as $carrierCode => $rates ) { + $carrierName = $carrierCode; + if (!is_null(Mage::getStoreConfig('carriers/'.$carrierCode.'/title'))) { + $carrierName = Mage::getStoreConfig('carriers/'.$carrierCode.'/title'); + } + + foreach ($rates as $rate) { + $rateItem = $this->_getAttributes($rate, "quote_shipping_rate"); + $rateItem['carrierName'] = $carrierName; + $ratesResult[] = $rateItem; + unset($rateItem); + } + } + } catch (Mage_Core_Exception $e) { + $this->_fault('shipping_methods_list_could_not_be_retrived', $e->getMessage()); + } + + return $ratesResult; + } + + +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api/V2.php index 79322da107..3b9106c558 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api/V2.php @@ -1,38 +1,38 @@ - - */ - -class Mage_Checkout_Model_Cart_Shipping_Api_V2 extends Mage_Checkout_Model_Cart_Shipping_Api -{ - -} + + */ + +class Mage_Checkout_Model_Cart_Shipping_Api_V2 extends Mage_Checkout_Model_Cart_Shipping_Api +{ + +} diff --git a/app/code/core/Mage/Checkout/Model/Type/Multishipping.php b/app/code/core/Mage/Checkout/Model/Type/Multishipping.php index 8a37db4442..a617749aca 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Multishipping.php +++ b/app/code/core/Mage/Checkout/Model/Type/Multishipping.php @@ -496,35 +496,40 @@ public function createOrders() $shippingAddresses[] = $this->getQuote()->getBillingAddress(); } - foreach ($shippingAddresses as $address) { - $order = $this->_prepareOrder($address); - - $orders[] = $order; - Mage::dispatchEvent( - 'checkout_type_multishipping_create_orders_single', - array('order'=>$order, 'address'=>$address) - ); - } + try { + foreach ($shippingAddresses as $address) { + $order = $this->_prepareOrder($address); + + $orders[] = $order; + Mage::dispatchEvent( + 'checkout_type_multishipping_create_orders_single', + array('order'=>$order, 'address'=>$address) + ); + } - foreach ($orders as $order) { - $order->place(); - $order->save(); - if ($order->getCanSendNewEmailFlag()){ - $order->sendNewOrderEmail(); + foreach ($orders as $order) { + $order->place(); + $order->save(); + if ($order->getCanSendNewEmailFlag()){ + $order->sendNewOrderEmail(); + } + $orderIds[$order->getId()] = $order->getIncrementId(); } - $orderIds[$order->getId()] = $order->getIncrementId(); - } - Mage::getSingleton('core/session')->setOrderIds($orderIds); - Mage::getSingleton('checkout/session')->setLastQuoteId($this->getQuote()->getId()); + Mage::getSingleton('core/session')->setOrderIds($orderIds); + Mage::getSingleton('checkout/session')->setLastQuoteId($this->getQuote()->getId()); - $this->getQuote() - ->setIsActive(false) - ->save(); + $this->getQuote() + ->setIsActive(false) + ->save(); - Mage::dispatchEvent('checkout_submit_all_after', array('orders' => $orders, 'quote' => $this->getQuote())); + Mage::dispatchEvent('checkout_submit_all_after', array('orders' => $orders, 'quote' => $this->getQuote())); - return $this; + return $this; + } catch (Exception $e) { + Mage::dispatchEvent('checkout_multishipping_refund_all', array('orders' => $orders)); + throw $e; + } } /** diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 9bd32a08ce..f9d145505c 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -250,7 +250,7 @@ public function saveBilling($data, $customerAddressId) ); } - $address->importCustomerAddress($customerAddress); + $address->importCustomerAddress($customerAddress)->setSaveInAddressBook(0); $addressForm->setEntity($address); $addressErrors = $addressForm->validateData($address->getData()); if ($addressErrors !== true) { @@ -496,7 +496,7 @@ public function saveShipping($data, $customerAddressId) ); } - $address->importCustomerAddress($customerAddress); + $address->importCustomerAddress($customerAddress)->setSaveInAddressBook(0); $addressForm->setEntity($address); $addressErrors = $addressForm->validateData($address->getData()); if ($addressErrors !== true) { diff --git a/app/code/core/Mage/Checkout/etc/wsdl.xml b/app/code/core/Mage/Checkout/etc/wsdl.xml index a86f100d98..4aab422f5f 100644 --- a/app/code/core/Mage/Checkout/etc/wsdl.xml +++ b/app/code/core/Mage/Checkout/etc/wsdl.xml @@ -1,12 +1,11 @@ - + - + + + - - + + - + - - - - - + Create shopping cart - - - - - Retrieve information about shopping cart - - - - - Create an order from shopping cart - - - - - Get total prices for shopping cart - - - - - Get terms and conditions - - - - - Add product(s) to shopping cart - - - - - Update product(s) quantities in shopping cart - - - - - Remove product(s) from shopping cart - - - - - Get list of products in shopping cart - - - - - Move product(s) to customer quote - - - - - Set customer for shopping cart - - - - - Set customer's addresses in shopping cart - - - - - Set shipping method - - - - - Get list of available shipping methods - - - - - Set payment method - - - - - Get list of available payment methods - - - - - Add coupon code for shopping cart - - - - - Remove coupon code from shopping cart - - - + + + + - + - - - - - - - - - - + - + - + - - + diff --git a/app/code/core/Mage/Compiler/etc/compilation.xml b/app/code/core/Mage/Compiler/etc/compilation.xml index 4d300081bb..d11906a9ba 100644 --- a/app/code/core/Mage/Compiler/etc/compilation.xml +++ b/app/code/core/Mage/Compiler/etc/compilation.xml @@ -218,6 +218,11 @@ + + + + + @@ -319,17 +324,12 @@ - - - - - diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Package.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Package.php index 7de33567ce..0e103ba81b 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Package.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Package.php @@ -77,18 +77,18 @@ protected function _prepareForm() $versionsInfo = array( array( - 'label' => Mage::helper('connect')->__('Version 2.x'), + 'label' => Mage::helper('connect')->__('1.5.0.0 & later'), 'value' => Mage_Connect_Package::PACKAGE_VERSION_2X ), array( - 'label' => Mage::helper('connect')->__('Version 1.x'), + 'label' => Mage::helper('connect')->__('Pre-1.5.0.0'), 'value' => Mage_Connect_Package::PACKAGE_VERSION_1X ) ); $fieldset->addField('version_ids','multiselect',array( 'name' => 'version_ids', 'required' => true, - 'label' => Mage::helper('connect')->__('Package Format'), + 'label' => Mage::helper('connect')->__('Supported releases'), 'style' => 'height: 45px;', 'values' => $versionsInfo )); diff --git a/app/code/core/Mage/Core/Model/App/Area.php b/app/code/core/Mage/Core/Model/App/Area.php index 98748de802..2148bb7f9a 100644 --- a/app/code/core/Mage/Core/Model/App/Area.php +++ b/app/code/core/Mage/Core/Model/App/Area.php @@ -34,10 +34,11 @@ class Mage_Core_Model_App_Area const AREA_GLOBAL = 'global'; const AREA_FRONTEND = 'frontend'; const AREA_ADMIN = 'admin'; + const AREA_ADMINHTML = 'adminhtml'; const PART_CONFIG = 'config'; const PART_EVENTS = 'events'; - const PART_TRANSLATE= 'translate'; + const PART_TRANSLATE = 'translate'; const PART_DESIGN = 'design'; /** diff --git a/app/code/core/Mage/Core/Model/App/Emulation.php b/app/code/core/Mage/Core/Model/App/Emulation.php new file mode 100644 index 0000000000..70ba30f20a --- /dev/null +++ b/app/code/core/Mage/Core/Model/App/Emulation.php @@ -0,0 +1,197 @@ + + */ +class Mage_Core_Model_App_Emulation extends Varien_Object +{ + /** + * Start enviromment emulation of the specified store + * + * Function returns information about initial store environment and emulates environment of another store + * + * @param integer $storeId + * @param string $area + * @param boolean $emulateSroreInlineTranslation emulate inline translation of the specified store or just disable it + * + * @return Varien_Object information about environment of the initial store + */ + public function startEnvironmentEmulation($storeId, $area = Mage_Core_Model_App_Area::AREA_FRONTEND, $emulateSroreInlineTranslation = false) + { + if (is_null($area)) { + $area = Mage_Core_Model_App_Area::AREA_FRONTEND; + } + if ($emulateSroreInlineTranslation) { + $initialTranslateInline = $this->_emulateInlineTranslation($storeId, $area); + } else { + $initialTranslateInline = $this->_emulateInlineTranslation(); + } + $initialDesign = $this->_emulateDesign($storeId, $area); + // Current store needs to be changed right before locale change and after design change + Mage::app()->setCurrentStore($storeId); + $initialLocaleCode = $this->_emulateLocale($storeId, $area); + + $initialEnvironmentInfo = new Varien_Object(); + $initialEnvironmentInfo->setInitialTranslateInline($initialTranslateInline) + ->setInitialDesign($initialDesign) + ->setInitialLocaleCode($initialLocaleCode); + + return $initialEnvironmentInfo; + } + + /** + * Stop enviromment emulation + * + * Function restores initial store environment + * + * @param Varien_Object $initialEnvironmentInfo information about environment of the initial store + * + * @return Mage_Core_Model_App_Emulation + */ + public function stopEnvironmentEmulation(Varien_Object $initialEnvironmentInfo) + { + $this->_restoreInitialInlineTranslation($initialEnvironmentInfo->getInitialTranslateInline()); + $initialDesign = $initialEnvironmentInfo->getInitialDesign(); + $this->_restoreInitialDesign($initialDesign); + // Current store needs to be changed right before locale change and after design change + Mage::app()->setCurrentStore($initialDesign['store']); + $this->_restoreInitialLocale($initialEnvironmentInfo->getInitialLocaleCode(), $initialDesign['area']); + return $this; + } + + /** + * Emulate inline translation of the specified store + * + * Function disables inline translation if $storeId is null + * + * @param integer|null $storeId + * @param string $area + * + * @return boolean initial inline translation state + */ + protected function _emulateInlineTranslation($storeId = null, $area = Mage_Core_Model_App_Area::AREA_FRONTEND) + { + if (is_null($storeId)) { + $newTranslateInline = false; + } else { + if ($area == Mage_Core_Model_App_Area::AREA_ADMINHTML) { + $newTranslateInline = Mage::getStoreConfigFlag('dev/translate_inline/active_admin', $storeId); + } else { + $newTranslateInline = Mage::getStoreConfigFlag('dev/translate_inline/active', $storeId); + } + } + $translateModel = Mage::getSingleton('core/translate'); + $initialTranslateInline = $translateModel->getTranslateInline(); + $translateModel->setTranslateInline($newTranslateInline); + return $initialTranslateInline; + } + + /** + * Apply design of the specified store + * + * @param integer $storeId + * @param string $area + * + * @return array initial design parameters(package, store, area) + */ + protected function _emulateDesign($storeId, $area = Mage_Core_Model_App_Area::AREA_FRONTEND) + { + $initialDesign = Mage::getDesign()->setAllGetOld(array( + 'package' => Mage::getStoreConfig('design/package/name', $storeId), + 'store' => $storeId, + 'area' => $area + )); + Mage::getDesign()->setTheme(''); + Mage::getDesign()->setPackageName(''); + return $initialDesign; + } + + /** + * Apply locale of the specified store + * + * @param integer $storeId + * @param string $area + * + * @return string initial locale code + */ + protected function _emulateLocale($storeId, $area = Mage_Core_Model_App_Area::AREA_FRONTEND) + { + $initialLocaleCode = Mage::app()->getLocale()->getLocaleCode(); + $newLocaleCode = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeId); + Mage::app()->getLocale()->setLocaleCode($newLocaleCode); + Mage::getSingleton('core/translate')->setLocale($newLocaleCode)->init($area, true); + return $initialLocaleCode; + } + + /** + * Restore initial inline translation state + * + * @param boolean $initialTranslateInline + * + * @return Mage_Core_Model_App_Emulation + */ + protected function _restoreInitialInlineTranslation($initialTranslateInline) + { + $translateModel = Mage::getSingleton('core/translate'); + $translateModel->setTranslateInline($initialTranslateInline); + return $this; + } + + /** + * Restore design of the initial store + * + * @param array $initialDesign + * + * @return Mage_Core_Model_App_Emulation + */ + protected function _restoreInitialDesign(array $initialDesign) + { + Mage::getDesign()->setAllGetOld($initialDesign); + Mage::getDesign()->setTheme(''); + Mage::getDesign()->setPackageName(''); + return $this; + } + + /** + * Restore locale of the initial store + * + * @param string $initialLocaleCode + * @param string $initialArea + * + * @return Mage_Core_Model_App_Emulation + */ + protected function _restoreInitialLocale($initialLocaleCode, $initialArea = Mage_Core_Model_App_Area::AREA_ADMINHTML) + { + Mage::app()->getLocale()->setLocaleCode($initialLocaleCode); + Mage::getSingleton('core/translate')->setLocale($initialLocaleCode)->init($initialArea, true); + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Cache.php b/app/code/core/Mage/Core/Model/Cache.php index f581ae7ddf..56775e36d4 100644 --- a/app/code/core/Mage/Core/Model/Cache.php +++ b/app/code/core/Mage/Core/Model/Cache.php @@ -236,6 +236,11 @@ protected function _getTwoLevelsBackendOptions($fastOptions, $cacheOptions) $options['slow_backend_custom_naming'] = true; $options['slow_backend_autoload'] = true; + if (isset($cacheOptions['auto_refresh_fast_cache'])) { + $options['auto_refresh_fast_cache'] = (bool)$cacheOptions['auto_refresh_fast_cache']; + } else { + $options['auto_refresh_fast_cache'] = false; + } if (isset($cacheOptions['slow_backend'])) { $options['slow_backend'] = $cacheOptions['slow_backend']; } else { @@ -249,6 +254,11 @@ protected function _getTwoLevelsBackendOptions($fastOptions, $cacheOptions) if ($options['slow_backend'] == 'database') { $options['slow_backend'] = 'Varien_Cache_Backend_Database'; $options['slow_backend_options'] = $this->getDbAdapterOptions(); + if (isset($cacheOptions['slow_backend_store_data'])) { + $options['slow_backend_options']['store_data'] = (bool)$cacheOptions['slow_backend_store_data']; + } else { + $options['slow_backend_options']['store_data'] = false; + } } $backend = array( diff --git a/app/code/core/Mage/Core/Model/Design/Package.php b/app/code/core/Mage/Core/Model/Design/Package.php index 44dcfaad5e..34476259f0 100644 --- a/app/code/core/Mage/Core/Model/Design/Package.php +++ b/app/code/core/Mage/Core/Model/Design/Package.php @@ -186,14 +186,14 @@ public function setAllGetOld($storePackageArea) $oldValues['store'] = $this->getStore(); $this->setStore($storePackageArea['store']); } - if (array_key_exists('package', $storePackageArea)) { - $oldValues['package'] = $this->getPackageName(); - $this->setPackageName($storePackageArea['package']); - } if (array_key_exists('area', $storePackageArea)) { $oldValues['area'] = $this->getArea(); $this->setArea($storePackageArea['area']); } + if (array_key_exists('package', $storePackageArea)) { + $oldValues['package'] = $this->getPackageName(); + $this->setPackageName($storePackageArea['package']); + } return $oldValues; } diff --git a/app/code/core/Mage/Core/Model/Email/Info.php b/app/code/core/Mage/Core/Model/Email/Info.php new file mode 100644 index 0000000000..28cb25472e --- /dev/null +++ b/app/code/core/Mage/Core/Model/Email/Info.php @@ -0,0 +1,137 @@ + + */ +class Mage_Core_Model_Email_Info extends Varien_Object +{ + /** + * Name list of "Bcc" recipients + * + * @var array + */ + protected $_bccNames = array(); + + /** + * Email list of "Bcc" recipients + * + * @var array + */ + protected $_bccEmails = array(); + + /** + * Name list of "To" recipients + * + * @var array + */ + protected $_toNames = array(); + + /** + * Email list of "To" recipients + * + * @var array + */ + protected $_toEmails = array(); + + + /** + * Add new "Bcc" recipient to current email + * + * @param string $email + * @param string|null $name + * @return Mage_Core_Model_Email_Info + */ + public function addBcc($email, $name = null) + { + array_push($this->_bccNames, $name); + array_push($this->_bccEmails, $email); + return $this; + } + + /** + * Add new "To" recipient to current email + * + * @param string $email + * @param string|null $name + * @return Mage_Core_Model_Email_Info + */ + public function addTo($email, $name = null) + { + array_push($this->_toNames, $name); + array_push($this->_toEmails, $email); + return $this; + } + + /** + * Get the name list of "Bcc" recipients + * + * @return array + */ + public function getBccNames() + { + return $this->_bccNames; + } + + /** + * Get the email list of "Bcc" recipients + * + * @return array + */ + public function getBccEmails() + { + return $this->_bccEmails; + } + + /** + * Get the name list of "To" recipients + * + * @return array + */ + public function getToNames() + { + return $this->_toNames; + } + + /** + * Get the email list of "To" recipients + * + * @return array + */ + public function getToEmails() + { + return $this->_toEmails; + } +} diff --git a/app/code/core/Mage/Core/Model/Email/Template/Mailer.php b/app/code/core/Mage/Core/Model/Email/Template/Mailer.php new file mode 100644 index 0000000000..d68b518222 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Email/Template/Mailer.php @@ -0,0 +1,167 @@ + + */ +class Mage_Core_Model_Email_Template_Mailer extends Varien_Object +{ + /** + * List of email infos + * @see Mage_Core_Model_Email_Info + * + * @var array + */ + protected $_emailInfos = array(); + + /** + * Add new email info to corresponding list + * + * @param Mage_Core_Model_Email_Info $emailInfo + * @return Mage_Core_Model_Email_Template_Mailer + */ + public function addEmailInfo(Mage_Core_Model_Email_Info $emailInfo) + { + array_push($this->_emailInfos, $emailInfo); + return $this; + } + + /** + * Send all emails from email list + * @see self::$_emailInfos + * + * @return Mage_Core_Model_Email_Template_Mailer + */ + public function send() + { + $emailTemplate = Mage::getModel('core/email_template'); + // Send all emails from corresponding list + while (!empty($this->_emailInfos)) { + $emailInfo = array_pop($this->_emailInfos); + // Handle "Bcc" recepients of the current email + $emailTemplate->addBcc($emailInfo->getBccEmails()); + // Set required design parameters and delegate email sending to Mage_Core_Model_Email_Template + $emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $this->getStoreId())) + ->sendTransactional( + $this->getTemplateId(), + $this->getSender(), + $emailInfo->getToEmails(), + $emailInfo->getToNames(), + $this->getTemplateParams(), + $this->getStoreId() + ); + } + return $this; + } + + /** + * Set email sender + * + * @param string|array $sender + * @return Mage_Core_Model_Email_Template_Mailer + */ + public function setSender($sender) + { + return $this->setData('sender', $sender); + } + + /** + * Get email sender + * + * @return string|array|null + */ + public function getSender() + { + return $this->_getData('sender'); + } + + /** + * Set store id + * + * @param int $storeId + * @return Mage_Core_Model_Email_Template_Mailer + */ + public function setStoreId($storeId) + { + return $this->setData('store_id', $storeId); + } + + /** + * Get store id + * + * @return int|null + */ + public function getStoreId() + { + return $this->_getData('store_id'); + } + + /** + * Set template id + * + * @param int $templateId + * @return Mage_Core_Model_Email_Template_Mailer + */ + public function setTemplateId($templateId) + { + return $this->setData('template_id', $templateId); + } + + /** + * Get template id + * + * @return int|null + */ + public function getTemplateId() + { + return $this->_getData('template_id'); + } + + /** + * Set tempate parameters + * + * @param array $templateParams + * @return Mage_Core_Model_Email_Template_Mailer + */ + public function setTemplateParams(array $templateParams) + { + return $this->setData('template_params', $templateParams); + } + + /** + * Get template parameters + * + * @return array|null + */ + public function getTemplateParams() + { + return $this->_getData('template_params'); + } +} diff --git a/app/code/core/Mage/Core/Model/File/Storage/Flag.php b/app/code/core/Mage/Core/Model/File/Storage/Flag.php index 7eba205fd6..e19373d517 100644 --- a/app/code/core/Mage/Core/Model/File/Storage/Flag.php +++ b/app/code/core/Mage/Core/Model/File/Storage/Flag.php @@ -62,4 +62,21 @@ class Mage_Core_Model_File_Storage_Flag extends Mage_Core_Model_Flag * @var string */ protected $_flagCode = 'synchronize'; + + /** + * Pass error to flag + * + * @param Exception $e + * @return Mage_Core_Model_File_Storage_Flag + */ + public function passError(Exception $e) + { + $data = $this->getFlagData(); + if (!is_array($data)) { + $data = array(); + } + $data['has_errors'] = true; + $this->setFlagData($data); + return $this; + } } diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php index 4f3e02d132..b303b1516a 100644 --- a/app/code/core/Mage/Core/Model/Locale.php +++ b/app/code/core/Mage/Core/Model/Locale.php @@ -199,6 +199,7 @@ public function getLocaleCode() public function setLocaleCode($code) { $this->_localeCode = $code; + $this->_locale = null; return $this; } diff --git a/app/code/core/Mage/Core/Model/Observer.php b/app/code/core/Mage/Core/Model/Observer.php index 5d332d2597..a35deb5bcc 100644 --- a/app/code/core/Mage/Core/Model/Observer.php +++ b/app/code/core/Mage/Core/Model/Observer.php @@ -70,7 +70,7 @@ public function addSynchronizeNotification(Varien_Event_Observer $observer) $description = Mage::helper('adminhtml')->__('One or more media files failed to be synchronized during the media storages syncronization process. Refer to the log file for details.'); } else { $severity = Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE; - $title = Mage::helper('adminhtml')->__('Media storage synchronization has completed!'); + $title = Mage::helper('adminhtml')->__('Media storages synchronization has completed!'); $description = Mage::helper('adminhtml')->__('Synchronization of media storages has been successfully completed.'); } diff --git a/app/code/core/Mage/Core/Model/Template.php b/app/code/core/Mage/Core/Model/Template.php index 2ac49f8dcd..a4db50448c 100644 --- a/app/code/core/Mage/Core/Model/Template.php +++ b/app/code/core/Mage/Core/Model/Template.php @@ -52,7 +52,7 @@ abstract class Mage_Core_Model_Template extends Mage_Core_Model_Abstract */ protected $_designConfig; - + /** * Configuration of emulated desing package. * @@ -60,6 +60,14 @@ abstract class Mage_Core_Model_Template extends Mage_Core_Model_Abstract */ protected $_emulatedDesignConfig = false; + /** + * Initial environment information + * @see self::_applyDesignConfig() + * + * @var Varien_Object|null + */ + protected $_initialEnvironmentInfo = null; + /** * Applying of design config * @@ -67,28 +75,14 @@ abstract class Mage_Core_Model_Template extends Mage_Core_Model_Abstract */ protected function _applyDesignConfig() { - $design = Mage::getDesign(); - $designConfig = $this->getDesignConfig() - ->setOldArea($design->getArea()) - ->setOldStore(is_object($design->getStore()) ? $design->getStore()->getId() : $design->getStore()); - - if ($designConfig->hasArea()) { - $design->setArea($designConfig->getArea()); - } - - if ($designConfig->hasStore()) { - $store = $designConfig->getStore(); - Mage::app()->setCurrentStore($store); - $locale = new Zend_Locale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store)); - Mage::app()->getLocale()->setLocale($locale)->setLocaleCode($locale->toString()); - if ($designConfig->hasArea()) { - Mage::getSingleton('core/translate')->setLocale($locale)->init($designConfig->getArea(), true); - } - $design->setStore($store); - $design->setTheme(''); - $design->setPackageName(''); + $designConfig = $this->getDesignConfig(); + $store = $designConfig->getStore(); + $storeId = is_object($store) ? $store->getId() : $store; + $area = $designConfig->getArea(); + if (!is_null($storeId)) { + $appEmulation = Mage::getSingleton('core/app_emulation'); + $this->_initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId, $area); } - return $this; } @@ -99,20 +93,11 @@ protected function _applyDesignConfig() */ protected function _cancelDesignConfig() { - if ($this->getDesignConfig()) { - if ($this->getDesignConfig()->getOldArea()) { - Mage::getDesign()->setArea($this->getDesignConfig()->getOldArea()); - } - - if ($this->getDesignConfig()->hasOldStore()) { - $oldStore = $this->getDesignConfig()->getOldStore(); - Mage::getDesign()->setStore($oldStore); - Mage::app()->setCurrentStore($oldStore); - Mage::getDesign()->setTheme(''); - Mage::getDesign()->setPackageName(''); - } + if (!empty($this->_initialEnvironmentInfo)) { + $appEmulation = Mage::getSingleton('core/app_emulation'); + $appEmulation->stopEnvironmentEmulation($this->_initialEnvironmentInfo); + $this->_initialEnvironmentInfo = null; } - Mage::app()->getLocale()->revert(); return $this; } @@ -172,10 +157,10 @@ public function emulateDesign($storeId, $area=self::DEFAULT_DESIGN_AREA) */ public function revertDesign() { - if ($this->_emulatedDesignConfig) - { + if ($this->_emulatedDesignConfig) { $this->setDesignConfig($this->_emulatedDesignConfig->getData()); - $this->_applyDesignConfig(); + $this->_cancelDesignConfig(); + $this->_emulatedDesignConfig = false; } } diff --git a/app/code/core/Mage/Core/etc/config.xml b/app/code/core/Mage/Core/etc/config.xml index 872f30ad7b..479cd7be47 100644 --- a/app/code/core/Mage/Core/etc/config.xml +++ b/app/code/core/Mage/Core/etc/config.xml @@ -28,7 +28,7 @@ - 0.8.27 + 0.8.28 diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.27-0.8.28.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.27-0.8.28.php new file mode 100644 index 0000000000..e1b2a67c34 --- /dev/null +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.27-0.8.28.php @@ -0,0 +1,35 @@ +getTable('core/cache_tag'); +$installer->getConnection()->truncate($tagsTableName); +$installer->getConnection()->modifyColumn($tagsTableName, 'tag', 'VARCHAR(100)'); +$installer->getConnection()->modifyColumn($tagsTableName, 'cache_id', 'VARCHAR(200)'); +$installer->getConnection()->addKey($tagsTableName, '', array('tag', 'cache_id'), 'PRIMARY'); +$installer->getConnection()->dropKey($tagsTableName, 'IDX_TAG'); diff --git a/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php b/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php index 0d5698a4e9..a60494fecc 100644 --- a/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php +++ b/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php @@ -270,7 +270,7 @@ public function __construct() public function load() { - $addressType = $this->getVar('filter/addressType'); + $addressType = $this->getVar('filter/adressType'); //error in key filter addressType if ($addressType=='both') { $addressType = array('default_billing','default_shipping'); } diff --git a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Downloadable.php b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Downloadable.php index 813e121480..cca3268e7b 100644 --- a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Downloadable.php +++ b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Downloadable.php @@ -19,7 +19,7 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Adminhtml + * @package Mage_Downloadable * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Convert/Adapter/Entity.php b/app/code/core/Mage/Eav/Model/Convert/Adapter/Entity.php index 938cc5de13..0a37f4588d 100644 --- a/app/code/core/Mage/Eav/Model/Convert/Adapter/Entity.php +++ b/app/code/core/Mage/Eav/Model/Convert/Adapter/Entity.php @@ -218,12 +218,33 @@ public function setJoinAttr($joinAttr) } + /** + * Add join field + * + * @param array $joinField Variable should be have view: + * Example: + * array( + * 'alias' => 'alias_table', + * 'attribute' => 'table_name', //table name, must be used path of table like 'module/table_name' + * 'field' => 'field_name', //selected field name (optional) + * //bind main condition + * //left field use for joined table + * //and right field use for main table of collection + * //NOTE: around '=' cannot be used ' ' (space) because on the exploding not use space trimming + * 'bind' => 'self_item_id=other_id', + * 'cond' => 'alias_table.entity_id = e.entity_id', //additional condition (optional) + * 'joinType' => 'LEFT' + * ) + * NOTE: Optional key must be have NULL at least + * @return void + */ public function setJoinField($joinField) { if (is_array($joinField)) { $this->_joinField[] = $joinField; } } + public function load() { if (!($entityType = $this->getVar('entity_type')) diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Product/Helper/Form/Config.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Product/Helper/Form/Config.php new file mode 100644 index 0000000000..4551f1d8fb --- /dev/null +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Product/Helper/Form/Config.php @@ -0,0 +1,46 @@ + + */ +class Mage_GiftMessage_Block_Adminhtml_Product_Helper_Form_Config + extends Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Config +{ + /** + * Get config value data + * + * @return mixed + */ + protected function _getValueFromConfig() + { + return Mage::getStoreConfig(Mage_GiftMessage_Helper_Message::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS); + } +} diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php index 8d8b2dd587..8cfd281b6e 100644 --- a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php @@ -50,8 +50,12 @@ public function getItem() */ public function canDisplayGiftMessage() { + $item = $this->getItem(); + if (!$item) { + return false; + } return $this->helper('giftmessage/message')->getIsMessagesAvailable( - 'item', $this->getItem(), $this->getItem()->getStoreId() + 'item', $item, $item->getStoreId() ); } diff --git a/app/code/core/Mage/GiftMessage/Helper/Message.php b/app/code/core/Mage/GiftMessage/Helper/Message.php index a072cf9ed2..660a2a03a5 100644 --- a/app/code/core/Mage/GiftMessage/Helper/Message.php +++ b/app/code/core/Mage/GiftMessage/Helper/Message.php @@ -127,15 +127,15 @@ public function isMessagesAvailable($type, Varien_Object $entity, $store = null) } } } elseif ($type == 'item') { - return !$entity->getProduct()->isVirtual() && $this->_getDependenceFromStoreConfig( - $entity->getProduct()->getGiftMessageAvailable(), - $store - ); + return $this->_getDependenceFromStoreConfig( + $entity->getProduct()->getGiftMessageAvailable(), + $store + ); } elseif ($type == 'order_item') { - return !$entity->getIsVirtual() && $this->_getDependenceFromStoreConfig( - $entity->getGiftMessageAvailable(), - $store - ); + return $this->_getDependenceFromStoreConfig( + $entity->getGiftMessageAvailable(), + $store + ); } elseif ($type == 'address_item') { $storeId = is_numeric($store) ? $store : Mage::app()->getStore($store)->getId(); @@ -148,10 +148,10 @@ public function isMessagesAvailable($type, Varien_Object $entity, $store = null) ->getGiftMessageAvailable() ); } - return !$entity->getProduct()->isVirtual() && $this->_getDependenceFromStoreConfig( - $this->getCached('address_item_' . $entity->getProductId()), - $store - ); + return $this->_getDependenceFromStoreConfig( + $this->getCached('address_item_' . $entity->getProductId()), + $store + ); } else { return Mage::getStoreConfig(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, $store); } diff --git a/app/code/core/Mage/GiftMessage/Model/Observer.php b/app/code/core/Mage/GiftMessage/Model/Observer.php index 615c9c8bf2..51b6551e80 100644 --- a/app/code/core/Mage/GiftMessage/Model/Observer.php +++ b/app/code/core/Mage/GiftMessage/Model/Observer.php @@ -180,6 +180,11 @@ public function catalogEventProductCollectionAfterLoad($observer) public function salesEventOrderToQuote($observer) { $order = $observer->getEvent()->getOrder(); + // Do not import giftmessage data if order is reordered + if ($order->getReordered()) { + return $this; + } + if (!Mage::helper('giftmessage/message')->isMessagesAvailable('order', $order, $order->getStore())){ return $this; } @@ -204,6 +209,11 @@ public function salesEventOrderItemToQuoteItem($observer) { /** @var $orderItem Mage_Sales_Model_Order_Item */ $orderItem = $observer->getEvent()->getOrderItem(); + // Do not import giftmessage data if order is reordered + $order = $orderItem->getOrder(); + if ($order && $order->getReordered()) { + return $this; + } if (!Mage::helper('giftmessage/message')->isMessagesAvailable('order_item', $orderItem, $orderItem->getStoreId())){ return $this; diff --git a/app/code/core/Mage/GiftMessage/etc/config.xml b/app/code/core/Mage/GiftMessage/etc/config.xml index df0399429a..9ec490b907 100644 --- a/app/code/core/Mage/GiftMessage/etc/config.xml +++ b/app/code/core/Mage/GiftMessage/etc/config.xml @@ -28,7 +28,7 @@ - 0.7.4 + 0.7.6 diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.4-0.7.5.php new file mode 100644 index 0000000000..3dccfde6ec --- /dev/null +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -0,0 +1,30 @@ +updateAttribute('catalog_product', 'gift_message_available', 'apply_to', ''); diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.5-0.7.6.php new file mode 100644 index 0000000000..c6b2eb2931 --- /dev/null +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -0,0 +1,35 @@ +updateAttribute( + 'catalog_product', + 'gift_message_available', + 'frontend_input_renderer', + 'giftmessage/adminhtml_product_helper_form_config' +); diff --git a/app/code/core/Mage/GoogleCheckout/Model/Payment.php b/app/code/core/Mage/GoogleCheckout/Model/Payment.php index ba07fc6e02..9121c538dd 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Payment.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Payment.php @@ -178,4 +178,21 @@ public function getConfigData($field, $storeId = null) $path = 'google/checkout/'.$field; return Mage::getStoreConfig($path, $storeId); } + + /** + * Check void availability + * + * @param Varien_Object $payment + * @return bool + */ + public function canVoid(Varien_Object $payment) + { + if ($payment instanceof Mage_Sales_Model_Order_Invoice + || $payment instanceof Mage_Sales_Model_Order_Creditmemo + ) { + return false; + } + + return $this->_canVoid; + } } diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php index 6c9d82de71..5e919c2b0c 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php @@ -46,7 +46,7 @@ abstract class Mage_ImportExport_Model_Export_Entity_Abstract * * @var array */ - protected $attrCodes = null; + protected static $attrCodes = null; /** * DB connection. diff --git a/app/code/core/Mage/PageCache/Block/Cache/Additional.php b/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php similarity index 91% rename from app/code/core/Mage/PageCache/Block/Cache/Additional.php rename to app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php index f839b34db9..ac36de4f7d 100644 --- a/app/code/core/Mage/PageCache/Block/Cache/Additional.php +++ b/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php @@ -31,7 +31,7 @@ * @package Mage_PageCache * @author Magento Core Team */ -class Mage_PageCache_Block_Cache_Additional extends Mage_Adminhtml_Block_Template +class Mage_PageCache_Block_Adminhtml_Cache_Additional extends Mage_Adminhtml_Block_Template { /** * Get clean cache url @@ -40,7 +40,7 @@ class Mage_PageCache_Block_Cache_Additional extends Mage_Adminhtml_Block_Templat */ public function getCleanExternalCacheUrl() { - return $this->getUrl('*/pagecache/clean'); + return $this->getUrl('*/pageCache/clean'); } /** diff --git a/app/code/core/Mage/PageCache/Model/System/Config/Source/Controls.php b/app/code/core/Mage/PageCache/Model/System/Config/Source/Controls.php index 7fed8e8c0f..9ca57cf117 100644 --- a/app/code/core/Mage/PageCache/Model/System/Config/Source/Controls.php +++ b/app/code/core/Mage/PageCache/Model/System/Config/Source/Controls.php @@ -19,7 +19,7 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Page + * @package Mage_PageCache * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PageCache/etc/system.xml b/app/code/core/Mage/PageCache/etc/system.xml index c0d983be43..aae869c983 100644 --- a/app/code/core/Mage/PageCache/etc/system.xml +++ b/app/code/core/Mage/PageCache/etc/system.xml @@ -70,4 +70,4 @@ - \ No newline at end of file + diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet.php b/app/code/core/Mage/Paygate/Model/Authorizenet.php index 995b73af16..7354124413 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet.php @@ -543,7 +543,7 @@ protected function _partialAuthorization($payment, $amount, $requestType) array('is_transaction_closed' => 0), array($this->_realTransactionIdKey => $card->getLastTransId()), Mage::helper('paygate')->getTransactionMessage( - $payment, $requestType, $card->getLastTransId(), $card, $amount + $payment, $requestType, $card->getLastTransId(), $card, $card->getProcessedAmount() ) ); if ($requestType == self::REQUEST_TYPE_AUTH_CAPTURE) { diff --git a/app/code/core/Mage/Payment/Model/Info/Exception.php b/app/code/core/Mage/Payment/Model/Info/Exception.php index fc87f66314..43020758b2 100644 --- a/app/code/core/Mage/Payment/Model/Info/Exception.php +++ b/app/code/core/Mage/Payment/Model/Info/Exception.php @@ -19,7 +19,7 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Core + * @package Mage_Payment * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Method/Abstract.php b/app/code/core/Mage/Payment/Model/Method/Abstract.php index d890786508..9dee188030 100644 --- a/app/code/core/Mage/Payment/Model/Method/Abstract.php +++ b/app/code/core/Mage/Payment/Model/Method/Abstract.php @@ -148,7 +148,7 @@ public function canRefundPartialPerInvoice() /** * Check void availability * - * @param Varien_Object $invoicePayment + * @param Varien_Object $payment * @return bool */ public function canVoid(Varien_Object $payment) diff --git a/app/code/core/Mage/Payment/etc/config.xml b/app/code/core/Mage/Payment/etc/config.xml index ec3ffc1998..7b4436b8da 100644 --- a/app/code/core/Mage/Payment/etc/config.xml +++ b/app/code/core/Mage/Payment/etc/config.xml @@ -92,11 +92,6 @@ JCB 50 - - MCI - Maestro (International) - 53 - OT Other diff --git a/app/code/core/Mage/Paypal/Block/Hosted/Pro/Iframe.php b/app/code/core/Mage/Paypal/Block/Hosted/Pro/Iframe.php index af80d4ceba..ed5e50a075 100644 --- a/app/code/core/Mage/Paypal/Block/Hosted/Pro/Iframe.php +++ b/app/code/core/Mage/Paypal/Block/Hosted/Pro/Iframe.php @@ -33,7 +33,7 @@ */ class Mage_Paypal_Block_Hosted_Pro_Iframe extends Mage_Paypal_Block_Iframe { - /** + /** * Internal constructor * Set payment method code * diff --git a/app/code/core/Mage/Paypal/Block/Iframe.php b/app/code/core/Mage/Paypal/Block/Iframe.php index 80016287af..6065e0556e 100644 --- a/app/code/core/Mage/Paypal/Block/Iframe.php +++ b/app/code/core/Mage/Paypal/Block/Iframe.php @@ -113,7 +113,7 @@ protected function _getOrder() return $this->_order; } - /** + /** * Get frontend checkout session object * * @return Mage_Checkout_Model_Session @@ -227,4 +227,4 @@ public function isTestMode() { return $this->_getBlock()->isTestMode(); } -} \ No newline at end of file +} diff --git a/app/code/core/Mage/Paypal/Block/Payflow/Link/Iframe.php b/app/code/core/Mage/Paypal/Block/Payflow/Link/Iframe.php index 824235a173..170d46c844 100644 --- a/app/code/core/Mage/Paypal/Block/Payflow/Link/Iframe.php +++ b/app/code/core/Mage/Paypal/Block/Payflow/Link/Iframe.php @@ -51,7 +51,7 @@ protected function _construct() */ public function getFrameActionUrl() { - return $this->getUrl('paypal/payflow/form'); + return $this->getUrl('paypal/payflow/form', array('_secure' => true)); } /** diff --git a/app/code/core/Mage/Paypal/Model/Cart.php b/app/code/core/Mage/Paypal/Model/Cart.php index 259b1f3e6d..022293df8f 100644 --- a/app/code/core/Mage/Paypal/Model/Cart.php +++ b/app/code/core/Mage/Paypal/Model/Cart.php @@ -211,6 +211,23 @@ public function addItem($name, $qty, $amount, $identifier = null) return $item; } + /** + * Remove item from cart by identifier + * + * @param string $identifier + * @return bool + */ + public function removeItem($identifier) + { + foreach ($this->_items as $key => $item) { + if ($item->getId() == $identifier) { + unset($this->_items[$key]); + return true; + } + } + return false; + } + /** * Compound the specified amount with the specified total * @@ -311,12 +328,19 @@ protected function _render() $this->_renderTotalLineItemDescriptions(self::TOTAL_DISCOUNT) ); } + $shippingItemId = $this->_renderTotalLineItemDescriptions(self::TOTAL_SHIPPING, $shippingDescription); if ($this->_isShippingAsItem && (float)$this->_totals[self::TOTAL_SHIPPING]) { $this->addItem(Mage::helper('paypal')->__('Shipping'), 1, (float)$this->_totals[self::TOTAL_SHIPPING], - $this->_renderTotalLineItemDescriptions(self::TOTAL_SHIPPING, $shippingDescription) + $shippingItemId ); } + $this->_validate(); + // if cart items are invalid, prepare cart for transfer without line items + if (!$this->_areItemsValid) { + $this->removeItem($shippingItemId); + } + // compound non-regular items into subtotal foreach ($this->_items as $key => $item) { if ($key > $lastRegularItemKey && $item->getAmount() != 0) { @@ -324,7 +348,6 @@ protected function _render() } } - $this->_validate(); $this->_shouldRender = false; } @@ -401,21 +424,29 @@ protected function _validate() protected function _addRegularItem(Varien_Object $salesItem) { if ($this->_salesEntity instanceof Mage_Sales_Model_Order) { - $qty = $salesItem->getQtyOrdered(); - $amount = $salesItem->getBasePrice(); + $qty = (int) $salesItem->getQtyOrdered(); + $amount = (float) $salesItem->getBasePrice(); // TODO: nominal item for order } else { - $qty = $salesItem->getTotalQty(); - $amount = $salesItem->isNominal() ? 0 : $salesItem->getBaseCalculationPrice(); + $qty = (int) $salesItem->getTotalQty(); + $amount = $salesItem->isNominal() ? 0 : (float) $salesItem->getBaseCalculationPrice(); } // workaround in case if item subtotal precision is not compatible with PayPal (.2) $subAggregatedLabel = ''; - if ((float)$amount - round((float)$amount, 2)) { + if ($amount - round($amount, 2)) { $amount = $amount * $qty; $subAggregatedLabel = ' x' . $qty; $qty = 1; } - return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, (float)$amount, $salesItem->getSku()); + + // aggregate item price if item qty * price does not match row total + if (($amount * $qty) != $salesItem->getBaseRowTotal()) { + $amount = (float) $salesItem->getBaseRowTotal(); + $subAggregatedLabel = ' x' . $qty; + $qty = 1; + } + + return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku()); } /** diff --git a/app/code/core/Mage/Paypal/Model/Config.php b/app/code/core/Mage/Paypal/Model/Config.php index d0c48dcb13..51c39af418 100644 --- a/app/code/core/Mage/Paypal/Model/Config.php +++ b/app/code/core/Mage/Paypal/Model/Config.php @@ -809,11 +809,14 @@ public function getExpressCheckoutButtonTypes() */ public function getPaymentActions() { - return array( - self::PAYMENT_ACTION_AUTH => Mage::helper('paypal')->__('Authorization'), - self::PAYMENT_ACTION_ORDER => Mage::helper('paypal')->__('Order'), - self::PAYMENT_ACTION_SALE => Mage::helper('paypal')->__('Sale'), + $paymentActions = array( + self::PAYMENT_ACTION_AUTH => Mage::helper('paypal')->__('Authorization'), + self::PAYMENT_ACTION_SALE => Mage::helper('paypal')->__('Sale') ); + if (!is_null($this->_methodCode) && $this->_methodCode == self::METHOD_WPP_EXPRESS) { + $paymentActions[self::PAYMENT_ACTION_ORDER] = Mage::helper('paypal')->__('Order'); + } + return $paymentActions; } /** diff --git a/app/code/core/Mage/Paypal/Model/Direct.php b/app/code/core/Mage/Paypal/Model/Direct.php index c5a6344bcc..1c12a61d9b 100644 --- a/app/code/core/Mage/Paypal/Model/Direct.php +++ b/app/code/core/Mage/Paypal/Model/Direct.php @@ -224,7 +224,8 @@ public function refund(Varien_Object $payment, $amount) */ public function cancel(Varien_Object $payment) { - $this->_pro->cancel($payment); + $this->void($payment); + return $this; } @@ -370,4 +371,21 @@ protected function _importResultToPayment($api, $payment) $payment->setTransactionId($api->getTransactionId())->setIsTransactionClosed(0); $this->_pro->importPaymentInfo($api, $payment); } + + /** + * Check void availability + * + * @param Varien_Object $payment + * @return bool + */ + public function canVoid(Varien_Object $payment) + { + if ($payment instanceof Mage_Sales_Model_Order_Invoice + || $payment instanceof Mage_Sales_Model_Order_Creditmemo + ) { + return false; + } + + return $this->_canVoid; + } } diff --git a/app/code/core/Mage/Paypal/Model/Express.php b/app/code/core/Mage/Paypal/Model/Express.php index 5e8c05554f..6537cc42fc 100644 --- a/app/code/core/Mage/Paypal/Model/Express.php +++ b/app/code/core/Mage/Paypal/Model/Express.php @@ -46,6 +46,7 @@ class Mage_Paypal_Model_Express extends Mage_Payment_Model_Method_Abstract * Availability options */ protected $_isGateway = false; + protected $_canOrder = true; protected $_canAuthorize = true; protected $_canCapture = true; protected $_canCapturePartial = true; @@ -212,7 +213,8 @@ public function refund(Varien_Object $payment, $amount) */ public function cancel(Varien_Object $payment) { - $this->_pro->cancel($payment); + $this->void($payment); + return $this; } @@ -409,4 +411,21 @@ protected function _importToPayment($api, $payment) $this->_pro->importPaymentInfo($api, $payment); } + + /** + * Check void availability + * + * @param Varien_Object $payment + * @return bool + */ + public function canVoid(Varien_Object $payment) + { + if ($payment instanceof Mage_Sales_Model_Order_Invoice + || $payment instanceof Mage_Sales_Model_Order_Creditmemo + ) { + return false; + } + + return $this->_canVoid; + } } diff --git a/app/code/core/Mage/Paypal/Model/Pro.php b/app/code/core/Mage/Paypal/Model/Pro.php index ab0b760ca7..7d86f116f1 100644 --- a/app/code/core/Mage/Paypal/Model/Pro.php +++ b/app/code/core/Mage/Paypal/Model/Pro.php @@ -242,7 +242,7 @@ public function refund(Varien_Object $payment, $amount) ->setAmount($amount) ->setCurrencyCode($order->getBaseCurrencyCode()) ; - $canRefundMore = $order->canCreditmemo(); // TODO: fix this to be able to create multiple refunds + $canRefundMore = $payment->getCreditmemo()->getInvoice()->canRefund(); $isFullRefund = !$canRefundMore && (0 == ((float)$order->getBaseTotalOnlineRefunded() + (float)$order->getBaseTotalOfflineRefunded())); $api->setRefundType($isFullRefund ? Mage_Paypal_Model_Config::REFUND_TYPE_FULL diff --git a/app/code/core/Mage/Paypal/Model/Standard.php b/app/code/core/Mage/Paypal/Model/Standard.php index 4802a45a5b..55851bb121 100644 --- a/app/code/core/Mage/Paypal/Model/Standard.php +++ b/app/code/core/Mage/Paypal/Model/Standard.php @@ -141,9 +141,7 @@ public function getStandardCheckoutFormFields() $api->setPaypalCart(Mage::getModel('paypal/cart', array($order))) ->setIsLineItemsEnabled($this->_config->lineItemsEnabled) ; - if (!$this->_config->lineItemsEnabled) { - $api->setCartSummary($this->_getAggregatedCartSummary()); - } + $api->setCartSummary($this->_getAggregatedCartSummary()); $result = $api->getStandardCheckoutRequest(); return $result; diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cert.php b/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cert.php index 0e22065037..fc31f93e9b 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cert.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cert.php @@ -42,6 +42,9 @@ protected function _beforeSave() Mage::getModel('paypal/cert')->loadByWebsite($this->getScopeId())->delete(); } + if (!isset($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'])) { + return $this; + } $tmpPath = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']; if ($tmpPath && file_exists($tmpPath)) { if (!filesize($tmpPath)) { diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions.php b/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions.php new file mode 100644 index 0000000000..79068de661 --- /dev/null +++ b/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions.php @@ -0,0 +1,42 @@ +getPaymentActions(); + } +} diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions/Express.php b/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions/Express.php new file mode 100644 index 0000000000..e9c0be947d --- /dev/null +++ b/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions/Express.php @@ -0,0 +1,43 @@ +setMethod(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS); + return $configModel->getPaymentActions(); + } +} diff --git a/app/code/core/Mage/Paypal/controllers/HostedproController.php b/app/code/core/Mage/Paypal/controllers/HostedproController.php index a43ec4c72a..dcdf9dc40f 100644 --- a/app/code/core/Mage/Paypal/controllers/HostedproController.php +++ b/app/code/core/Mage/Paypal/controllers/HostedproController.php @@ -45,7 +45,7 @@ public function returnAction() } } - /** + /** * When a customer cancel payment from gateway. */ public function cancelAction() @@ -58,7 +58,7 @@ public function cancelAction() $this->getResponse()->setBody($redirectBlock->toHtml()); } - /** + /** * Cancel order, return quote to customer * * @param string $errorMsg @@ -94,7 +94,7 @@ protected function _cancelPayment($errorMsg = '') return $gotoSection; } - /** + /** * Get frontend checkout session object * * @return Mage_Checkout_Model_Session diff --git a/app/code/core/Mage/Paypal/etc/system.xml b/app/code/core/Mage/Paypal/etc/system.xml index 702dc95009..a19c395374 100644 --- a/app/code/core/Mage/Paypal/etc/system.xml +++ b/app/code/core/Mage/Paypal/etc/system.xml @@ -317,7 +317,7 @@ payment/paypal_express/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions_express 15 1 1 @@ -458,7 +458,7 @@ payment/paypal_standard/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions 15 1 1 @@ -555,7 +555,7 @@ payment/paypal_direct/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions 15 1 1 @@ -704,7 +704,7 @@ payment/paypal_billing_agreement/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions 20 1 1 @@ -791,7 +791,7 @@ payment/paypaluk_direct/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions 15 1 1 @@ -975,7 +975,7 @@ 1 - + @@ -1008,7 +1008,7 @@ payment/verisign/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions 15 1 1 @@ -1214,7 +1214,7 @@ payment/paypaluk_express/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions 15 1 1 @@ -1451,7 +1451,7 @@ - + text @@ -1490,7 +1490,7 @@ payment/payflow_link/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions 15 1 1 @@ -1541,7 +1541,7 @@ text - payment/payflow_link/user + payment/payflow_link/user 45 1 1 @@ -1633,7 +1633,7 @@ payment/hosted_pro/payment_action select - paypal/config::getPaymentActions + paypal/system_config_source_paymentActions 15 1 1 @@ -1656,7 +1656,7 @@ 1 1 1 - + payment/hosted_pro/debug diff --git a/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php b/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php index fda8583acd..22e50a4bc9 100644 --- a/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php +++ b/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php @@ -251,7 +251,7 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp 'SALUTATION' => 'prefix', 'SUFFIX' => 'suffix', - 'COUNTRY' => 'country_id', // iso-3166 two-character code + 'COUNTRYCODE' => 'country_id', // iso-3166 two-character code 'STATE' => 'region', 'CITY' => 'city', 'STREET' => 'street', diff --git a/app/code/core/Mage/ProductAlert/Model/Email.php b/app/code/core/Mage/ProductAlert/Model/Email.php index 64bd21c348..1074922d7e 100644 --- a/app/code/core/Mage/ProductAlert/Model/Email.php +++ b/app/code/core/Mage/ProductAlert/Model/Email.php @@ -247,18 +247,12 @@ public function send() return false; } - // set design parameters, required for email (remember current) - $currentDesign = Mage::getDesign()->setAllGetOld(array( - 'store' => $storeId, - 'area' => 'frontend', - 'package' => Mage::getStoreConfig('design/package/name', $storeId), - )); - - Mage::app()->getLocale()->emulate($storeId); + if ($this->_type != 'price' && $this->_type != 'stock') { + return false; + } - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); + $appEmulation = Mage::getSingleton('core/app_emulation'); + $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); if ($this->_type == 'price') { $this->_getPriceBlock() @@ -270,8 +264,7 @@ public function send() } $block = $this->_getPriceBlock()->toHtml(); $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_PRICE_TEMPLATE, $storeId); - } - elseif ($this->_type == 'stock') { + } else { $this->_getStockBlock() ->setStore($store) ->reset(); @@ -282,10 +275,8 @@ public function send() $block = $this->_getStockBlock()->toHtml(); $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_STOCK_TEMPLATE, $storeId); } - else { - Mage::app()->getLocale()->revert(); - return false; - } + + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); Mage::getModel('core/email_template') ->setDesignConfig(array( @@ -302,12 +293,6 @@ public function send() ) ); - $translate->setTranslateInline(true); - - // revert current design - Mage::getDesign()->setAllGetOld($currentDesign); - Mage::app()->getLocale()->revert(); - return true; } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php index 3744e8270a..572e80e3b3 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php @@ -197,7 +197,10 @@ public function addOrderedQty($from = '', $to = '') $this->getSelect()->reset()->from( array('order_items' => $qtyOrderedTableName), - array('ordered_qty' => "SUM(order_items.{$qtyOrderedFieldName})") + array( + 'ordered_qty' => "SUM(order_items.{$qtyOrderedFieldName})", + 'order_items_name' => 'order_items.name' + ) ); $_joinCondition = $this->getConnection()->quoteInto( @@ -212,9 +215,9 @@ public function addOrderedQty($from = '', $to = '') $this->getSelect() - ->joinInner(array('e' => $this->getProductEntityTableName()), + ->joinLeft(array('e' => $this->getProductEntityTableName()), "e.entity_id = order_items.{$productIdFieldName} AND e.entity_type_id = {$this->getProductEntityTypeId()}{$productTypes}") - ->group('e.entity_id') + ->group('order_items.product_id') ->having('ordered_qty > 0'); return $this; diff --git a/app/code/core/Mage/Rule/Model/Condition/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Abstract.php index a702b1ba93..3769c4905c 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Abstract.php @@ -515,7 +515,7 @@ public function validateAttribute($validatedValue) ($op == '()' || $op == '!()' || $op == '{}' || $op == '!{}') && !is_array($value) ) || ( - !($op == '()' || $op == '!()' || $op == '{}' || $op == '!{}') + !($op == '()' || $op == '!()' || $op == '{}' || $op == '!{}' || $op == '==' || $op == '!=') && is_array($value) )) { return false; @@ -525,10 +525,19 @@ public function validateAttribute($validatedValue) switch ($op) { case '==': case '!=': - if (is_array($validatedValue)) { - $result = in_array($value, $validatedValue); + if (is_array($value)) { + if (is_array($validatedValue)) { + $result = array_intersect($value, $validatedValue); + $result = !empty($result); + } else { + return false; + } } else { - $result = $validatedValue == $value; + if (is_array($validatedValue)) { + $result = in_array($value, $validatedValue); + } else { + $result = $validatedValue == $value; + } } break; diff --git a/app/code/core/Mage/Rule/Model/Rule.php b/app/code/core/Mage/Rule/Model/Rule.php index a3625512f1..196adb95ea 100644 --- a/app/code/core/Mage/Rule/Model/Rule.php +++ b/app/code/core/Mage/Rule/Model/Rule.php @@ -80,7 +80,7 @@ public function setConditions($conditions) /** * Retrieve Condition model * - * @return Mage_SalesRule_Model_Rule_Condition_Abstract + * @return Mage_SalesRule_Model_Rule_Condition_Combine */ public function getConditions() { @@ -345,7 +345,7 @@ public function setIsReadonly($value) $this->_isReadonly = (boolean) $value; return $this; } - + /** * Validates data for rule * @param Varien_Object $object @@ -357,7 +357,7 @@ public function validateData(Varien_Object $object) if($object->getData('from_date') && $object->getData('to_date')){ $dateStart = new Zend_Date($object->getData('from_date'), Varien_Date::DATE_INTERNAL_FORMAT); $dateEnd = new Zend_Date($object->getData('to_date'), Varien_Date::DATE_INTERNAL_FORMAT); - + if ($dateStart->compare($dateEnd)===1) { return array(Mage::helper('rule')->__("End Date should be greater than Start Date")); } diff --git a/app/code/core/Mage/Sales/Model/Order.php b/app/code/core/Mage/Sales/Model/Order.php index ea9120b0e6..59a7a4d894 100644 --- a/app/code/core/Mage/Sales/Model/Order.php +++ b/app/code/core/Mage/Sales/Model/Order.php @@ -805,7 +805,7 @@ public function cancel() } /** - * Prepare order totlas to cancellation + * Prepare order totals to cancellation * @param string $comment * @param bool $graceful * @return Mage_Sales_Model_Order @@ -883,160 +883,151 @@ public function getShippingCarrier() } /** - * Sending email with order data + * Send email with order data * * @return Mage_Sales_Model_Order */ public function sendNewOrderEmail() { - if (!Mage::helper('sales')->canSendNewOrderEmail($this->getStore()->getId())) { + $storeId = $this->getStore()->getId(); + + if (!Mage::helper('sales')->canSendNewOrderEmail($storeId)) { return $this; } + // Get the destination email addresses to send copies to + $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO); + $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId); - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); - - $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment()) - ->setIsSecureMode(true); - - $paymentBlock->getMethod()->setStore($this->getStore()->getId()); + // Start store emulation process + $appEmulation = Mage::getSingleton('core/app_emulation'); + $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); - $mailTemplate = Mage::getModel('core/email_template'); - /* @var $mailTemplate Mage_Core_Model_Email_Template */ - $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO); - $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $this->getStoreId()); - if ($copyTo && $copyMethod == 'bcc') { - foreach ($copyTo as $email) { - $mailTemplate->addBcc($email); - } + try { + // Retrieve specified view block from appropriate design package (depends on emulated store) + $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment()) + ->setIsSecureMode(true); + $paymentBlock->getMethod()->setStore($storeId); + $paymentBlockHtml = $paymentBlock->toHtml(); + } catch (Exception $exception) { + // Stop store emulation process + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + throw $exception; } + // Stop store emulation process + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + + // Retrieve corresponding email template id and customer name if ($this->getCustomerIsGuest()) { - $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $this->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId); $customerName = $this->getBillingAddress()->getName(); } else { - $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $this->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId); $customerName = $this->getCustomerName(); } - $sendTo = array( - array( - 'email' => $this->getCustomerEmail(), - 'name' => $customerName - ) - ); - if ($copyTo && $copyMethod == 'copy') { + $mailer = Mage::getModel('core/email_template_mailer'); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($this->getCustomerEmail(), $customerName); + if ($copyTo && $copyMethod == 'bcc') { + // Add bcc to customer email foreach ($copyTo as $email) { - $sendTo[] = array( - 'email' => $email, - 'name' => null - ); + $emailInfo->addBcc($email); } } + $mailer->addEmailInfo($emailInfo); - foreach ($sendTo as $recipient) { - $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$this->getStoreId())) - ->sendTransactional( - $template, - Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $this->getStoreId()), - $recipient['email'], - $recipient['name'], - array( - 'order' => $this, - 'billing' => $this->getBillingAddress(), - 'payment_html' => $paymentBlock->toHtml(), - ) - ); + // Email copies are sent as separated emails if their copy method is 'copy' + if ($copyTo && $copyMethod == 'copy') { + foreach ($copyTo as $email) { + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($email); + $mailer->addEmailInfo($emailInfo); + } } + + // Set all required params and send emails + $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId)); + $mailer->setStoreId($storeId); + $mailer->setTemplateId($templateId); + $mailer->setTemplateParams(array( + 'order' => $this, + 'billing' => $this->getBillingAddress(), + 'payment_html' => $paymentBlockHtml + ) + ); + $mailer->send(); + $this->setEmailSent(true); $this->_getResource()->saveAttribute($this, 'email_sent'); - $translate->setTranslateInline(true); return $this; } /** - * Sending email with order update information + * Send email with order update information * + * @param boolean $notifyCustomer + * @param string $comment * @return Mage_Sales_Model_Order */ - public function sendOrderUpdateEmail($notifyCustomer=true, $comment='') + public function sendOrderUpdateEmail($notifyCustomer = true, $comment = '') { - if (!Mage::helper('sales')->canSendOrderCommentEmail($this->getStore()->getId())) { + $storeId = $this->getStore()->getId(); + + if (!Mage::helper('sales')->canSendOrderCommentEmail($storeId)) { return $this; } - + // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO); - $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $this->getStoreId()); + $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $storeId); + // Check if at least one recepient is found if (!$notifyCustomer && !$copyTo) { return $this; } - // set design parameters, required for email (remember current) - $currentDesign = Mage::getDesign()->setAllGetOld(array( - 'store' => $this->getStoreId(), - 'area' => 'frontend', - 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), - )); - - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); - - $sendTo = array(); - - $mailTemplate = Mage::getModel('core/email_template'); - + // Retrieve corresponding email template id and customer name if ($this->getCustomerIsGuest()) { - $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $this->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $storeId); $customerName = $this->getBillingAddress()->getName(); } else { - $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $this->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $storeId); $customerName = $this->getCustomerName(); } + $mailer = Mage::getModel('core/email_template_mailer'); if ($notifyCustomer) { - $sendTo[] = array( - 'name' => $customerName, - 'email' => $this->getCustomerEmail() - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($this->getCustomerEmail(), $customerName); if ($copyTo && $copyMethod == 'bcc') { + // Add bcc to customer email foreach ($copyTo as $email) { - $mailTemplate->addBcc($email); + $emailInfo->addBcc($email); } } - + $mailer->addEmailInfo($emailInfo); } + // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { foreach ($copyTo as $email) { - $sendTo[] = array( - 'name' => null, - 'email' => $email - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($email); + $mailer->addEmailInfo($emailInfo); } } - foreach ($sendTo as $recipient) { - $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store' => $this->getStoreId())) - ->sendTransactional( - $template, - Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $this->getStoreId()), - $recipient['email'], - $recipient['name'], - array( - 'order' => $this, - 'billing' => $this->getBillingAddress(), - 'comment' => $comment - ) - ); - } - - $translate->setTranslateInline(true); - - // revert current design - Mage::getDesign()->setAllGetOld($currentDesign); + // Set all required params and send emails + $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $storeId)); + $mailer->setStoreId($storeId); + $mailer->setTemplateId($templateId); + $mailer->setTemplateParams(array( + 'order' => $this, + 'comment' => $comment, + 'billing' => $this->getBillingAddress() + ) + ); + $mailer->send(); return $this; } diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo.php index 8e78f4dcf0..44d358f324 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo.php @@ -287,6 +287,9 @@ public function refund() if ($this->getInvoice()) { $this->getInvoice()->setIsUsedForRefund(true); + $this->getInvoice()->setBaseTotalRefunded( + $this->getInvoice()->getBaseTotalRefunded() + $this->getBaseGrandTotal() + ); $this->setInvoiceId($this->getInvoice()->getId()); } @@ -535,172 +538,161 @@ public function getCommentsCollection($reload=false) /** - * Sending email with creditmemo data + * Send email with creditmemo data * - * @return Mage_Sales_Model_Order_Invoice + * @param boolean $notifyCustomer + * @param string $comment + * @return Mage_Sales_Model_Order_Creditmemo */ - public function sendEmail($notifyCustomer=true, $comment='') + public function sendEmail($notifyCustomer = true, $comment = '') { - if (!Mage::helper('sales')->canSendNewCreditmemoEmail($this->getOrder()->getStore()->getId())) { + $order = $this->getOrder(); + $storeId = $order->getStore()->getId(); + + if (!Mage::helper('sales')->canSendNewCreditmemoEmail($storeId)) { return $this; } - - $currentDesign = Mage::getDesign()->setAllGetOld(array( - 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), - 'store' => $this->getStoreId() - )); - - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); - - $order = $this->getOrder(); - + // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO); - $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $this->getStoreId()); - + $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId); + // Check if at least one recepient is found if (!$notifyCustomer && !$copyTo) { return $this; } - $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment()) - ->setIsSecureMode(true); - $paymentBlock->getMethod()->setStore($order->getStore()->getId()); - $mailTemplate = Mage::getModel('core/email_template'); + // Start store emulation process + $appEmulation = Mage::getSingleton('core/app_emulation'); + $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); + try { + // Retrieve specified view block from appropriate design package (depends on emulated store) + $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment()) + ->setIsSecureMode(true); + $paymentBlock->getMethod()->setStore($storeId); + $paymentBlockHtml = $paymentBlock->toHtml(); + } catch (Exception $exception) { + // Stop store emulation process + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + throw $exception; + } + + // Stop store emulation process + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + + // Retrieve corresponding email template id and customer name if ($order->getCustomerIsGuest()) { - $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId); $customerName = $order->getBillingAddress()->getName(); } else { - $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId); $customerName = $order->getCustomerName(); } + $mailer = Mage::getModel('core/email_template_mailer'); if ($notifyCustomer) { - $sendTo[] = array( - 'name' => $customerName, - 'email' => $order->getCustomerEmail() - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($order->getCustomerEmail(), $customerName); if ($copyTo && $copyMethod == 'bcc') { + // Add bcc to customer email foreach ($copyTo as $email) { - $mailTemplate->addBcc($email); + $emailInfo->addBcc($email); } } - + $mailer->addEmailInfo($emailInfo); } + // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { foreach ($copyTo as $email) { - $sendTo[] = array( - 'name' => null, - 'email' => $email - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($email); + $mailer->addEmailInfo($emailInfo); } } - foreach ($sendTo as $recipient) { - $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId())) - ->sendTransactional( - $template, - Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $order->getStoreId()), - $recipient['email'], - $recipient['name'], - array( - 'order' => $order, - 'creditmemo' => $this, - 'comment' => $comment, - 'billing' => $order->getBillingAddress(), - 'payment_html'=> $paymentBlock->toHtml(), - ) - ); - } - - $translate->setTranslateInline(true); - - Mage::getDesign()->setAllGetOld($currentDesign); + // Set all required params and send emails + $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId)); + $mailer->setStoreId($storeId); + $mailer->setTemplateId($templateId); + $mailer->setTemplateParams(array( + 'order' => $order, + 'creditmemo' => $this, + 'comment' => $comment, + 'billing' => $order->getBillingAddress(), + 'payment_html' => $paymentBlockHtml + ) + ); + $mailer->send(); return $this; } /** - * Sending email with invoice update information + * Send email with creditmemo update information * - * @return Mage_Sales_Model_Order_Invoice + * @param boolean $notifyCustomer + * @param string $comment + * @return Mage_Sales_Model_Order_Creditmemo */ - public function sendUpdateEmail($notifyCustomer=true, $comment='') + public function sendUpdateEmail($notifyCustomer = true, $comment = '') { - if (!Mage::helper('sales')->canSendCreditmemoCommentEmail($this->getOrder()->getStore()->getId())) { + $order = $this->getOrder(); + $storeId = $order->getStore()->getId(); + + if (!Mage::helper('sales')->canSendCreditmemoCommentEmail($storeId)) { return $this; } - - $currentDesign = Mage::getDesign()->setAllGetOld(array( - 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), - )); - - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); - - $order = $this->getOrder(); - + // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO); - $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $this->getStoreId()); - + $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $storeId); + // Check if at least one recepient is found if (!$notifyCustomer && !$copyTo) { return $this; } - $mailTemplate = Mage::getModel('core/email_template'); - + // Retrieve corresponding email template id and customer name if ($order->getCustomerIsGuest()) { - $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $storeId); $customerName = $order->getBillingAddress()->getName(); } else { - $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $storeId); $customerName = $order->getCustomerName(); } + $mailer = Mage::getModel('core/email_template_mailer'); if ($notifyCustomer) { - $sendTo[] = array( - 'name' => $customerName, - 'email' => $order->getCustomerEmail() - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($order->getCustomerEmail(), $customerName); if ($copyTo && $copyMethod == 'bcc') { + // Add bcc to customer email foreach ($copyTo as $email) { - $mailTemplate->addBcc($email); + $emailInfo->addBcc($email); } } - + $mailer->addEmailInfo($emailInfo); } + // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { foreach ($copyTo as $email) { - $sendTo[] = array( - 'name' => null, - 'email' => $email - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($email); + $mailer->addEmailInfo($emailInfo); } } - foreach ($sendTo as $recipient) { - $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId())) - ->sendTransactional( - $template, - Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $order->getStoreId()), - $recipient['email'], - $recipient['name'], - array( - 'order' => $order, - 'billing'=> $order->getBillingAddress(), - 'creditmemo'=> $this, - 'comment'=> $comment - ) - ); - } - - $translate->setTranslateInline(true); - - Mage::getDesign()->setAllGetOld($currentDesign); + // Set all required params and send emails + $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $storeId)); + $mailer->setStoreId($storeId); + $mailer->setTemplateId($templateId); + $mailer->setTemplateParams(array( + 'order' => $order, + 'creditmemo' => $this, + 'comment' => $comment, + 'billing' => $order->getBillingAddress() + ) + ); + $mailer->send(); return $this; } diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice.php b/app/code/core/Mage/Sales/Model/Order/Invoice.php index a2648e790e..baad247bf9 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice.php @@ -233,7 +233,7 @@ public function canVoid() } /** - * Check invice cancel action availability + * Check invoice cancel action availability * * @return bool */ @@ -242,6 +242,22 @@ public function canCancel() return $this->getState() == self::STATE_OPEN; } + /** + * Check invoice refund action availability + * + * @return bool + */ + public function canRefund() + { + if ($this->getState() != self::STATE_PAID) { + return false; + } + if (abs($this->getBaseGrandTotal() - $this->getBaseTotalRefunded()) < .0001) { + return false; + } + return true; + } + /** * Capture invoice * @@ -590,173 +606,161 @@ public function getCommentsCollection($reload=false) } /** - * Sending email with Invoice data + * Send email with invoice data * + * @param boolean $notifyCustomer + * @param string $comment * @return Mage_Sales_Model_Order_Invoice */ - public function sendEmail($notifyCustomer=true, $comment='') + public function sendEmail($notifyCustomer = true, $comment = '') { - if (!Mage::helper('sales')->canSendNewInvoiceEmail($this->getOrder()->getStore()->getId())) { + $order = $this->getOrder(); + $storeId = $order->getStore()->getId(); + + if (!Mage::helper('sales')->canSendNewInvoiceEmail($storeId)) { return $this; } - - $currentDesign = Mage::getDesign()->setAllGetOld(array( - 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), - 'store' => $this->getStoreId() - )); - - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); - - $order = $this->getOrder(); + // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO); - $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $this->getStoreId()); - + $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId); + // Check if at least one recepient is found if (!$notifyCustomer && !$copyTo) { return $this; } - $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment()) - ->setIsSecureMode(true); - $paymentBlock->getMethod()->setStore($order->getStore()->getId()); - $mailTemplate = Mage::getModel('core/email_template'); + // Start store emulation process + $appEmulation = Mage::getSingleton('core/app_emulation'); + $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); + + try { + // Retrieve specified view block from appropriate design package (depends on emulated store) + $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment()) + ->setIsSecureMode(true); + $paymentBlock->getMethod()->setStore($storeId); + $paymentBlockHtml = $paymentBlock->toHtml(); + } catch (Exception $exception) { + // Stop store emulation process + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + throw $exception; + } + // Stop store emulation process + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + + // Retrieve corresponding email template id and customer name if ($order->getCustomerIsGuest()) { - $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId); $customerName = $order->getBillingAddress()->getName(); } else { - $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId); $customerName = $order->getCustomerName(); } + $mailer = Mage::getModel('core/email_template_mailer'); if ($notifyCustomer) { - $sendTo[] = array( - 'name' => $customerName, - 'email' => $order->getCustomerEmail() - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($order->getCustomerEmail(), $customerName); if ($copyTo && $copyMethod == 'bcc') { + // Add bcc to customer email foreach ($copyTo as $email) { - $mailTemplate->addBcc($email); + $emailInfo->addBcc($email); } } - + $mailer->addEmailInfo($emailInfo); } + // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { foreach ($copyTo as $email) { - $sendTo[] = array( - 'name' => null, - 'email' => $email - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($email); + $mailer->addEmailInfo($emailInfo); } } - foreach ($sendTo as $recipient) { - $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId())) - ->sendTransactional( - $template, - Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $order->getStoreId()), - $recipient['email'], - $recipient['name'], - array( - 'order' => $order, - 'invoice' => $this, - 'comment' => $comment, - 'billing' => $order->getBillingAddress(), - 'payment_html'=> $paymentBlock->toHtml(), - ) - ); - } - - $translate->setTranslateInline(true); - - Mage::getDesign()->setAllGetOld($currentDesign); + // Set all required params and send emails + $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId)); + $mailer->setStoreId($storeId); + $mailer->setTemplateId($templateId); + $mailer->setTemplateParams(array( + 'order' => $order, + 'invoice' => $this, + 'comment' => $comment, + 'billing' => $order->getBillingAddress(), + 'payment_html' => $paymentBlockHtml + ) + ); + $mailer->send(); return $this; } /** - * Sending email with invoice update information + * Send email with invoice update information * + * @param boolean $notifyCustomer + * @param string $comment * @return Mage_Sales_Model_Order_Invoice */ - public function sendUpdateEmail($notifyCustomer=true, $comment='') + public function sendUpdateEmail($notifyCustomer = true, $comment = '') { - if (!Mage::helper('sales')->canSendInvoiceCommentEmail($this->getOrder()->getStore()->getId())) { + $order = $this->getOrder(); + $storeId = $order->getStore()->getId(); + + if (!Mage::helper('sales')->canSendInvoiceCommentEmail($storeId)) { return $this; } - - $currentDesign = Mage::getDesign()->setAllGetOld(array( - 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), - )); - - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); - - $order = $this->getOrder(); - + // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO); - $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $this->getStoreId()); - + $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $storeId); + // Check if at least one recepient is found if (!$notifyCustomer && !$copyTo) { return $this; } - $sendTo = array(); - - $mailTemplate = Mage::getModel('core/email_template'); - + // Retrieve corresponding email template id and customer name if ($order->getCustomerIsGuest()) { - $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $storeId); $customerName = $order->getBillingAddress()->getName(); } else { - $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $storeId); $customerName = $order->getCustomerName(); } + $mailer = Mage::getModel('core/email_template_mailer'); if ($notifyCustomer) { - $sendTo[] = array( - 'name' => $customerName, - 'email' => $order->getCustomerEmail() - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($order->getCustomerEmail(), $customerName); if ($copyTo && $copyMethod == 'bcc') { + // Add bcc to customer email foreach ($copyTo as $email) { - $mailTemplate->addBcc($email); + $emailInfo->addBcc($email); } } - + $mailer->addEmailInfo($emailInfo); } + // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { foreach ($copyTo as $email) { - $sendTo[] = array( - 'name' => null, - 'email' => $email - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($email); + $mailer->addEmailInfo($emailInfo); } } - foreach ($sendTo as $recipient) { - $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId())) - ->sendTransactional( - $template, - Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $order->getStoreId()), - $recipient['email'], - $recipient['name'], - array( - 'order' => $order, - 'billing'=> $order->getBillingAddress(), - 'invoice'=> $this, - 'comment'=> $comment - ) - ); - } - - $translate->setTranslateInline(true); - - Mage::getDesign()->setAllGetOld($currentDesign); + // Set all required params and send emails + $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $storeId)); + $mailer->setStoreId($storeId); + $mailer->setTemplateId($templateId); + $mailer->setTemplateParams(array( + 'order' => $order, + 'invoice' => $this, + 'comment' => $comment, + 'billing' => $order->getBillingAddress() + ) + ); + $mailer->send(); return $this; } diff --git a/app/code/core/Mage/Sales/Model/Order/Item.php b/app/code/core/Mage/Sales/Model/Order/Item.php index b84c0524b3..44876973d7 100644 --- a/app/code/core/Mage/Sales/Model/Order/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Item.php @@ -550,6 +550,7 @@ public function getBuyRequest() $option = array(); } $buyRequest = new Varien_Object($option); + $buyRequest->setQty($this->getQtyOrdered() * 1); return $buyRequest; } } diff --git a/app/code/core/Mage/Sales/Model/Order/Shipment.php b/app/code/core/Mage/Sales/Model/Order/Shipment.php index dd336625b5..e20ba7b510 100644 --- a/app/code/core/Mage/Sales/Model/Order/Shipment.php +++ b/app/code/core/Mage/Sales/Model/Order/Shipment.php @@ -323,172 +323,161 @@ public function getCommentsCollection($reload=false) } /** - * Sending email with Invoice data + * Send email with shipment data * - * @return Mage_Sales_Model_Order_Invoice + * @param boolean $notifyCustomer + * @param string $comment + * @return Mage_Sales_Model_Order_Shipment */ - public function sendEmail($notifyCustomer=true, $comment='') + public function sendEmail($notifyCustomer = true, $comment = '') { - if (!Mage::helper('sales')->canSendNewShipmentEmail($this->getOrder()->getStore()->getId())) { + $order = $this->getOrder(); + $storeId = $order->getStore()->getId(); + + if (!Mage::helper('sales')->canSendNewShipmentEmail($storeId)) { return $this; } - - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); - - $order = $this->getOrder(); + // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO); - $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $this->getStoreId()); - + $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId); + // Check if at least one recepient is found if (!$notifyCustomer && !$copyTo) { return $this; } - $currentDesign = Mage::getDesign()->setAllGetOld(array( - 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), - 'store' => $this->getStoreId() - )); + // Start store emulation process + $appEmulation = Mage::getSingleton('core/app_emulation'); + $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId); - $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment()) - ->setIsSecureMode(true); - $paymentBlock->getMethod()->setStore($order->getStore()->getId()); + try { + // Retrieve specified view block from appropriate design package (depends on emulated store) + $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment()) + ->setIsSecureMode(true); + $paymentBlock->getMethod()->setStore($storeId); + $paymentBlockHtml = $paymentBlock->toHtml(); + } catch (Exception $exception) { + // Stop store emulation process + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + throw $exception; + } - $mailTemplate = Mage::getModel('core/email_template'); + // Stop store emulation process + $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + // Retrieve corresponding email template id and customer name if ($order->getCustomerIsGuest()) { - $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId); $customerName = $order->getBillingAddress()->getName(); } else { - $template = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId); $customerName = $order->getCustomerName(); } + $mailer = Mage::getModel('core/email_template_mailer'); if ($notifyCustomer) { - $sendTo[] = array( - 'name' => $customerName, - 'email' => $order->getCustomerEmail() - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($order->getCustomerEmail(), $customerName); if ($copyTo && $copyMethod == 'bcc') { + // Add bcc to customer email foreach ($copyTo as $email) { - $mailTemplate->addBcc($email); + $emailInfo->addBcc($email); } } - + $mailer->addEmailInfo($emailInfo); } + // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { foreach ($copyTo as $email) { - $sendTo[] = array( - 'name' => null, - 'email' => $email - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($email); + $mailer->addEmailInfo($emailInfo); } } - foreach ($sendTo as $recipient) { - $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId())) - ->sendTransactional( - $template, - Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $order->getStoreId()), - $recipient['email'], - $recipient['name'], - array( - 'order' => $order, - 'shipment' => $this, - 'comment' => $comment, - 'billing' => $order->getBillingAddress(), - 'payment_html'=> $paymentBlock->toHtml(), - ) - ); - } - - $translate->setTranslateInline(true); - - Mage::getDesign()->setAllGetOld($currentDesign); + // Set all required params and send emails + $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId)); + $mailer->setStoreId($storeId); + $mailer->setTemplateId($templateId); + $mailer->setTemplateParams(array( + 'order' => $order, + 'shipment' => $this, + 'comment' => $comment, + 'billing' => $order->getBillingAddress(), + 'payment_html' => $paymentBlockHtml + ) + ); + $mailer->send(); return $this; } /** - * Sending email with Shipment update information + * Send email with shipment update information * + * @param boolean $notifyCustomer + * @param string $comment * @return Mage_Sales_Model_Order_Shipment */ - public function sendUpdateEmail($notifyCustomer = true, $comment='') + public function sendUpdateEmail($notifyCustomer = true, $comment = '') { - if (!Mage::helper('sales')->canSendShipmentCommentEmail($this->getOrder()->getStore()->getId())) { + $order = $this->getOrder(); + $storeId = $order->getStore()->getId(); + + if (!Mage::helper('sales')->canSendShipmentCommentEmail($storeId)) { return $this; } - - $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ - $translate->setTranslateInline(false); - - $order = $this->getOrder(); - + // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO); - $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $this->getStoreId()); - + $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $storeId); + // Check if at least one recepient is found if (!$notifyCustomer && !$copyTo) { return $this; } - $currentDesign = Mage::getDesign()->setAllGetOld(array( - 'package' => Mage::getStoreConfig('design/package/name', $this->getStoreId()), - )); - - $mailTemplate = Mage::getModel('core/email_template'); - + // Retrieve corresponding email template id and customer name if ($order->getCustomerIsGuest()) { - $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $storeId); $customerName = $order->getBillingAddress()->getName(); } else { - $template = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $order->getStoreId()); + $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $storeId); $customerName = $order->getCustomerName(); } + $mailer = Mage::getModel('core/email_template_mailer'); if ($notifyCustomer) { - $sendTo[] = array( - 'name' => $customerName, - 'email' => $order->getCustomerEmail() - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($order->getCustomerEmail(), $customerName); if ($copyTo && $copyMethod == 'bcc') { + // Add bcc to customer email foreach ($copyTo as $email) { - $mailTemplate->addBcc($email); + $emailInfo->addBcc($email); } } - + $mailer->addEmailInfo($emailInfo); } + // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { foreach ($copyTo as $email) { - $sendTo[] = array( - 'name' => null, - 'email' => $email - ); + $emailInfo = Mage::getModel('core/email_info'); + $emailInfo->addTo($email); + $mailer->addEmailInfo($emailInfo); } } - foreach ($sendTo as $recipient) { - $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId())) - ->sendTransactional( - $template, - Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $order->getStoreId()), - $recipient['email'], - $recipient['name'], - array( - 'order' => $order, - 'billing' => $order->getBillingAddress(), - 'shipment'=> $this, - 'comment' => $comment - ) - ); - } - - $translate->setTranslateInline(true); - - Mage::getDesign()->setAllGetOld($currentDesign); + // Set all required params and send emails + $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $storeId)); + $mailer->setStoreId($storeId); + $mailer->setTemplateId($templateId); + $mailer->setTemplateParams(array( + 'order' => $order, + 'shipment' => $this, + 'comment' => $comment, + 'billing' => $order->getBillingAddress() + ) + ); + $mailer->send(); return $this; } diff --git a/app/code/core/Mage/Sales/Model/Quote.php b/app/code/core/Mage/Sales/Model/Quote.php index 3e7c772985..6c3073816b 100644 --- a/app/code/core/Mage/Sales/Model/Quote.php +++ b/app/code/core/Mage/Sales/Model/Quote.php @@ -254,7 +254,7 @@ public function loadByIdWithoutStore($quoteId) $this->_afterLoad(); return $this; } - + /** * Assign customer model object data to quote * @@ -815,6 +815,7 @@ public function addProduct(Mage_Catalog_Model_Product $product, $request = null) */ protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty = 1) { + $newItem = false; $item = $this->getItemByProduct($product); if (!$item) { $item = Mage::getModel('sales/quote_item'); @@ -825,6 +826,7 @@ protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty else { $item->setStoreId(Mage::app()->getStore()->getId()); } + $newItem = true; } /** @@ -837,8 +839,10 @@ protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty $item->setOptions($product->getCustomOptions()) ->setProduct($product); - - $this->addItem($item); + // Add only item that is not in quote already (there can be other new or already saved item + if ($newItem) { + $this->addItem($item); + } return $item; } diff --git a/app/code/core/Mage/Sales/Model/Quote/Item.php b/app/code/core/Mage/Sales/Model/Quote/Item.php index 63fa318d1d..f756776754 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item.php @@ -662,8 +662,8 @@ public function getBuyRequest() $buyRequest = new Varien_Object($option ? unserialize($option->getValue()) : null); // Overwrite standard buy request qty, because item qty could have changed since adding to quote - $buyRequest->setOriginalQty($buyRequest); - $buyRequest->setQty($this->getQty()); + $buyRequest->setOriginalQty($buyRequest->getQty()) + ->setQty($this->getQty() * 1); return $buyRequest; } diff --git a/app/code/core/Mage/Sales/Model/Service/Order.php b/app/code/core/Mage/Sales/Model/Service/Order.php index 61dd04bed1..13fb1a5630 100644 --- a/app/code/core/Mage/Sales/Model/Service/Order.php +++ b/app/code/core/Mage/Sales/Model/Service/Order.php @@ -201,9 +201,37 @@ public function prepareInvoiceCreditmemo($invoice, $data = array()) $qtys = isset($data['qtys']) ? $data['qtys'] : array(); $creditmemo = $this->_convertor->toCreditmemo($this->_order); $creditmemo->setInvoice($invoice); + + $invoiceQtysRefunded = array(); + foreach($invoice->getOrder()->getCreditmemosCollection() as $createdCreditmemo) { + if ($createdCreditmemo->getState() != Mage_Sales_Model_Order_Creditmemo::STATE_CANCELED + && $createdCreditmemo->getInvoiceId() == $invoice->getId()) { + foreach($createdCreditmemo->getAllItems() as $createdCreditmemoItem) { + $orderItemId = $createdCreditmemoItem->getOrderItem()->getId(); + if (isset($invoiceQtysRefunded[$orderItemId])) { + $invoiceQtysRefunded[$orderItemId] += $createdCreditmemoItem->getQty(); + } else { + $invoiceQtysRefunded[$orderItemId] = $createdCreditmemoItem->getQty(); + } + } + } + } + + $invoiceQtysRefundLimits = array(); + foreach($invoice->getAllItems() as $invoiceItem) { + $invoiceQtyCanBeRefunded = $invoiceItem->getQty(); + $orderItemId = $invoiceItem->getOrderItem()->getId(); + if (isset($invoiceQtysRefunded[$orderItemId])) { + $invoiceQtyCanBeRefunded = $invoiceQtyCanBeRefunded - $invoiceQtysRefunded[$orderItemId]; + } + $invoiceQtysRefundLimits[$orderItemId] = $invoiceQtyCanBeRefunded; + } + + foreach ($invoice->getAllItems() as $invoiceItem) { $orderItem = $invoiceItem->getOrderItem(); - if (!$this->_canRefundItem($orderItem, $qtys)) { + + if (!$this->_canRefundItem($orderItem, $qtys, $invoiceQtysRefundLimits)) { continue; } @@ -218,6 +246,9 @@ public function prepareInvoiceCreditmemo($invoice, $data = array()) } else { continue; } + if (isset($invoiceQtysRefundLimits[$orderItem->getId()])) { + $qty = min($qty, $invoiceQtysRefundLimits[$orderItem->getId()]); + } } $qty = min($qty, $invoiceItem->getQty()); $totalQty += $qty; @@ -357,15 +388,16 @@ protected function _canShipItem($item, $qtys=array()) * * @param Mage_Sales_Model_Order_Item $item * @param array $qtys + * @param array $invoiceQtysRefundLimits * @return bool */ - protected function _canRefundItem($item, $qtys=array()) + protected function _canRefundItem($item, $qtys=array(), $invoiceQtysRefundLimits=array()) { if ($item->isDummy()) { if ($item->getHasChildren()) { foreach ($item->getChildrenItems() as $child) { if (empty($qtys)) { - if ($child->getQtyToRefund()>0) { + if ($this->_canRefundNoDummyItem($child, $invoiceQtysRefundLimits)) { return true; } } else { @@ -378,13 +410,34 @@ protected function _canRefundItem($item, $qtys=array()) } else if($item->getParentItem()) { $parent = $item->getParentItem(); if (empty($qtys)) { - return $parent->getQtyToRefund()>0; + return $this->_canRefundNoDummyItem($parent, $invoiceQtysRefundLimits); } else { return isset($qtys[$parent->getId()]) && $qtys[$parent->getId()] > 0; } } } else { - return $item->getQtyToRefund()>0; + return $this->_canRefundNoDummyItem($item, $invoiceQtysRefundLimits); } } + + /** + * Check if no dummy order item can be refunded + * + * @param Mage_Sales_Model_Order_Item $item + * @param array $invoiceQtysRefundLimits + * @return bool + */ + protected function _canRefundNoDummyItem($item, $invoiceQtysRefundLimits=array()) + { + if ($item->getQtyToRefund() < 0) { + return false; + } + + if (isset($invoiceQtysRefundLimits[$item->getId()])) { + return $invoiceQtysRefundLimits[$item->getId()] > 0; + } + + return true; + } + } diff --git a/app/code/core/Mage/Sales/etc/config.xml b/app/code/core/Mage/Sales/etc/config.xml index e045e03fc8..c38a085a37 100644 --- a/app/code/core/Mage/Sales/etc/config.xml +++ b/app/code/core/Mage/Sales/etc/config.xml @@ -28,7 +28,7 @@ - 1.4.0.23 + 1.4.0.24 diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.23-1.4.0.24.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.23-1.4.0.24.php new file mode 100644 index 0000000000..674531c768 --- /dev/null +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.23-1.4.0.24.php @@ -0,0 +1,30 @@ +getConnection()->addColumn($installer->getTable('sales_flat_invoice'), + 'base_total_refunded', 'decimal(12,4) default NULL'); diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php index 1a4dfe1f05..8acd4a6d75 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php @@ -72,6 +72,11 @@ public function loadAttributeOptions() return $this; } + public function loadValueOptions() + { + return $this; + } + public function loadOperatorOptions() { $this->setOperatorOption(array( diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Report/Tax.php b/app/code/core/Mage/Tax/Model/Mysql4/Report/Tax.php index cda3bb52c9..f7fa141d42 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Report/Tax.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Report/Tax.php @@ -68,7 +68,7 @@ public function aggregate($from = null, $to = null) 'order_status' => 'e.status', 'percent' => 'tax.percent', 'orders_count' => 'COUNT(DISTINCT(e.entity_id))', - 'tax_base_amount_sum' => 'SUM(tax.base_real_amount * e.base_to_global_rate)' + 'tax_base_amount_sum' => 'SUM(tax.base_amount * e.base_to_global_rate)' ); $select = $writeAdapter->select(); diff --git a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php index 8d2b243da6..5ce7acf940 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php +++ b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php @@ -117,10 +117,13 @@ public function collect(Mage_Sales_Model_Quote_Address $address) $address->getQuote()->getCustomerTaxClassId(), $this->_store ); - $this->_areTaxRequestsSimilar = $this->_calculator->compareRequests( - $this->_calculator->getRateOriginRequest($address->getQuote()->getStore()), - $request - ); + + if ($this->_config->priceIncludesTax($this->_store)) { + $this->_areTaxRequestsSimilar = $this->_calculator->compareRequests( + $this->_calculator->getRateOriginRequest($this->_store), + $request + ); + } switch ($this->_config->getAlgorithm($this->_store)) { case Mage_Tax_Model_Calculation::CALC_UNIT_BASE: diff --git a/app/code/core/Mage/Wishlist/Block/Abstract.php b/app/code/core/Mage/Wishlist/Block/Abstract.php index bb113eb511..bd26d95d89 100644 --- a/app/code/core/Mage/Wishlist/Block/Abstract.php +++ b/app/code/core/Mage/Wishlist/Block/Abstract.php @@ -354,4 +354,26 @@ public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix = ->setIdSuffix($idSuffix) ->toHtml(); } + + /** + * Retrieve URL to item Product + * + * @param Mage_Wishlist_Model_Item $item + * @param array $additional + * @return string + */ + public function getProductUrl($item, $additional = array()) + { + $buyRequest = $item->getBuyRequest(); + $product = $item->getProduct(); + if (is_object($buyRequest)) { + $config = $buyRequest->getSuperProductConfig(); + if ($config && isset($config['product_id'])) { + $product = Mage::getModel('catalog/product') + ->setStoreId(Mage::app()->getStore()->getStoreId()) + ->load($config['product_id']); + } + } + return parent::getProductUrl($product, $additional); + } } diff --git a/app/code/core/Mage/Wishlist/Model/Config.php b/app/code/core/Mage/Wishlist/Model/Config.php new file mode 100644 index 0000000000..bd0a46d684 --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Config.php @@ -0,0 +1,43 @@ +getProductAttributes(); + $attrsForWishlist = Mage::getConfig()->getNode(self::XML_PATH_PRODUCT_ATTRIBUTES)->asArray(); + + return array_merge($attrsForCatalog, array_keys($attrsForWishlist)); + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Config/Source/Summary.php b/app/code/core/Mage/Wishlist/Model/Config/Source/Summary.php index fd0bd010eb..409c64c722 100644 --- a/app/code/core/Mage/Wishlist/Model/Config/Source/Summary.php +++ b/app/code/core/Mage/Wishlist/Model/Config/Source/Summary.php @@ -19,7 +19,7 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Checkout + * @package Mage_Wishlist * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Model/Item.php b/app/code/core/Mage/Wishlist/Model/Item.php index 007183778d..d4ba631340 100644 --- a/app/code/core/Mage/Wishlist/Model/Item.php +++ b/app/code/core/Mage/Wishlist/Model/Item.php @@ -400,7 +400,8 @@ public function getBuyRequest() { $option = $this->getOptionByCode('info_buyRequest'); $buyRequest = new Varien_Object($option ? unserialize($option->getValue()) : null); - $buyRequest->setQty($this->getQty() * 1); + $buyRequest->setOriginalQty($buyRequest->getQty()) + ->setQty($this->getQty() * 1); return $buyRequest; } diff --git a/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Collection.php b/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Collection.php index 557e7c3c5c..71bd618fe4 100644 --- a/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Collection.php +++ b/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Collection.php @@ -83,13 +83,22 @@ class Mage_Wishlist_Model_Mysql4_Item_Collection extends Mage_Core_Model_Mysql4_ */ protected $_itemsQty; + /** + * Whether product name attribute value table is joined in select + * + * @var boolean + */ + protected $_isProductNameJoined = false; + /** * Initialize resource model for collection * + * @return void */ public function _construct() { $this->_init('wishlist/item'); + $this->addFilterToMap('store_id', 'main_table.store_id'); } /** @@ -108,7 +117,6 @@ protected function _afterLoad() $this->_assignProducts(); $this->resetItemsDataChanged(); - $this->getPageSize(); return $this; @@ -143,11 +151,10 @@ protected function _assignProducts() Varien_Profiler::start('WISHLIST:'.__METHOD__); $productIds = array(); foreach ($this as $item) { - $productIds[$item->getProductId()]=1; + $productIds[$item->getProductId()] = 1; } $this->_productIds = array_merge($this->_productIds, array_keys($productIds)); - $attributes = Mage::getSingleton('catalog/config')->getProductAttributes(); - + $attributes = Mage::getSingleton('wishlist/config')->getProductAttributes(); $productCollection = Mage::getModel('catalog/product')->getCollection() ->addIdFilter($this->_productIds) ->addAttributeToSelect($attributes) @@ -167,7 +174,7 @@ protected function _assignProducts() } Mage::dispatchEvent('wishlist_item_collection_products_after_load', array( - 'product_collection' => $productCollection + 'product_collection' => $productCollection )); foreach ($this as $item) { @@ -203,7 +210,6 @@ protected function _assignProducts() public function addWishlistFilter(Mage_Wishlist_Model_Wishlist $wishlist) { $this->addFieldToFilter('wishlist_id', $wishlist->getId()); - return $this; } @@ -215,11 +221,16 @@ public function addWishlistFilter(Mage_Wishlist_Model_Wishlist $wishlist) */ public function addStoreFilter($store = null) { + if (is_null($store)) { + $store = Mage::app()->getStore()->getId(); + } + if (!is_array($store)) { $store = array($store); } $this->_storeIds = $store; + $this->addFieldToFilter('store_id', $store); return $this; } @@ -303,16 +314,121 @@ public function setInStockFilter($flag = true) /** * Set add days in whishlist * + * This method appears in 1.5.0.0 in deprecated state, because: + * - we need it to make wishlist item collection interface as much as possible compatible with old + * wishlist product collection + * - this method is useless because we can calculate days in php, and don't use MySQL for it + * + * @deprecated after 1.4.2.0 * @return Mage_Wishlist_Model_Mysql4_Item_Collection */ - public function addDaysInWishlist($flag = null) + public function addDaysInWishlist() { + $this->_addDaysInWishlist = true; $this->getSelect()->columns(array('days_in_wishlist' => "(TO_DAYS('" . (substr(Mage::getSingleton('core/date')->date(), 0, -2) . '00') . "') ". "- TO_DAYS(DATE_ADD(added_at, INTERVAL " .(int) Mage::getSingleton('core/date')->getGmtOffset() . " SECOND)))")); return $this; } + /** + * Adds filter on days in wishlist + * + * $constraints may contain 'from' and 'to' indexes with number of days to look for items + * + * @param array $constraints + * @return Mage_Wishlist_Model_Mysql4_Item_Collection + */ + public function addDaysFilter($constraints) + { + if (!is_array($constraints)) { + return $this; + } + + $filter = array(); + + $now = Mage::getSingleton('core/date')->date(); + $gmtOffset = (int) Mage::getSingleton('core/date')->getGmtOffset(); + if (isset($constraints['from'])) { + $lastDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); + $lastDay->subSecond($gmtOffset) + ->subDay($constraints['from'] - 1); + $filter['to'] = $lastDay; + } + + if (isset($constraints['to'])) { + $firstDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); + $firstDay->subSecond($gmtOffset) + ->subDay($constraints['to']); + $filter['from'] = $firstDay; + } + + if ($filter) { + $filter['datetime'] = true; + $this->addFieldToFilter('added_at', $filter); + } + + return $this; + } + + /** + * Joins product name attribute value to use it in WHERE and ORDER clauses + * + * @return Mage_Wishlist_Model_Mysql4_Item_Collection + */ + protected function _joinProductNameTable() + { + if (!$this->_isProductNameJoined) { + $entityTypeId = Mage::getResourceModel('catalog/config') + ->getEntityTypeId(); + $attribute = Mage::getModel('catalog/entity_attribute') + ->loadByCode($entityTypeId, 'name'); + + $storeId = Mage::app()->getStore()->getId(); + + $this->getSelect() + ->join( + array('product_name_table' => $attribute->getBackendTable()), + 'product_name_table.entity_id=main_table.product_id' . + ' AND product_name_table.store_id=' . $storeId . + ' AND product_name_table.attribute_id=' . $attribute->getId(). + ' AND product_name_table.entity_type_id=' . $entityTypeId, + array() + ); + + $this->_isProductNameJoined = true; + } + return $this; + } + + /** + * Adds filter on product name + * + * @param string $productName + * @return Mage_Wishlist_Model_Mysql4_Item_Collection + */ + public function addProductNameFilter($productName) + { + $this->_joinProductNameTable(); + $this->getSelect() + ->where('INSTR(product_name_table.value, ?)', $productName); + + return $this; + } + + /** + * Sets ordering by product name + * + * @param string $dir + * @return Mage_Wishlist_Model_Mysql4_Item_Collection + */ + public function setOrderByProductName($dir) + { + $this->_joinProductNameTable(); + $this->getSelect()->order('product_name_table.value ' . $dir); + return $this; + } + /** * Get sum of items collection qty * diff --git a/app/code/core/Mage/Wishlist/etc/config.xml b/app/code/core/Mage/Wishlist/etc/config.xml index 192f7a1669..f0838dc179 100644 --- a/app/code/core/Mage/Wishlist/etc/config.xml +++ b/app/code/core/Mage/Wishlist/etc/config.xml @@ -92,6 +92,15 @@ + + + + + + + + + diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php index 65e9244054..ed4098ba61 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php @@ -31,8 +31,6 @@ * @package Mage_XmlConnect * @author Magento Core Team */ - - class Mage_XmlConnect_Block_Adminhtml_History extends Mage_Adminhtml_Block_Widget_Grid_Container { /** @@ -42,7 +40,7 @@ public function __construct() { $this->_blockGroup = 'xmlconnect'; $this->_controller = 'adminhtml_history'; - $this->_headerText = Mage::helper('xmlconnect')->__('App Submission History'); + $this->_headerText = $this->__('App Submission History'); parent::__construct(); $this->removeButton('add'); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php index b7c8b5d46d..b4edcb4f24 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php @@ -33,7 +33,6 @@ */ class Mage_XmlConnect_Block_Adminhtml_History_Grid extends Mage_Adminhtml_Block_Widget_Grid { - /** * Constructor * @@ -67,27 +66,33 @@ protected function _prepareCollection() protected function _prepareColumns() { $this->addColumn('title', array( - 'header' => Mage::helper('xmlconnect')->__('App Title'), + 'header' => $this->__('App Title'), 'align' => 'left', 'index' => 'title', 'type' => 'text', )); + $this->addColumn('name', array( + 'header' => $this->__('App Name'), + 'align' => 'left', + 'index' => 'name', + )); + $this->addColumn('code', array( - 'header' => Mage::helper('xmlconnect')->__('App Code'), + 'header' => $this->__('App Code'), 'align' => 'left', 'index' => 'code', )); $this->addColumn('created_at', array( - 'header' => Mage::helper('xmlconnect')->__('Date Submitted'), + 'header' => $this->__('Date Submitted'), 'align' => 'left', 'index' => 'created_at', 'type' => 'datetime' )); $this->addColumn('activation_key', array( - 'header' => Mage::helper('xmlconnect')->__('Activation Key'), + 'header' => $this->__('Activation Key'), 'align' => 'left', 'index' => 'activation_key', )); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php index 0434fd2a15..94cf1c86bb 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php @@ -24,8 +24,13 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - - +/** + * XmlConnect application grid + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile extends Mage_Adminhtml_Block_Widget_Grid_Container { /** @@ -35,10 +40,9 @@ public function __construct() { $this->_controller = 'adminhtml_mobile'; $this->_blockGroup = 'xmlconnect'; - $this->_headerText = Mage::helper('xmlconnect')->__('Manage Apps'); - $this->_addButtonLabel = Mage::helper('xmlconnect')->__('Add App'); + $this->_headerText = $this->__('Manage Apps'); + $this->_addButtonLabel = $this->__('Add App'); parent::__construct(); } - } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php index ce2041d0ca..ab0a062769 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php @@ -23,7 +23,6 @@ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit extends Mage_Adminhtml_Block_Widget_Form_Container { /** @@ -35,39 +34,54 @@ public function __construct() $this->_controller = 'adminhtml_mobile'; $this->_blockGroup = 'xmlconnect'; parent::__construct(); - $model = Mage::registry('current_app'); + $app = $this->getApplication(); - $this->_updateButton('save', 'label', Mage::helper('xmlconnect')->__('Save')); - $this->_updateButton('save', 'onclick', 'if (editForm.submit()) {disableElements(\'save\')}'); + if ((bool)!Mage::getSingleton('adminhtml/session')->getNewApplication()) { + $this->_updateButton('save', 'label', $this->__('Save')); + $this->_updateButton('save', 'onclick', 'if (editForm.submit()) {disableElements(\'save\')}'); - $this->_addButton('save_and_continue', array( - 'label' => Mage::helper('xmlconnect')->__('Save and Continue Edit'), - 'onclick' => 'saveAndContinueEdit()', - 'class' => 'save', - ), -5); + $this->_addButton('save_and_continue', array( + 'label' => $this->__('Save and Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save', + ), -5); - if (Mage::registry('current_app')->getId()) { - $this->_addButton('submit_application_button', array( - 'label' => Mage::helper('xmlconnect')->__('Save and Submit App'), - 'onclick' => 'saveAndSubmitApp()', - 'class' => 'save' - ), -10); - } + if ($app->getId()) { + $this->_addButton('submit_application_button', array( + 'label' => $this->__('Save and Submit App'), + 'onclick' => 'saveAndSubmitApp()', + 'class' => 'save' + ), -10); + } - $this->_formScripts[] = 'function saveAndContinueEdit() {' - .'if (editForm.submit($(\'edit_form\').action + \'back/edit/\')) {disableElements(\'save\')};}'; - if ($model->getId()) { - $this->_formScripts[] = 'function saveAndSubmitApp() {' - .'if (editForm.submit($(\'edit_form\').action+\'submitapp/' . $model->getId() . '\')) {' - .'disableElements(\'save\')};}'; + $this->_formScripts[] = 'function saveAndContinueEdit() {' + .'if (editForm.submit($(\'edit_form\').action + \'back/edit/\')) {disableElements(\'save\')};}'; + if ($app->getId()) { + $this->_formScripts[] = 'function saveAndSubmitApp() {' + .'if (editForm.submit($(\'edit_form\').action+\'submitapp/' . $app->getId() . '\')) {' + .'disableElements(\'save\')};}'; + } + } else { + $this->removeButton('save'); + $this->removeButton('delete'); } - if (Mage::registry('current_app')->getIsSubmitted()) { + if (isset($app) && $app->getIsSubmitted()) { $this->removeButton('delete'); } $this->removeButton('reset'); } + /** + * Retrieve currently edited application object + * + * @return Mage_XmlConnect_Model_Application + */ + public function getApplication() + { + return Mage::registry('current_app'); + } + /** * Adding JS scripts to block * @@ -87,11 +101,11 @@ protected function _prepareLayout() */ public function getHeaderText() { - $app = Mage::registry('current_app'); + $app = $this->getApplication(); if ($app && $app->getId()) { - return Mage::helper('xmlconnect')->__('Edit App "%s"', $this->htmlEscape($app->getName())); + return $this->__('Edit App "%s"', $this->htmlEscape($app->getName())); } else { - return Mage::helper('xmlconnect')->__('New App'); + return $this->__('New App'); } } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php index 4af1501076..03a4f7d415 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php @@ -25,7 +25,6 @@ */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Form extends Mage_Adminhtml_Block_Widget_Form { - /** * Prepare form before rendering HTML * Setting Form Fieldsets and fields @@ -34,7 +33,12 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Form extends Mage_Adminhtml_Bl */ protected function _prepareForm() { - $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getUrl('*/mobile/save'), 'method' => 'post', 'enctype' => 'multipart/form-data')); + $form = new Varien_Data_Form(array('id' => 'edit_form', + 'action' => Mage::getSingleton('adminhtml/session')->getNewApplication() + ? $this->getUrl('*/mobile/edit', array('_current' => true)) : $this->getUrl('*/mobile/save'), + 'method' => 'post', + 'enctype' => 'multipart/form-data' + )); $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php index 5813c679e3..928847adbc 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php @@ -37,5 +37,4 @@ public function __construct() $this->setId('mobile_app_submit'); $this->setDestElementId('content'); } - } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php index 7d8e63dad9..2c13ef5611 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php @@ -73,15 +73,15 @@ protected function _prepareForm() $dummy = array(array( 'value' => '', 'label' => '' )); $this->_pages = array_merge($dummy, $pages); - $fieldset = $form->addFieldset('cms_pages', array('legend' => Mage::helper('xmlconnect')->__('Pages'))); + $fieldset = $form->addFieldset('cms_pages', array('legend' => $this->__('Pages'))); $this->_addElementTypes($fieldset); $fieldset->addField('page_row_add', 'addrow', array( 'onclick' => 'insertNewTableRow(this)', 'options' => $this->_pages, 'class' => ' scalable save ', - 'label' => Mage::helper('xmlconnect')->__('Label'), - 'before_element_html' => Mage::helper('xmlconnect')->__('Get Content from CMS Page').'', + 'label' => $this->__('Label'), + 'before_element_html' => $this->__('Get Content from CMS Page').'', )); if (isset($conf['native']['pages'])) { @@ -91,7 +91,7 @@ protected function _prepareForm() } $data = $model->getFormData(); - $data['page_row_add'] = Mage::helper('xmlconnect')->__('Add Page'); + $data['page_row_add'] = $this->__('Add Page'); $form->setValues($data); return parent::_prepareForm(); } @@ -103,7 +103,7 @@ protected function _prepareForm() */ public function getTabLabel() { - return Mage::helper('xmlconnect')->__('Content'); + return $this->__('Content'); } /** @@ -113,7 +113,7 @@ public function getTabLabel() */ public function getTabTitle() { - return Mage::helper('xmlconnect')->__('Content'); + return $this->__('Content'); } /** @@ -123,7 +123,7 @@ public function getTabTitle() */ public function canShowTab() { - return true; + return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication(); } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php index 4d43ea3b5a..866f00b1cc 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php @@ -44,7 +44,7 @@ public function __construct() */ public function getTabLabel() { - return Mage::helper('xmlconnect')->__('Design'); + return $this->__('Design'); } /** @@ -54,7 +54,7 @@ public function getTabLabel() */ public function getTabTitle() { - return Mage::helper('xmlconnect')->__('Design'); + return $this->__('Design'); } /** @@ -64,7 +64,7 @@ public function getTabTitle() */ public function canShowTab() { - return true; + return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication(); } /** @@ -76,4 +76,14 @@ public function isHidden() { return false; } + + /** + * Check if we have to show Preview Block + * + * @return bool + */ + public function canShowPreview() + { + return true; + } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php index 4af6291d69..bc94a6e918 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php @@ -32,7 +32,7 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Images ex */ public function getTitle() { - return Mage::helper('xmlconnect')->__('Images'); + return $this->__('Images'); } /** @@ -48,6 +48,7 @@ public function getIsOpen() /** * Prepare form * + * @throws Mage_Core_Exception * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form */ protected function _prepareForm() @@ -58,25 +59,73 @@ protected function _prepareForm() $this->_addElementTypes($fieldset); $this->addImage($fieldset, 'conf[native][navigationBar][icon]', - Mage::helper('xmlconnect')->__('Logo in Header'), - Mage::helper('xmlconnect')->__('Recommended size 35px x 35px.'), + $this->__('Logo in Header'), + $this->__('Recommended size 35px x 35px.'), $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/navigationBar/icon')), true ); - $this->addImage($fieldset, - 'conf[native][body][bannerImage]', - Mage::helper('xmlconnect')->__('Banner on Home Screen'), - Mage::helper('xmlconnect')->__('Recommended size 320px x 230px. Note: Image size affects the performance of your app. Keep your image size below 50 KB for optimal performance.'), - $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/bannerImage')), - true - ); - $this->addImage($fieldset, - 'conf[native][body][backgroundImage]', - Mage::helper('xmlconnect')->__('App Background'), - Mage::helper('xmlconnect')->__('Recommended size 320px x 367px. Note: Image size affects the performance of your app. Keep your image size below 75 KB for optimal performance.'), - $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/backgroundImage')), - true - ); + + $deviceType = Mage::helper('xmlconnect')->getApplication()->getType(); + switch ($deviceType) { + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE: + $this->addImage($fieldset, + 'conf[native][body][bannerImage]', + $this->__('Banner on Home Screen'), + $this->__('Recommended size 320px x 230px. Note: Image size affects the performance of your app. Keep your image size below 50 KB for optimal performance.'), + $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/bannerImage')), + true + ); + $this->addImage($fieldset, + 'conf[native][body][backgroundImage]', + $this->__('App Background'), + $this->__('Recommended size 320px x 367px. Note: Image size affects the performance of your app. Keep your image size below 75 KB for optimal performance.'), + $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/backgroundImage')), + true + ); + break; + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD: + $this->addImage($fieldset, + 'conf[native][body][bannerImageIpad]', + $this->__('Banner on Home Screen'), + $this->__('Recommended size 768px x 294px. Note: Image size affects the performance of your app.'), + $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/bannerImageIpad')), + true + ); + $this->addImage($fieldset, + 'conf[native][body][backgroundImageIpadLandscape]', + $this->__('App Background (landscape mode)'), + $this->__('Recommended size 1024px x 704px. Note: Image size affects the performance of your app.'), + $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/backgroundImageIpadLandscape')), + true + ); + $this->addImage($fieldset, + 'conf[native][body][backgroundImageIpadPortret]', + $this->__('App Background (portrait mode)'), + $this->__('Recommended size 768px x 960px. Note: Image size affects the performance of your app.'), + $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/backgroundImageIpadPortret')), + true + ); + break; + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID: + $this->addImage($fieldset, + 'conf[native][body][bannerImageAndroid]', + $this->__('Banner on Home Screen'), + $this->__('Recommended size 320px x 258px. Note: Image size affects the performance of your app. Keep your image size below 50 KB for optimal performance.'), + $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/bannerImageAndroid')), + true + ); + $this->addImage($fieldset, + 'conf[native][body][backgroundImageAndroid]', + $this->__('App Background'), + $this->__('Recommended size 320px x 455px. Note: Image size affects the performance of your app. Keep your image size below 75 KB for optimal performance.'), + $this->_getDesignPreviewImageUrl(Mage::helper('xmlconnect/image')->getInterfaceImagesPaths('conf/native/body/backgroundImageAndroid')), + true + ); + break; + default: + Mage::throwException($this->__('Device doesn\'t recognized: "%s". Unable to load a helper.', $deviceType)); + break; + } $form->setValues($this->getApplication()->getFormData()); $this->setForm($form); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php index 19dc140666..0970b2cbfe 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php @@ -32,7 +32,12 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Tabs exte */ public function getTitle() { - return Mage::helper('xmlconnect')->__('Tabs'); + if (Mage::helper('xmlconnect')->getApplication()->getType() == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD) { + $title = $this->__('Extensions'); + } else { + $title = $this->__('Tabs'); + } + return $title; } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php index 3e307e1106..36c3eb76f7 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php @@ -32,7 +32,7 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Themes ex */ public function getTitle() { - return Mage::helper('xmlconnect')->__('Color Themes'); + return $this->__('Color Themes'); } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php index 88b768a51c..34079a0e48 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php @@ -31,7 +31,15 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Preview extends Mag public function __construct() { parent::__construct(); - $this->setTemplate('xmlconnect/edit/tab/design/preview.phtml'); + + $device = Mage::helper('xmlconnect')->getApplication()->getType(); + if (array_key_exists($device, Mage::helper('xmlconnect')->getSupportedDevices())) { + $template = 'xmlconnect/edit/tab/design/preview_' . strtolower($device) . '.phtml'; + } else { + Mage::throwException($this->__('Device doesn\'t recognized. Unable to load a template.')); + } + + $this->setTemplate($template); } /** @@ -42,6 +50,16 @@ public function __construct() */ public function getPreviewActionUrl($page = 'home') { - return $this->getUrl('*/*/preview' . $page, array('application_id' => Mage::registry('current_app')->getId())); + $params = array(); + $model = Mage::registry('current_app'); + if ($model !== null) { + if ($model->getId() !== null) { + $params = array('application_id' => $model->getId()); + } else { + $params = array('devtype' => $model->getDevtype()); + } + + } + return $this->getUrl('*/*/preview' . $page, $params); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php index 9724ca5279..010d21b343 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php @@ -38,23 +38,23 @@ public function __construct() $data = $model->getFormData(); $this->setColorFieldset (array ( - array ( 'id' => 'field_colors', 'label' => Mage::helper('xmlconnect')->__('Colors'), 'fields' => array ( - $this->_addColorBox('conf[native][navigationBar][tintColor]', Mage::helper('xmlconnect')->__('Header Background Color'), $data), - $this->_addColorBox('conf[native][body][primaryColor]', Mage::helper('xmlconnect')->__('Primary Color'), $data), - $this->_addColorBox('conf[native][body][secondaryColor]', Mage::helper('xmlconnect')->__('Secondary Color'), $data), - $this->_addColorBox('conf[native][categoryItem][backgroundColor]', Mage::helper('xmlconnect')->__('Category Item Background Color'), $data), - $this->_addColorBox('conf[native][categoryItem][tintColor]', Mage::helper('xmlconnect')->__('Category Button Color'), $data), + array ( 'id' => 'field_colors', 'label' => $this->__('Colors'), 'fields' => array ( + $this->_addColorBox('conf[native][navigationBar][tintColor]', $this->__('Header Background Color'), $data), + $this->_addColorBox('conf[native][body][primaryColor]', $this->__('Primary Color'), $data), + $this->_addColorBox('conf[native][body][secondaryColor]', $this->__('Secondary Color'), $data), + $this->_addColorBox('conf[native][categoryItem][backgroundColor]', $this->__('Category Item Background Color'), $data), + $this->_addColorBox('conf[native][categoryItem][tintColor]', $this->__('Category Button Color'), $data), )), - array ( 'id' => 'field_fonts', 'label' => Mage::helper('xmlconnect')->__('Fonts'), 'fields' => array ( - $this->_addColorBox('conf[extra][fontColors][header]', Mage::helper('xmlconnect')->__('Header Font Color'), $data), - $this->_addColorBox('conf[extra][fontColors][primary]', Mage::helper('xmlconnect')->__('Primary Font Color'), $data), - $this->_addColorBox('conf[extra][fontColors][secondary]', Mage::helper('xmlconnect')->__('Secondary Font Color'), $data), - $this->_addColorBox('conf[extra][fontColors][price]', Mage::helper('xmlconnect')->__('Price Font Color'), $data), + array ( 'id' => 'field_fonts', 'label' => $this->__('Fonts'), 'fields' => array ( + $this->_addColorBox('conf[extra][fontColors][header]', $this->__('Header Font Color'), $data), + $this->_addColorBox('conf[extra][fontColors][primary]', $this->__('Primary Font Color'), $data), + $this->_addColorBox('conf[extra][fontColors][secondary]', $this->__('Secondary Font Color'), $data), + $this->_addColorBox('conf[extra][fontColors][price]', $this->__('Price Font Color'), $data), )), - array ( 'id' => 'field_advanced', 'label' => Mage::helper('xmlconnect')->__('Advanced Settings'), 'fields' => array ( - $this->_addColorBox('conf[native][body][backgroundColor]', Mage::helper('xmlconnect')->__('Background Color'), $data), - $this->_addColorBox('conf[native][body][scrollBackgroundColor]', Mage::helper('xmlconnect')->__('Scroll Background Color'), $data), - $this->_addColorBox('conf[native][itemActions][relatedProductBackgroundColor]', Mage::helper('xmlconnect')->__('Related Product Background Color'), $data), + array ( 'id' => 'field_advanced', 'label' => $this->__('Advanced Settings'), 'fields' => array ( + $this->_addColorBox('conf[native][body][backgroundColor]', $this->__('Background Color'), $data), + $this->_addColorBox('conf[native][body][scrollBackgroundColor]', $this->__('Scroll Background Color'), $data), + $this->_addColorBox('conf[native][itemActions][relatedProductBackgroundColor]', $this->__('Related Product Background Color'), $data), )), )); } @@ -140,7 +140,7 @@ public function getApplication() { $model = Mage::registry('current_app'); if (!($model instanceof Mage_XmlConnect_Model_Application)) { - Mage::throwException(Mage::helper('xmlconnect')->__('App model not loaded.')); + Mage::throwException($this->__('App model not loaded.')); } return $model; diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php new file mode 100755 index 0000000000..9d940a6034 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php @@ -0,0 +1,140 @@ +setShowGlobalIcon(true); + } + + /** + * Prepare form before rendering HTML + * Setting Form Fieldsets and fields + * + * @return Mage_Adminhtml_Block_Widget_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + + $this->setForm($form); + + $data = $this->getApplication()->getFormData(); + $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); + + $fieldset = $form->addFieldset('flurryAnalytics', array('legend' => $this->__('Flurry Analytics'))); + + $enabled = $fieldset->addField('conf/native/merchantFlurryTracking/isActive', 'select', array( + 'label' => $this->__('Enable Flurry Analytics'), + 'name' => 'conf[native][merchantFlurryTracking][isActive]', + 'values' => $yesNoValues, + 'note' => $this->__('Enable Flurry Analytics for the merchant.'), + 'value' => (isset($data['conf[native][merchantFlurryTracking][isActive]']) ? $data['conf[native][merchantFlurryTracking][isActive]'] : '0') + )); + + $flurryAnalyticsUrl = $this->escapeHtml(Mage::getStoreConfig('xmlconnect/flurry_analytics/statistics_url')); + + $flurryLink = $fieldset->addField('flurry_analytics_link', 'link', array( + 'title' => $this->__('Flurry Analytics Site'), + 'label' => $this->__('Flurry Analytics Site'), + 'value' => $flurryAnalyticsUrl, + 'href' => $flurryAnalyticsUrl, + 'target' => '__blank', + 'note' => $this->__('You can watch statistics here.'), + )); + + $flurryApiCode = $fieldset->addField('conf/native/merchantFlurryTracking/accountId', 'text', array( + 'label' => $this->__('Flurry Api Code'), + 'name' => 'conf[native][merchantFlurryTracking][accountId]', + 'enabled' => true, + 'required' => true, + 'value' => (isset($data['conf[native][merchantFlurryTracking][accountId]']) ? $data['conf[native][merchantFlurryTracking][accountId]'] : '') + )); + + // field dependencies + $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence') + ->addFieldMap($flurryApiCode->getHtmlId(), $flurryApiCode->getName()) + ->addFieldMap($enabled->getHtmlId(), $enabled->getName()) + ->addFieldDependence( + $flurryApiCode->getName(), + $enabled->getName(), + 1) + ); + + return parent::_prepareForm(); + } + + /** + * Tab label getter + * + * @return string + */ + public function getTabLabel() + { + return $this->__('Analytics'); + } + + /** + * Tab title getter + * + * @return string + */ + public function getTabTitle() + { + return $this->__('Flurry Analytics'); + } + + /** + * Check if tab can be shown + * + * @return bool + */ + public function canShowTab() + { + return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication() + && $this->getApplication()->getType() == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE; + } + + /** + * Check if tab hidden + * + * @return bool + */ + public function isHidden() + { + return false; + } +} + diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php index 3a7e3f83ae..2a1ca9b40f 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php @@ -38,7 +38,7 @@ protected function _prepareForm() $form = new Varien_Data_Form(); $form->setHtmlIdPrefix('app_'); - $fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('xmlconnect')->__('App Information'))); + $fieldset = $form->addFieldset('base_fieldset', array('legend' => $this->__('App Information'))); if ($model->getId()) { $fieldset->addField('application_id', 'hidden', array( @@ -48,15 +48,16 @@ protected function _prepareForm() $fieldset->addField('name', 'text', array( 'name' => 'name', - 'label' => Mage::helper('xmlconnect')->__('App Name'), - 'title' => Mage::helper('xmlconnect')->__('App Name'), + 'label' => $this->__('App Name'), + 'title' => $this->__('App Name'), + 'maxlength' => '250', 'required' => true, )); if ($model->getId()) { $field = $fieldset->addField('code', 'label', array( - 'label' => Mage::helper('xmlconnect')->__('App Code'), - 'title' => Mage::helper('xmlconnect')->__('App Code'), + 'label' => $this->__('App Code'), + 'title' => $this->__('App Code'), )); } @@ -66,8 +67,8 @@ protected function _prepareForm() if (!Mage::app()->isSingleStoreMode()) { $storeElement = $fieldset->addField('store_id', 'select', array( 'name' => 'store_id', - 'label' => Mage::helper('xmlconnect')->__('Store View'), - 'title' => Mage::helper('xmlconnect')->__('Store View'), + 'label' => $this->__('Store View'), + 'title' => $this->__('Store View'), 'required' => true, 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(true, false), )); @@ -83,21 +84,26 @@ protected function _prepareForm() $storeElement->setDisabled(true); } - $fieldset->addField('type', 'select', array( - 'name' => 'type', - 'label' => Mage::helper('xmlconnect')->__('Device Type'), - 'title' => Mage::helper('xmlconnect')->__('Device Type'), - 'disabled' => $model->getId() ? true : false, - 'values' => Mage::helper('xmlconnect')->getDeviceTypeOptions(), + $fieldset->addField('showdev', 'select', array( + 'name' => 'showdev', + 'label' => $this->__('Device Type'), + 'title' => $this->__('Device Type'), + 'values' => array($model->getType() => $model->getDevtype()), + 'disabled' => true, + )); + + $fieldset->addField('devtype', 'hidden', array( + 'name' => 'devtype', + 'value' => $model->getDevtype(), )); $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); $fieldset->addField('browsing_mode', 'select', array( - 'label' => Mage::helper('xmlconnect')->__('Catalog Only App?'), + 'label' => $this->__('Catalog Only App?'), 'name' => 'browsing_mode', - 'note' => Mage::helper('xmlconnect')->__('A Catalog Only App will not support functions such as add to cart, add to wishlist, or login.'), - 'values' => $yesNoValues + 'note' => $this->__('A Catalog Only App will not support functions such as add to cart, add to wishlist, or login.'), + 'values' => $yesNoValues )); $form->setValues($model->getFormData()); @@ -112,7 +118,7 @@ protected function _prepareForm() */ public function getTabLabel() { - return Mage::helper('xmlconnect')->__('General'); + return $this->__('General'); } /** @@ -122,7 +128,7 @@ public function getTabLabel() */ public function getTabTitle() { - return Mage::helper('xmlconnect')->__('General'); + return $this->__('General'); } /** @@ -132,7 +138,7 @@ public function getTabTitle() */ public function canShowTab() { - return true; + return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication(); } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php new file mode 100755 index 0000000000..e87cbc9871 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php @@ -0,0 +1,177 @@ +setShowGlobalIcon(true); + } + + /** + * Prepare form before rendering HTML + * Setting Form Fieldsets and fields + * + * @return Mage_Adminhtml_Block_Widget_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + + $this->setForm($form); + + $data = $this->getApplication()->getFormData(); + + $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); + + $fieldset = $form->addFieldset('notifications', array( + 'legend' => $this->__('Urban Airship Push Notification'), + )); + + $notificationEnabled = $fieldset->addField('conf/native/notifisations/isActive', 'select', array( + 'label' => $this->__('Enable AirMail Message Push notification'), + 'name' => 'conf[native][notifications][isActive]', + 'values' => $yesNoValues, + 'value' => (isset($data['conf[native][notifications][isActive]']) ? $data['conf[native][notifications][isActive]'] : '0'), + )); + + $applicationKey = $fieldset->addField('conf/native/notifications/applicationKey', 'text', array( + 'label' => $this->__('Application Key'), + 'name' => 'conf[native][notifications][applicationKey]', + 'value' => (isset($data['conf[native][notifications][applicationKey]']) ? $data['conf[native][notifications][applicationKey]'] : ''), + 'required' => true + )); + + $applicationSecret = $fieldset->addField('conf/native/notifications/applicationSecret', 'text', array( + 'label' => $this->__('Application Secret'), + 'name' => 'conf[native][notifications][applicationSecret]', + 'value' => (isset($data['conf[native][notifications][applicationSecret]']) ? $data['conf[native][notifications][applicationSecret]'] : ''), + 'required' => true + )); + + + $applicationMasterSecret = $fieldset->addField('conf/native/notifications/applicationMasterSecret', 'text', array( + 'label' => $this->__('Application Master Secret'), + 'name' => 'conf[native][notifications][applicationMasterSecret]', + 'value' => (isset($data['conf[native][notifications][applicationMasterSecret]']) ? $data['conf[native][notifications][applicationMasterSecret]'] : ''), + 'required' => true + )); + + $mailboxTitle = $fieldset->addField('conf/native/notifications/mailboxTitle', 'text', array( + 'label' => $this->__('Mailbox title'), + 'name' => 'conf[native][notifications][mailboxTitle]', + 'value' => (isset($data['conf[native][notifications][mailboxTitle]']) ? $data['conf[native][notifications][mailboxTitle]'] : ''), + 'required' => true, + 'note' => $this->__('The Mailbox title will be shown in the More Info tab. To understand more about the title, please click here') + )); + + // field dependencies + $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence') + ->addFieldMap($applicationKey->getHtmlId(), $applicationKey->getName()) + ->addFieldMap($applicationSecret->getHtmlId(), $applicationSecret->getName()) + ->addFieldMap($applicationMasterSecret->getHtmlId(), $applicationMasterSecret->getName()) + ->addFieldMap($mailboxTitle->getHtmlId(), $mailboxTitle->getName()) + ->addFieldMap($notificationEnabled->getHtmlId(), $notificationEnabled->getName()) + ->addFieldDependence( + $applicationKey->getName(), + $notificationEnabled->getName(), + 1) + ->addFieldDependence( + $applicationSecret->getName(), + $notificationEnabled->getName(), + 1) + ->addFieldDependence( + $applicationMasterSecret->getName(), + $notificationEnabled->getName(), + 1) + ->addFieldDependence( + $mailboxTitle->getName(), + $notificationEnabled->getName(), + 1) + ); + + return parent::_prepareForm(); + } + + /** + * Tab label getter + * + * @return string + */ + public function getTabLabel() + { + return $this->__('Push Notification'); + } + + /** + * Tab title getter + * + * @return string + */ + public function getTabTitle() + { + return $this->__('Push Notification'); + } + + /** + * Check if tab can be shown + * + * @return bool + */ + public function canShowTab() + { + return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication() + && $this->getApplication()->getType() == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE; + } + + /** + * Check if tab hidden + * + * @return bool + */ + public function isHidden() + { + if (!$this->getData('conf/special/notifications_submitted')) { + return false; + } else { + return true; + } + } + + /** + * Append helper above form + * @return string + */ + protected function _toHtml() + { + return $this->getChildHtml('app_notification_helper') . parent::_toHtml(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php index 6068cfb4a0..0320858cec 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php @@ -47,7 +47,6 @@ public function __construct() */ protected function _prepareForm() { - $form = new Varien_Data_Form(); $this->setForm($form); @@ -55,13 +54,13 @@ protected function _prepareForm() $data = $this->getApplication()->getFormData(); $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); - $fieldset = $form->addFieldset('onepage_checkout', array('legend' => Mage::helper('xmlconnect')->__('Standard Checkout'))); + $fieldset = $form->addFieldset('onepage_checkout', array('legend' => $this->__('Standard Checkout'))); $fieldset->addField('conf/native/defaultCheckout/isActive', 'select', array( - 'label' => Mage::helper('xmlconnect')->__('Enable Standard Checkout'), + 'label' => $this->__('Enable Standard Checkout'), 'name' => 'conf[native][defaultCheckout][isActive]', 'values' => $yesNoValues, - 'note' => Mage::helper('xmlconnect')->__('Standard Checkout uses the checkout methods provided by Magento. Only inline payment methods are supported. (e.g PayPal Direct, Authorize.Net, etc.)'), + 'note' => $this->__('Standard Checkout uses the checkout methods provided by Magento. Only inline payment methods are supported. (e.g PayPal Direct, Authorize.Net, etc.)'), 'value' => (isset($data['conf[native][defaultCheckout][isActive]']) ? $data['conf[native][defaultCheckout][isActive]'] : '1') )); @@ -69,20 +68,20 @@ protected function _prepareForm() /** * PayPal MEP management */ - $isExpressCheckoutAvaliable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(); + $isExpressCheckoutAvaliable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null); $paypalActive = 0; if (isset($data['conf[native][paypal][isActive]'])) { $paypalActive = (int)($data['conf[native][paypal][isActive]'] && $isExpressCheckoutAvaliable); } - $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array('legend' => Mage::helper('xmlconnect')->__('PayPal Mobile Embedded Payment (MEP)'))); + $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array('legend' => $this->__('PayPal Mobile Embedded Payment (MEP)'))); - $activateMepMethodNote = Mage::helper('xmlconnect')->__('To activate PayPal MEP payment method activate Express checkout first. '); + $activateMepMethodNote = $this->__('To activate PayPal MEP payment method activate Express checkout first. '); $paypalConfigurationUrl = $this->escapeHtml($this->getUrl('adminhtml/system_config/edit', array('section' => 'paypal'))); - $businessAccountNote = Mage::helper('xmlconnect')->__('MEP is PayPal`s native checkout experience for the iPhone. You can choose to use MEP alongside standard checkout, or use it as your only checkout method for Magento mobile. PayPal MEP requires a PayPal business account', $paypalConfigurationUrl); + $businessAccountNote = $this->__('MEP is PayPal`s native checkout experience for the iPhone. You can choose to use MEP alongside standard checkout, or use it as your only checkout method for Magento mobile. PayPal MEP requires a PayPal business account', $paypalConfigurationUrl); $paypalActiveField = $fieldsetPaypal->addField('conf/native/paypal/isActive', 'select', array( - 'label' => Mage::helper('xmlconnect')->__('Activate PayPal Checkout'), + 'label' => $this->__('Activate PayPal Checkout'), 'name' => 'conf[native][paypal][isActive]', 'note' => (!$isExpressCheckoutAvaliable ? $activateMepMethodNote : $businessAccountNote), 'values' => $yesNoValues, @@ -92,8 +91,8 @@ protected function _prepareForm() $merchantlabelField = $fieldsetPaypal->addField('conf/special/merchantLabel', 'text', array( 'name' => 'conf[special][merchantLabel]', - 'label' => Mage::helper('xmlconnect')->__('Merchant Label'), - 'title' => Mage::helper('xmlconnect')->__('Merchant Label'), + 'label' => $this->__('Merchant Label'), + 'title' => $this->__('Merchant Label'), 'required' => true, 'value' => (isset($data['conf[special][merchantLabel]']) ? $data['conf[special][merchantLabel]'] : '') )); @@ -118,7 +117,7 @@ protected function _prepareForm() */ public function getTabLabel() { - return Mage::helper('xmlconnect')->__('Payment Methods'); + return $this->__('Payment Methods'); } /** @@ -128,7 +127,7 @@ public function getTabLabel() */ public function getTabTitle() { - return Mage::helper('xmlconnect')->__('Payment Methods'); + return $this->__('Payment Methods'); } /** @@ -138,7 +137,7 @@ public function getTabTitle() */ public function canShowTab() { - return true; + return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication(); } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php new file mode 100755 index 0000000000..9d299b2eab --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php @@ -0,0 +1,110 @@ +setChild('continue_button', + $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData(array( + 'label' => Mage::helper('catalog')->__('Continue'), + 'onclick' => "if (editForm.submit()) { return false }", + 'class' => 'save' + )) + ); + return parent::_prepareLayout(); + } + + /** + * Prepare form before rendering HTML + * Setting Form Fieldsets and fields + * + * @return Mage_Adminhtml_Block_Widget_Form + */ + protected function _prepareForm() + { + + $form = new Varien_Data_Form(); + $form->setHtmlIdPrefix('app_'); + $fieldset = $form->addFieldset('base_fieldset', array('legend' => $this->__('Device Information'))); + + $fieldset->addField('type', 'select', array( + 'name' => 'type', + 'label' => $this->__('Device Type'), + 'title' => $this->__('Device Type'), + 'values' => Mage::helper('xmlconnect')->getDeviceTypeOptions(), + 'required' => true + )); + + $fieldset->addField('continue_button', 'note', array( + 'text' => $this->getChildHtml('continue_button'), + )); + + $this->setForm($form); + return parent::_prepareForm(); + } + + /** + * Tab label getter + * + * @return string + */ + public function getTabLabel() + { + return $this->__('Settings'); + } + + /** + * Tab title getter + * + * @return string + */ + public function getTabTitle() + { + return $this->__('Settings'); + } + + /** + * Check if tab can be shown + * + * @return bool + */ + public function canShowTab() + { + return (bool) Mage::getSingleton('adminhtml/session')->getNewApplication(); + } + + /** + * Check if tab hidden + * + * @return bool + */ + public function isHidden() + { + return false; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php index 1980e1a9da..0bfe1f7f3d 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php @@ -34,7 +34,6 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Submission_History extends Mage_Adminhtml_Block_Widget_Grid implements Mage_Adminhtml_Block_Widget_Tab_Interface { - /** * Set order by column and order direction * Set grid ID @@ -59,7 +58,7 @@ public function __construct() */ public function getTabLabel() { - return Mage::helper('xmlconnect')->__('Submission History'); + return $this->__('Submission History'); } /** @@ -69,7 +68,7 @@ public function getTabLabel() */ public function getTabTitle() { - return Mage::helper('xmlconnect')->__('Submission History'); + return $this->__('Submission History'); } /** @@ -79,7 +78,7 @@ public function getTabTitle() */ public function canShowTab() { - return true; + return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication(); } /** @@ -114,14 +113,14 @@ protected function _prepareCollection() protected function _prepareColumns() { $this->addColumn('activation_key', array( - 'header' => Mage::helper('xmlconnect')->__('Activation Key'), + 'header' => $this->__('Activation Key'), 'align' => 'left', 'index' => 'activation_key', 'type' => 'text' )); $this->addColumn('created_at', array( - 'header' => Mage::helper('xmlconnect')->__('Date Submitted'), + 'header' => $this->__('Date Submitted'), 'align' => 'left', 'index' => 'created_at', 'type' => 'datetime' diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php index 1acec8fcc1..450df57027 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php @@ -36,6 +36,25 @@ public function __construct() parent::__construct(); $this->setId('mobile_app_tabs'); $this->setDestElementId('edit_form'); - $this->setTitle(Mage::helper('xmlconnect')->__('Manage Mobile App')); + $this->setTitle($this->__('Manage Mobile App')); + } + + /** + * Preparing global layout + * + * @return Mage_Core_Block_Abstract + */ + protected function _prepareLayout() + { + $model = Mage::registry('current_app'); + + if (Mage::getSingleton('adminhtml/session')->getNewApplication()) { + $this->addTab('set', array( + 'label' => $this->__('Settings'), + 'content' => $this->getLayout()->createBlock('xmlconnect/adminhtml_mobile_edit_tab_settings')->toHtml(), + 'active' => true + )); + } + return parent::_prepareLayout(); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php new file mode 100755 index 0000000000..2664be796f --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php @@ -0,0 +1,194 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Datetime extends Varien_Data_Form_Element_Abstract +{ + /** + * @var Zend_Date + */ + protected $_value; + + public function __construct($attributes=array()) + { + parent::__construct($attributes); + $this->setType('text'); + $this->setExtType('textfield'); + if (isset($attributes['value'])) { + $this->setValue($attributes['value']); + } + } + + /** + * If script executes on x64 system, converts large + * numeric values to timestamp limit + * + * @param int $value + * @return int + */ + protected function _toTimestamp($value) + { + $value = (int)$value; + if ($value > 3155760000) { + $value = 0; + } + return $value; + } + + /** + * Set date value + * If Zend_Date instance is provided instead of value, other params will be ignored. + * Format and locale must be compatible with Zend_Date + * + * @param mixed $value + * @param string $format + * @param string $locale + * @return Varien_Data_Form_Element_Date + */ + public function setValue($value, $format = null, $locale = null) + { + if (empty($value)) { + $this->_value = ''; + return $this; + } + if ($value instanceof Zend_Date) { + $this->_value = $value; + return $this; + } + if (preg_match('/^[0-9]+$/', $value)) { + $this->_value = new Zend_Date($this->_toTimestamp($value)); + //$this->_value = new Zend_Date((int)value); + return $this; + } + // last check, if input format was set + if (null === $format) { + $format = Varien_Date::DATETIME_INTERNAL_FORMAT; + if ($this->getInputFormat()) { + $format = $this->getInputFormat(); + } + } + // last check, if locale was set + if (null === $locale) { + if (!$locale = $this->getLocale()) { + $locale = null; + } + } + try { + $this->_value = new Zend_Date($value, $format, $locale); + } catch (Exception $e) { + $this->_value = ''; + } + return $this; + } + + /** + * Get date value as string. + * Format can be specified, or it will be taken from $this->getFormat() + * + * @param string $format (compatible with Zend_Date) + * @return string + */ + public function getValue($format = null) + { + if (empty($this->_value)) { + return ''; + } + if (null === $format) { + $format = $this->getFormat() . " " . $this->getFormatT(); + } + return $this->_value->toString($format); + } + + /** + * Get value instance, if any + * + * @return Zend_Date + */ + public function getValueInstance() + { + if (empty($this->_value)) { + return null; + } + return $this->_value; + } + + /** + * Output the input field and assign calendar instance to it. + * In order to output the date: + * - the value must be instantiated (Zend_Date) + * - output format must be set (compatible with Zend_Date) + * + * @return string + */ + public function getElementHtml() + { + $this->addClass('input-text'); + + $html = sprintf( + '' + .' ', + $this->getName(), $this->getHtmlId(), $this->_escape($this->getValue()), $this->serialize($this->getHtmlAttributes()), + $this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '') + ); + $outputFormat = $this->getFormat(); + $outputTimeFormat = $this->getFormatT(); + if (empty($outputFormat)) { + throw new Exception('Output format is not specified. Please, specify "format" key in constructor, or set it using setFormat().'); + } + $displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, false); + $displayTimeFormat = Varien_Date::convertZendToStrFtime($outputTimeFormat, false, true); + + + + $html .= sprintf(' + ', + $this->getHtmlId(), $displayFormat . " " . $displayTimeFormat, + $this->getTime() ? 'true' : 'false', $this->getHtmlId() + ); + + $html .= $this->getAfterElementHtml(); + + return $html; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php index d333b4ce22..1150df3d25 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php @@ -72,7 +72,7 @@ public function addElement(Varien_Data_Form_Element_Abstract $element, $after=fa * Getter for Label field * fetching first element as label * - * @param string $idSuffix + * @param string $idSuffix * @return string */ public function getLabelHtml($idSuffix = '') @@ -82,8 +82,7 @@ public function getLabelHtml($idSuffix = '') } /** - * Enter description here... - * gettter for second part of rendered field ("selectbox" and "delete button") + * Gettter for second part of rendered field ("selectbox" and "delete button") * fetching second element as * * @return string @@ -91,8 +90,8 @@ public function getLabelHtml($idSuffix = '') public function getElementHtml() { list($label, $element) = $this->getElements(); - return $element->toHtml() . '' . - ''; } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php index edeaae8d18..8266b6ea76 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php @@ -33,9 +33,20 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Tabs extends Varien_Da */ public function getHtml() { + if ((bool)Mage::getSingleton('adminhtml/session')->getNewApplication()) { + return ''; + } + $blockClassName = Mage::getConfig()->getBlockClassName('adminhtml/template'); $block = new $blockClassName; - $block->setTemplate('xmlconnect/form/element/app_tabs.phtml'); + $device = Mage::helper('xmlconnect')->getApplication()->getType(); + if (array_key_exists($device, Mage::helper('xmlconnect')->getSupportedDevices())) { + $template = 'xmlconnect/form/element/app_tabs_' . strtolower($device) . '.phtml'; + } else { + Mage::throwException($this->__('Device doesn\'t recognized. Unable to load a template.')); + } + + $block->setTemplate($template); $tabs = Mage::getModel('xmlconnect/tabs', $this->getValue()); $block->setTabs($tabs); $block->setName($this->getName()); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php index 2b6a26c24a..ec1bde70a5 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php @@ -56,13 +56,13 @@ protected function _prepareCollection() protected function _prepareColumns() { $this->addColumn('name', array( - 'header' => Mage::helper('xmlconnect')->__('App Name'), + 'header' => $this->__('App Name'), 'align' => 'left', 'index' => 'name', )); $this->addColumn('code', array( - 'header' => Mage::helper('xmlconnect')->__('Code'), + 'header' => $this->__('App Code'), 'align' => 'left', 'index' => 'code', 'width' => '200', @@ -70,7 +70,7 @@ protected function _prepareColumns() if (!Mage::app()->isSingleStoreMode()) { $this->addColumn('store_id', array( - 'header' => Mage::helper('xmlconnect')->__('Store View'), + 'header' => $this->__('Store View'), 'index' => 'store_id', 'type' => 'store', 'store_view' => true, @@ -80,7 +80,7 @@ protected function _prepareColumns() } $this->addColumn('type', array( - 'header' => Mage::helper('xmlconnect')->__('Device'), + 'header' => $this->__('Device'), 'type' => 'text', 'index' => 'type', 'align' => 'center', @@ -90,7 +90,7 @@ protected function _prepareColumns() )); $this->addColumn('status', array( - 'header' => Mage::helper('xmlconnect')->__('Status'), + 'header' => $this->__('Status'), 'index' => 'status', 'renderer' => 'xmlconnect/adminhtml_mobile_grid_renderer_bool', 'align' => 'center', diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php index 4966b47f5e..c23f219466 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php @@ -25,6 +25,31 @@ */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Content extends Mage_Adminhtml_Block_Template { + /** + * Category item tint color styles + * + * @var string + */ + protected $categoryItemTintColor = ''; + + /** + * Set path to template used for generating block's output. + * + * @param string $templateType + * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Content + */ + public function setTemplate($templateType) + { + $deviceType = Mage::helper('xmlconnect')->getApplication()->getType(); + + if ($deviceType == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE) { + parent::setTemplate('xmlconnect/edit/tab/design/preview/' . $templateType . '.phtml'); + } else { + parent::setTemplate('xmlconnect/edit/tab/design/preview/' . $templateType . '_' . $deviceType . '.phtml'); + } + return $this; + } + /** * Prepare config data * Implement set "conf" data as magic method @@ -39,9 +64,10 @@ public function setConf($conf) $tabs = isset($conf['tabBar']) && isset($conf['tabBar']['tabs']) ? $conf['tabBar']['tabs'] : false; if ($tabs !== false) { foreach ($tabs->getEnabledTabs() as $tab) { - $conf['tabBar'][$tab->action]['label'] = $tab->label; - $conf['tabBar'][$tab->action]['image'] = - Mage::helper('xmlconnect/image')->getSkinImagesUrl('mobile_preview/' . $tab->image); + $tab = (array) $tab; + $conf['tabBar'][$tab['action']]['label'] = $tab['label']; + $conf['tabBar'][$tab['action']]['image'] = + Mage::helper('xmlconnect/image')->getSkinImagesUrl('mobile_preview/' . $tab['image']); } } $this->setData('conf', $conf); @@ -70,6 +96,137 @@ public function getDesignPreviewImageUrl($name) return Mage::helper('xmlconnect/image')->getSkinImagesUrl('design_default/' . $name); } + /** + * Get application banner image url + * + * @throws Mage_Core_Exception + * @return string + */ + public function getBannerImage() + { + $deviceType = Mage::helper('xmlconnect')->getApplication()->getType(); + switch ($deviceType) { + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE: + + if ($this->getData('conf/body/bannerImage')) { + $bannerImage = $this->getData('conf/body/bannerImage'); + } else { + $bannerImage = $this->getDesignPreviewImageUrl( + $this->getInterfaceImagesPaths('conf/body/bannerImage') + ); + } + break; + + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD: + + $configPath = 'conf/body/bannerImageIpad'; + if ($this->getData($configPath)) { + $width = Mage_XmlConnect_Helper_Ipad::PREVIEW_BANNER_WIDTH; + $height = Mage_XmlConnect_Helper_Ipad::PREVIEW_BANNER_HEIGHT; + $bannerImage = Mage::helper('xmlconnect/image') + ->getCustomSizeImageUrl($this->_replaceConfig($configPath), $width, $height); + } else { + $bannerImage = $this->getPreviewImagesUrl('ipad/banner_image.png'); + } + break; + + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID: + + $configPath = 'conf/body/bannerImageAndroid'; + if ($this->getData($configPath)) { + $bannerImage = Mage::getBaseUrl('media') . 'xmlconnect/' + . $this->getData($configPath); + } else { + $bannerImage = $this->getDesignPreviewImageUrl( + $this->getInterfaceImagesPaths($configPath) + ); + } + break; + + default: + Mage::throwException($this->__('Device doesn\'t recognized: "%s". Unable to load a helper.', $deviceType)); + break; + } + return $bannerImage; + } + + /** + * Get Ipad background image url + * + * @param string $param type of orientation + * @throws Mage_Core_Exception + * @return string + */ + public function getIpadBackgroundImage($param) + { + $backgroundImage = ''; + switch ($param) { + case Mage_XmlConnect_Helper_Ipad::ORIENTATION_LANDSCAPE: + $configPath = 'conf/native/body/backgroundImageIpadLandscape'; + if ($this->getData($configPath)) { + $width = Mage_XmlConnect_Helper_Ipad::PREVIEW_LANDSCAPE_BACKGROUND_WIDTH; + $height = Mage_XmlConnect_Helper_Ipad::PREVIEW_LANDSCAPE_BACKGROUND_HEIGHT; + $backgroundImage = Mage::helper('xmlconnect/image') + ->getCustomSizeImageUrl($this->_replaceConfig($configPath), $width, $height); + } else { + $backgroundImage = + $this->getPreviewImagesUrl('ipad/background_home_landscape.jpg'); + } + break; + case Mage_XmlConnect_Helper_Ipad::ORIENTATION_PORTRAIT: + $configPath = 'conf/native/body/backgroundImageIpadPortret'; + $width = Mage_XmlConnect_Helper_Ipad::PREVIEW_PORTRAIT_BACKGROUND_WIDTH; + $height = Mage_XmlConnect_Helper_Ipad::PREVIEW_PORTRAIT_BACKGROUND_HEIGHT; + if ($this->getData($configPath)) { + $backgroundImage = Mage::helper('xmlconnect/image') + ->getCustomSizeImageUrl($this->_replaceConfig($configPath), $width, $height); + } else { + $backgroundImage = $this->getPreviewImagesUrl('ipad/background_portrait.jpg'); + } + break; + default: + Mage::throwException($this->__('Wrong Ipad background image orientation has been specified: "%s".', $param)); + } + return $backgroundImage; + } + + /** + * Get font info from config + * + * @param string $path + * @return string + */ + public function getConfigFontInfo($path) + { + return $this->getData('conf/fonts/' . $path); + } + + /** + * Get icon logo url + * + * @return string + */ + public function getLogoUrl() + { + $configPath = 'conf/navigationBar/icon'; + if ($this->getData($configPath)) { + return $this->getData($configPath); + } else { + return $this->getDesignPreviewImageUrl($this->getInterfaceImagesPaths($configPath)); + } + } + + /** + * Converts Data path(conf/submision/zzzz) to config path (conf/native/submission/zzzzz) + * + * @param string $configPath + * @return string + */ + protected function _replaceConfig($configPath) + { + return $configPath = preg_replace('/^conf\/(.*)$/', 'conf/native/${1}', $configPath); + } + /** * Expose function getInterfaceImagesPaths from xmlconnect/images * Converts Data path(conf/submision/zzzz) to config path (conf/native/submission/zzzzz) @@ -79,7 +236,7 @@ public function getDesignPreviewImageUrl($name) */ public function getInterfaceImagesPaths($path) { - $path = preg_replace('/^conf\/(.*)$/', 'conf/native/${1}', $path); + $path = $this->_replaceConfig($path); return Mage::helper('xmlconnect/image')->getInterfaceImagesPaths($path); } @@ -93,4 +250,54 @@ public function getPreviewCssUrl($name = '') { return Mage::getDesign()->getSkinUrl('xmlconnect/' . $name); } + + /** + * Get category item tint color styles + * + * @return string + */ + public function getCategoryItemTintColor() + { + if (!strlen($this->categoryItemTintColor)) { + $percent = .4; + $mask = 255; + + $hex = str_replace('#','',$this->getData('conf/categoryItem/tintColor')); + $hex2 = ''; + $_rgb = array(); + + $d = '[a-fA-F0-9]'; + + if (preg_match("/^($d$d)($d$d)($d$d)\$/", $hex, $rgb)) { + $_rgb = array(hexdec($rgb[1]), hexdec($rgb[2]), hexdec($rgb[3])); + } + if (preg_match("/^($d)($d)($d)$/", $hex, $rgb)) { + $_rgb = array(hexdec($rgb[1] . $rgb[1]), hexdec($rgb[2] . $rgb[2]), hexdec($rgb[3] . $rgb[3])); + } + + for ($i=0; $i<3; $i++) { + $_rgb[$i] = round($_rgb[$i] * $percent) + round($mask * (1-$percent)); + if ($_rgb[$i] > 255) { + $_rgb[$i] = 255; + } + } + + for($i=0; $i < 3; $i++) { + $hex_digit = dechex($_rgb[$i]); + if(strlen($hex_digit) == 1) { + $hex_digit = "0" . $hex_digit; + } + $hex2 .= $hex_digit; + } + if($hex && $hex2){ + // for IE + $this->categoryItemTintColor .= "filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#".$hex2."', endColorstr='#".$hex."');"; + // for webkit browsers + $this->categoryItemTintColor .= "background:-webkit-gradient(linear, left top, left bottom, from(#".$hex2."), to(#".$hex."));"; + // for firefox + $this->categoryItemTintColor .= "background:-moz-linear-gradient(top, #".$hex2.", #".$hex.");"; + } + } + return $this->categoryItemTintColor; + } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php index 489e96487c..48abca7efd 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php @@ -25,13 +25,27 @@ */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Tabitems extends Mage_Adminhtml_Block_Template { + /** + * Current active tab according preview action + * + * @var bool|string + */ + private $activeTab = false; + /** * Set preview tab items template */ public function __construct() { parent::__construct(); - $this->setTemplate('xmlconnect/edit/tab/design/preview/tab_items.phtml'); + + $deviceType = Mage::helper('xmlconnect')->getApplication()->getType(); + + if ($deviceType == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE) { + $this->setTemplate('xmlconnect/edit/tab/design/preview/tab_items.phtml'); + } else { + $this->setTemplate('xmlconnect/edit/tab/design/preview/tab_items_' . $deviceType . '.phtml'); + } } /** @@ -44,7 +58,6 @@ public function getTabItems() $items = array(); $model = Mage::registry('current_app'); $tabs = $model->getEnabledTabsArray(); - $tabLimit = (int) Mage::getStoreConfig('xmlconnect/devices/'.strtolower($model->getType()).'/tab_limit'); $showedTabs = 0; foreach ($tabs as $tab) { @@ -53,8 +66,23 @@ public function getTabItems() } $items[] = array( 'label' => Mage::helper('xmlconnect')->getTabLabel($tab->action), - 'image' => $tab->image); + 'image' => $tab->image, + 'action' => $tab->action, + 'active' => strtolower($tab->action) == strtolower($this->activeTab), + ); } return $items; } + + /** + * Set active tab + * + * @param string $tab + * @return Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Tabitems + */ + public function setActiveTab($tab) + { + $this->activeTab = $tab; + return $this; + } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php index 4d5f37a4d4..ac50416bcb 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php @@ -23,7 +23,6 @@ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission extends Mage_Adminhtml_Block_Widget_Form_Container { /** @@ -33,7 +32,6 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission extends Mage_Adminhtml_B */ public function __construct() { - $this->_objectId = 'application_id'; $this->_controller = 'adminhtml_mobile'; $this->_blockGroup = 'xmlconnect'; @@ -46,9 +44,9 @@ public function __construct() $app = Mage::registry('current_app'); if ($app && $app->getIsResubmitAction()) { - $label = Mage::helper('xmlconnect')->__('Resubmit App'); + $label = $this->__('Resubmit App'); } else { - $label = Mage::helper('xmlconnect')->__('Submit App'); + $label = $this->__('Submit App'); } $this->_addButton('submission_post', array( @@ -57,10 +55,9 @@ public function __construct() 'onclick' => "submitApplication()", )); - $this->_updateButton('back', 'label', Mage::helper('xmlconnect')->__('Back to App Edit')); + $this->_updateButton('back', 'label', $this->__('Back to App Edit')); $this->_updateButton('back', 'onclick', 'setLocation(\''. $this->getUrl('*/*/edit', array('application_id' => Mage::registry('current_app')->getId())) . '\')'); - } /** @@ -72,7 +69,7 @@ public function getHeaderText() { $app = Mage::registry('current_app'); if ($app && $app->getId()) { - return Mage::helper('xmlconnect')->__('Submit App "%s"', $this->htmlEscape($app->getName())); + return $this->__('Submit App "%s"', $this->htmlEscape($app->getName())); } return ''; } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php index a53484c75d..d25dc57337 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php @@ -44,7 +44,7 @@ public function __construct() */ public function getTabLabel() { - return Mage::helper('xmlconnect')->__('Submission'); + return $this->__('Submission'); } /** @@ -54,7 +54,7 @@ public function getTabLabel() */ public function getTabTitle() { - return Mage::helper('xmlconnect')->__('Submission'); + return $this->__('Submission'); } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php index 45e7e4aac0..661e252fd5 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php @@ -88,11 +88,11 @@ protected function _prepareForm() $formData = $this->getApplication()->getFormData(); $url = Mage::getStoreConfig('xmlconnect/mobile_application/activation_key_url'); - $afterElementHtml = Mage::helper('xmlconnect')->__('In order to submit your app, you need to first purchase a %s from MagentoCommerce', $url, Mage::helper('xmlconnect')->__('Activation Key')); - $fieldset = $form->addFieldset('submit_keys', array('legend' => Mage::helper('xmlconnect')->__('Key'))); + $afterElementHtml = $this->__('In order to submit your app, you need to first purchase a %s from MagentoCommerce', $url, $this->__('Activation Key')); + $fieldset = $form->addFieldset('submit_keys', array('legend' => $this->__('Key'))); $field = $fieldset->addField('conf[submit_text][key]', 'text', array( 'name' => 'conf[submit_text][key]', - 'label' => Mage::helper('xmlconnect')->__('Activation Key'), + 'label' => $this->__('Activation Key'), 'value' => isset($formData['conf[submit_text][key]']) ? $formData['conf[submit_text][key]'] : null, 'after_element_html' => $afterElementHtml, )); @@ -108,59 +108,60 @@ protected function _prepareForm() if ($isResubmit) { $url = Mage::getStoreConfig('xmlconnect/mobile_application/resubmission_key_url'); - $afterElementHtml = Mage::helper('xmlconnect')->__('In order to resubmit your app, you need to first purchase a %s from MagentoCommerce', $url, Mage::helper('xmlconnect')->__('Resubmission Key')); + $afterElementHtml = $this->__('In order to resubmit your app, you need to first purchase a %s from MagentoCommerce', $url, $this->__('Resubmission Key')); $fieldset->addField('conf[submit_text][resubmission_activation_key]', 'text', array( 'name' => 'conf[submit_text][resubmission_activation_key]', - 'label' => Mage::helper('xmlconnect')->__('Resubmission Key'), + 'label' => $this->__('Resubmission Key'), 'value' => isset($formData['conf[submit_text][resubmission_activation_key]']) ? $formData['conf[submit_text][resubmission_activation_key]'] : null, 'required' => true, 'after_element_html' => $afterElementHtml, )); } - $fieldset = $form->addFieldset('submit_general', array('legend' => Mage::helper('xmlconnect')->__('Submission Fields'))); + $fieldset = $form->addFieldset('submit_general', array('legend' => $this->__('Submission Fields'))); $fieldset->addField('submission_action', 'hidden', array( 'name' => 'submission_action', 'value' => '1', )); + $fieldset->addField('conf/submit_text/title', 'text', array( 'name' => 'conf[submit_text][title]', - 'label' => Mage::helper('xmlconnect')->__('Title'), - 'maxlength' => '200', + 'label' => $this->__('Title'), + 'maxlength' => $formData['type'] == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE ? '12' : '200', 'value' => isset($formData['conf[submit_text][title]']) ? $formData['conf[submit_text][title]'] : null, - 'note' => Mage::helper('xmlconnect')->__('Name that appears beneath your app when users install it to their device. We recommend choosing a name that is 10-12 characters and that your customers will recognize.'), + 'note' => $this->__('Name that appears beneath your app when users install it to their device. We recommend choosing a name that is 10-12 characters and that your customers will recognize.'), 'required' => true, )); $field = $fieldset->addField('conf/submit_text/description', 'textarea', array( 'name' => 'conf[submit_text][description]', - 'label' => Mage::helper('xmlconnect')->__('Description'), + 'label' => $this->__('Description'), 'maxlength' => '500', 'value' => isset($formData['conf[submit_text][description]']) ? $formData['conf[submit_text][description]'] : null, - 'note' => Mage::helper('xmlconnect')->__('Description that appears in the iTunes App Store. 4000 chars maximum. '), + 'note' => $this->__('Description that appears in the iTunes App Store. 4000 chars maximum. '), 'required' => true, )); $field->setRows(15); $fieldset->addField('conf/submit_text/contact_email', 'text', array( 'name' => 'conf[submit_text][email]', - 'label' => Mage::helper('xmlconnect')->__('Contact Email'), + 'label' => $this->__('Contact Email'), 'class' => 'email', 'maxlength' => '40', 'value' => isset($formData['conf[submit_text][email]']) ? $formData['conf[submit_text][email]'] : null, - 'note' => Mage::helper('xmlconnect')->__('Administrative contact for this app and for app submission issues.'), + 'note' => $this->__('Administrative contact for this app and for app submission issues.'), 'required' => true, )); $fieldset->addField('conf/submit_text/price_free_label', 'label', array( 'name' => 'conf[submit_text][price_free_label]', - 'label' => Mage::helper('xmlconnect')->__('Price'), - 'value' => Mage::helper('xmlconnect')->__('Free'), + 'label' => $this->__('Price'), + 'value' => $this->__('Free'), 'maxlength' => '40', 'checked' => 'checked', - 'note' => Mage::helper('xmlconnect')->__('Only free apps are allowed in this version.'), + 'note' => $this->__('Only free apps are allowed in this version.'), )); $fieldset->addField('conf/submit_text/price_free', 'hidden', array( @@ -171,40 +172,40 @@ protected function _prepareForm() $selected = isset($formData['conf[submit_text][country]']) ? explode(',', $formData['conf[submit_text][country]']) : null; $fieldset->addField('conf/submit_text/country', 'multiselect', array( 'name' => 'conf[submit_text][country][]', - 'label' => Mage::helper('xmlconnect')->__('Country'), + 'label' => $this->__('Country'), 'values' => Mage::helper('xmlconnect')->getCountryOptionsArray(), 'value' => $selected, - 'note' => Mage::helper('xmlconnect')->__('Make this app available in the following territories'), + 'note' => $this->__('Make this app available in the following territories'), 'required' => true, )); $fieldset->addField('conf/submit_text/copyright', 'text', array( 'name' => 'conf[submit_text][copyright]', - 'label' => Mage::helper('xmlconnect')->__('Copyright'), + 'label' => $this->__('Copyright'), 'maxlength' => '200', 'value' => isset($formData['conf[submit_text][copyright]']) ? $formData['conf[submit_text][copyright]'] : null, - 'note' => Mage::helper('xmlconnect')->__('Appears in the info section of your app (example: Copyright 2010 – Your Company, Inc.)'), + 'note' => $this->__('Appears in the info section of your app (example: Copyright 2010 – Your Company, Inc.)'), 'required' => true, )); $fieldset->addField('conf/submit_text/keywords', 'text', array( 'name' => 'conf[submit_text][keywords]', - 'label' => Mage::helper('xmlconnect')->__('Keywords'), + 'label' => $this->__('Keywords'), 'maxlength' => '100', 'value' => isset($formData['conf[submit_text][keywords]']) ? $formData['conf[submit_text][keywords]'] : null, - 'note' => Mage::helper('xmlconnect')->__('One or more keywords that describe your app. Keywords are matched to users` searches in the App Store and help return accurate search results. Separate multiple keywords with commas. 100 chars is maximum.'), + 'note' => $this->__('One or more keywords that describe your app. Keywords are matched to users` searches in the App Store and help return accurate search results. Separate multiple keywords with commas. 100 chars is maximum.'), )); - $fieldset = $form->addFieldset('submit_icons', array('legend' => Mage::helper('xmlconnect')->__('Icons'))); - $this->addImage($fieldset, 'conf/submit/icon', Mage::helper('xmlconnect')->__('Large iTunes Icon'), - Mage::helper('xmlconnect')->__('Large icon that appears in the iTunes App Store. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Required size: 512px x 512px.'), '', true); - $this->addImage($fieldset, 'conf/submit/loader_image', Mage::helper('xmlconnect')->__('Loader Splash Screen'), - Mage::helper('xmlconnect')->__('Image that appears on first screen while your app is loading. Required size: 320px x 460px.'), '', true); + $fieldset = $form->addFieldset('submit_icons', array('legend' => $this->__('Icons'))); + $this->addImage($fieldset, 'conf/submit/icon', $this->__('Large iTunes Icon'), + $this->__('Large icon that appears in the iTunes App Store. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Required size: 512px x 512px.'), '', true); + $this->addImage($fieldset, 'conf/submit/loader_image', $this->__('Loader Splash Screen'), + $this->__('Image that appears on first screen while your app is loading. Required size: 320px x 460px.'), '', true); - $this->addImage($fieldset, 'conf/submit/logo', Mage::helper('xmlconnect')->__('Custom App Icon'), - Mage::helper('xmlconnect')->__('Icon that will appear on the user’s phone after they download your app. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Recommended size: 57px x 57px at 72 dpi.'), '', true); - $this->addImage($fieldset, 'conf/submit/big_logo', Mage::helper('xmlconnect')->__('Copyright Page Logo'), - Mage::helper('xmlconnect')->__('Store logo that is displayed on copyright page of app. Preferred size: 100px x 100px.'), '', true); + $this->addImage($fieldset, 'conf/submit/logo', $this->__('Custom App Icon'), + $this->__('Icon that will appear on the user’s phone after they download your app. You do not need to apply a gradient or soft edges (this is done automatically by Apple). Recommended size: 57px x 57px at 72 dpi.'), '', true); + $this->addImage($fieldset, 'conf/submit/big_logo', $this->__('Copyright Page Logo'), + $this->__('Store logo that is displayed on copyright page of app. Preferred size: 100px x 100px.'), '', true); return parent::_prepareForm(); } @@ -216,7 +217,7 @@ protected function _prepareForm() */ public function getTabLabel() { - return Mage::helper('xmlconnect')->__('Submission'); + return $this->__('Submission'); } /** @@ -226,7 +227,7 @@ public function getTabLabel() */ public function getTabTitle() { - return Mage::helper('xmlconnect')->__('Submission'); + return $this->__('Submission'); } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php index d3961b8545..1a1b03ac2b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php @@ -35,6 +35,6 @@ public function __construct() $this->setId('mobile_app_tabs'); $this->setDestElementId('edit_form'); - $this->setTitle(Mage::helper('xmlconnect')->__('Manage Mobile App')); + $this->setTitle($this->__('Manage Mobile App')); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php index a6103b351a..a1782da08b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php @@ -74,10 +74,11 @@ public function addFont($fieldset, $fieldPrefix, $title) 'name' => $fieldPrefix, 'label' => $title, )); + $el->initFields(array( 'name' => $fieldPrefix, - 'fontNames' => Mage::helper('xmlconnect/iphone')->getFontList(), - 'fontSizes' => Mage::helper('xmlconnect/iphone')->getFontSizes(), + 'fontNames' => Mage::helper('xmlconnect')->getDeviceHelper()->getFontList(), + 'fontSizes' => Mage::helper('xmlconnect')->getDeviceHelper()->getFontSizes(), )); } @@ -97,6 +98,7 @@ protected function _getAdditionalElementTypes() 'theme' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_theme'), 'page' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_page'), 'addrow'=> $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_addrow'), + 'datetime' => $config->getBlockClassName('xmlconnect/adminhtml_mobile_form_element_datetime'), ); } @@ -109,7 +111,7 @@ public function getApplication() { $model = Mage::registry('current_app'); if (!($model instanceof Mage_XmlConnect_Model_Application)) { - Mage::throwException(Mage::helper('xmlconnect')->__('App model not loaded.')); + Mage::throwException($this->__('App model not loaded.')); } return $model; diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php new file mode 100755 index 0000000000..547b53c3c7 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php @@ -0,0 +1,48 @@ + + */ + class Mage_XmlConnect_Block_Adminhtml_Queue extends Mage_Adminhtml_Block_Widget_Grid_Container + { + /** + * Class constructor + */ + public function __construct() + { + $this->_blockGroup = 'xmlconnect'; + $this->_controller = 'adminhtml_queue'; + $this->_headerText = $this->__('AirMail Messages Queue'); + + parent::__construct(); + $this->removeButton('add'); + } + } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php new file mode 100755 index 0000000000..483a924755 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php @@ -0,0 +1,80 @@ +_objectId = 'id'; + $this->_controller = 'adminhtml_queue'; + $this->_blockGroup = 'xmlconnect'; + parent::__construct(); + + $message = Mage::registry('current_message'); + if ($message && $message->getStatus() != Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) { + $this->_removeButton('reset'); + $this->_removeButton('save'); + } else { + $this->_updateButton('save', 'label', $this->__('Queue Message')); + $this->_updateButton('save', 'onclick', 'if (editForm.submit()) {disableElements(\'save\')}'); + } + $this->_removeButton('delete'); + + $this->_updateButton('back', 'onclick', 'setLocation(\'' . $this->getBackUrl() . '\')'); + } + + /** + * Get URL for back (reset) button + * + * @return string + */ + public function getBackUrl() + { + $template = Mage::registry('current_template'); + $message = Mage::registry('current_message'); + return $message && !$message->getId() && $template && $template->getId() + ? $this->getUrl('*/*/template') + : $this->getUrl('*/*/queue'); + } + + /** + * Get header text + * + * @return string + */ + public function getHeaderText() + { + $message = Mage::registry('current_message'); + if ($message && $message->getId()) { + return $this->__('Edit AirMail Message Queue #%s', $this->htmlEscape($message->getId())); + } else { + return $this->__('New AirMail Message Queue'); + } + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php new file mode 100755 index 0000000000..a64b90e440 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php @@ -0,0 +1,137 @@ +_fieldsEnabled = $model->getStatus() == Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE ? true : false; + + parent::_prepareForm(); + + if (null !== Mage::registry('current_template')) { + $templateModel = Mage::registry('current_template'); + } else { + $templateModel = Mage::getModel('xmlconnect/template')->load($model->getTemplateId()); + } + + $fieldset = $this->getForm()->addFieldset("message_settings", array('legend' => $this->__('Message Settings')), '^'); + + if ($model->getId()) { + $fieldset->addField('message_id', 'hidden', array( + 'name' => 'message_id' + )); + } + + // set exec_time for showing accordingly to locale datetime settings + $model->setExecTime(Mage::getSingleton('core/date')->date(null, $model->getExecTime())); + + /*@var $sovereignField Varien_Data_Form_Element_Abstract */ + $sovereignField = $fieldset->addField('type', 'select', array( + 'name' => 'type', + 'values' => Mage::helper('xmlconnect')->getMessageTypeOptions(), + 'label' => $this->__('Message Type'), + 'title' => $this->__('Message Type'), + 'disabled' => !$this->_fieldsEnabled, + 'required' => true, + )); + + $fieldset->addField('exec_time', 'date', array( + 'name' => 'exec_time', + 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), + 'label' => $this->__('Start Date'), + 'time' => true, + 'title' => $this->__('Start Date'), + 'image' => $this->getSkinUrl('images/grid-cal.gif'), + 'note' => $this->__('If leave this field empty, the message will be sent immediately'), + 'disabled' => !$this->_fieldsEnabled, + 'required' => false, + )); + + $this->_addElementTypes($fieldset); + + // field dependencies + // i don't know how to not hardcoded this dependence (I mean 'airmail' message type is now used for set these dependences) + if (isset($this->_dependentFields['message_title']) || isset($this->_dependentFields['content'])) { + $dependenceBlock = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence'); + + $dependenceBlock->addFieldMap($this->_dependentFields['message_title']->getHtmlId(), $this->_dependentFields['message_title']->getName()) + ->addFieldMap($this->_dependentFields['content']->getHtmlId(), $this->_dependentFields['content']->getName()) + ->addFieldMap($sovereignField->getHtmlId(), $sovereignField->getName()); + + if (isset($this->_dependentFields['message_title']) && $this->_dependentFields['message_title']) { + $dependenceBlock->addFieldDependence( + $this->_dependentFields['message_title']->getName(), + $sovereignField->getName(), + Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL); + + if (!$this->_fieldsEnabled) { + $this->_dependentFields['message_title']->setReadonly(true, true); + } + } + + if (isset($this->_dependentFields['content']) && $this->_dependentFields['content']) { + $dependenceBlock->addFieldDependence( + $this->_dependentFields['content']->getName(), + $sovereignField->getName(), + Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL); + + if (!$this->_fieldsEnabled) { + $this->_dependentFields['content']->setReadonly(true, true); + } + } + $this->setChild('form_after', $dependenceBlock); + } + + if (!$model->getName()) { + $model->setName($templateModel->getName()); + } + if (!$model->getPushTitle()) { + $model->setPushTitle($templateModel->getPushTitle()); + } + if (!$model->getMessageTitle()) { + $model->setMessageTitle($templateModel->getMessageTitle()); + } + if (!$model->getContent()) { + $model->setContent($templateModel->getContent()); + } + if (!$model->getTemplateId()) { + $model->setTemplateId($templateModel->getId()); + } + $model->setMessageId($model->getId()); + + $this->getForm()->setAction($this->getUrl('*/*/saveMessage')); + $this->getForm()->setValues($model->getData()); + + $this->setForm($this->getForm()); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php new file mode 100755 index 0000000000..3a847290b8 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php @@ -0,0 +1,183 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid extends Mage_Adminhtml_Block_Widget_Grid +{ + + /** + * Constructor + * + * Setting grid_id, sort order and sort direction + */ + public function __construct() + { + parent::__construct(); + $this->setId('app_queue_grid'); + $this->setDefaultSort('exec_time'); + $this->setDefaultDir('DESC'); + $this->setSaveParametersInSession(true); + } + + /** + * Setting collection to show + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareCollection() + { + $collection = Mage::getModel('xmlconnect/queue')->getCollection(); + + $collection->addFieldToFilter('main_table.status', array('neq' => Mage_XmlConnect_Model_Queue::STATUS_DELETED)); + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * Configuration of grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareColumns() + { + $this->addColumn('id', array( + 'header' => $this->__('ID'), + 'align' => 'center', + 'index' => 'main_table.id', + 'width' => '40px', + 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_id' + )); + + $this->addColumn('exec_time', array( + 'header' => $this->__('Queue Date'), + 'index' => 'exec_time', + 'type' => 'datetime', + 'gmtoffset' => false, + 'default' => ' ---- ' + )); + + $this->addColumn('app_code', array( + 'header' => $this->__('Application Name'), + 'align' => 'left', + 'index' => 'main_table.app_code', + 'type' => 'options', + 'options' => Mage::helper('xmlconnect')->getApplications(), + 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_application' + )); + + $this->addColumn('name', array( + 'header' => $this->__('Template Name'), + 'align' => 'left', + 'index' => 't.name', + 'type' => 'text', + 'default' => '--- Parent template has been deleted ---', + 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_template' + )); + + $this->addColumn('push_title', array( + 'header' => $this->__('Push Title'), + 'align' => 'left', + 'index' => 'main_table.push_title', + 'type' => 'text', + 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_pushtitle' + )); + + $this->addColumn('message_title', array( + 'header' => $this->__('Message Title'), + 'align' => 'left', + 'index' => 'main_table.message_title', + 'type' => 'text', + 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_msgtitle' + )); + + $this->addColumn('status', array( + 'header' => $this->__('Status'), + 'align' => 'left', + 'index' => 'main_table.status', + 'type' => 'options', + 'width' => '50px', + 'options' => array( + Mage_XmlConnect_Model_Queue::STATUS_CANCELED => $this->__('Canceled'), + Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE => $this->__('In Queue'), + Mage_XmlConnect_Model_Queue::STATUS_COMPLETED => $this->__('Completed'), + ), + 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_status', + )); + + $this->addColumn('action', array( + 'header' => $this->__('Action'), + 'type' => 'action', + 'getter' => 'getId', + 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_action', + + 'filter' => false, + 'sortable' => false, + )); + + return parent::_prepareColumns(); + } + + /** + * Prepare mass actions + * + * @return Mage_XmlConnect_Block_Adminhtml_Queue_Grid + */ + protected function _prepareMassaction() + { + $this->setMassactionIdField('id'); + $this->getMassactionBlock()->setFormFieldName('queue'); + + $this->getMassactionBlock()->addItem('delete', array( + 'label' => $this->__('Delete'), + 'url' => $this->getUrl('*/*/massDeleteQueue'), + 'confirm' => $this->__('Are you sure you what to delete selected records?') + )); + + $this->getMassactionBlock()->addItem('cancel', array( + 'label' => $this->__('Cancel'), + 'url' => $this->getUrl('*/*/massCancelQueue'), + 'confirm' => $this->__('Are you sure you what to cancel selected records?') + )); + return $this; + } + + /** + * Configure row click url + * + * @param Mage_Catalog_Model_Queue|Varien_Object $row + * @return string + */ + public function getRowUrl($row) + { + return $this->getUrl('*/*/editQueue', array('id' => $row->getId())); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php new file mode 100755 index 0000000000..dfdbb039b9 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php @@ -0,0 +1,73 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + $actions = array( + array( + 'caption' => $this->__('Preview'), + 'url' => $this->getUrl('*/*/previewQueue', array('id' => $row->getId())), + 'popup' => true, + ), + ); + + if ($row->getStatus() == Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) { + $actions[] = array( + 'caption' => $this->__('Edit'), + 'url' => $this->getUrl('*/*/editQueue', array('id' => $row->getId())), + ); + $actions[] = array( + 'caption' => $this->__('Cancel'), + 'url' => $this->getUrl('*/*/cancelQueue', array('id' => $row->getId())), + 'confirm' => $this->__('Are you sure you whant to cancel a message?') + ); + } + + $actions[] = array( + 'caption' => $this->__('Delete'), + 'url' => $this->getUrl('*/*/deleteQueue', array('id' => $row->getId())), + 'confirm' => $this->__('Are you sure you whant to delete a message?') + ); + + $this->getColumn()->setActions($actions); + return parent::render($row); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php new file mode 100755 index 0000000000..1b27368e2c --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php @@ -0,0 +1,50 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Application extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + $str = htmlspecialchars($row->getAppName()); + if ($str == '') { + $str = ' --- '; + } + return $str; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php new file mode 100755 index 0000000000..11ae295acc --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php @@ -0,0 +1,46 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Id extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + return $row->getId(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php new file mode 100755 index 0000000000..f27cfbe5fa --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php @@ -0,0 +1,50 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Msgtitle extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + $msgTitle = $row->getMessageTitle(); + if (strlen($msgTitle) > 50) { + $msgTitle = substr($msgTitle, 0, 50) . '...'; + } + return htmlspecialchars($msgTitle); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php new file mode 100755 index 0000000000..a5d2b09b91 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php @@ -0,0 +1,47 @@ + + */ + +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Pushtitle extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + return htmlspecialchars($row->getPushTitle()); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php new file mode 100755 index 0000000000..b0ac6794c1 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php @@ -0,0 +1,69 @@ + + */ + +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Status extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + $str = ''; + if (is_numeric($row->getStatus())) { + switch ($row->getStatus()) { + case Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE: + $str = $this->__('In Queue'); + break; + case Mage_XmlConnect_Model_Queue::STATUS_CANCELED: + $str = $this->__('Cancelled'); + break; + case Mage_XmlConnect_Model_Queue::STATUS_COMPLETED: + $str = $this->__('Completed'); + break; + case Mage_XmlConnect_Model_Queue::STATUS_DELETED: + $str = $this->__('Deleted'); + break; + } + } + + if ($str === '') { + $str = $this->__('Undefined'); + } + + return htmlspecialchars($str); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php new file mode 100755 index 0000000000..920c371858 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php @@ -0,0 +1,51 @@ + + */ + +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Template extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + $str = htmlspecialchars($row->getTplName()); + if ($str == '') { + $str .= '---'; + } + return $str; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php new file mode 100755 index 0000000000..ec5a184d1e --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php @@ -0,0 +1,65 @@ + + */ + class Mage_XmlConnect_Block_Adminhtml_Template extends Mage_Adminhtml_Block_Widget_Grid_Container + { + /** + * Class constructor + */ + public function __construct() + { + $this->_blockGroup = 'xmlconnect'; + $this->_controller = 'adminhtml_template'; + $this->_headerText = $this->__('AirMail templates'); + + parent::__construct(); + $this->removeButton('add'); + } + + /** + * Prepare layout + * Add new button + * + * @return Mage_Adminhtml_Block_Widget_Grid_Container + */ + protected function _prepareLayout() + { + $this->_addButton('add_new', array( + 'label' => $this->__('Add New Template'), + 'onclick' => "setLocation('{$this->getUrl('*/*/newTemplate')}')", + 'class' => 'add' + )); + + return parent::_prepareLayout(); + } + } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php new file mode 100755 index 0000000000..229fd9a12e --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php @@ -0,0 +1,71 @@ +_objectId = 'id'; + $this->_controller = 'adminhtml_template'; + $this->_blockGroup = 'xmlconnect'; + parent::__construct(); + + $this->_updateButton('delete', 'onclick', 'deleteConfirm(\'' + . Mage::helper('adminhtml')->__('Warning: All related AirMail messages will be deteted!\n Are you sure you want to do this?') + .'\', \'' . $this->getDeleteUrl() . '\')'); + $this->_updateButton('save', 'label', $this->__('Save')); + $this->_updateButton('save', 'onclick', 'if (editForm.submit()) {disableElements(\'save\')}'); + $this->_updateButton('back', 'onclick', 'setLocation(\'' . $this->getUrl('*/*/template') . '\')'); + } + + /** + * Return delete url for customer group + * + * @return string + */ + public function getDeleteUrl() + { + return $this->getUrl('*/*/deletetemplate', array($this->_objectId => $this->getRequest()->getParam($this->_objectId))); + } + + /** + * Get text for header + * + * @return string + */ + public function getHeaderText() + { + $template = Mage::registry('current_template'); + if ($template && $template->getId()) { + return $this->__('Edit Template "%s"', $this->htmlEscape($template->getName())); + } else { + return $this->__('New Template'); + } + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php new file mode 100755 index 0000000000..ce3080bb1d --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php @@ -0,0 +1,136 @@ +isEnabled()) { + $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + } + } + + /** + * Prepare form + * + * @return Mage_Adminhtml_Block_Widget_Form + */ + protected function _prepareForm() + { + $model = Mage::registry('current_template'); + + if (!$model) { + $model = new Varien_Object(); + } + + $action = $this->getUrl('*/*/saveTemplate'); + + $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $action, 'method' => 'post', 'enctype' => 'multipart/form-data')); + $form->setHtmlIdPrefix('template_'); + + $fieldset = $form->addFieldset('edit_template', array('legend' => $this->__('Template'))); + $this->_addElementTypes($fieldset); + + if ($model->getId()) { + $fieldset->addField('id', 'hidden', array( + 'name' => 'id', + )); + $fieldset->addField('template_id', 'hidden', array( + 'name' => 'template_id', + )); + } + + $fieldset->addField('app_code', 'select', array( + 'name' => 'app_code', + 'label' => $this->__('Application'), + 'title' => $this->__('Application'), + 'disabled' => $model->getId() || !$this->_fieldsEnabled ? true : false, + 'values' => Mage::helper('xmlconnect')->getApplicationOptions(), + 'note' => $this->__('Creating a Template is allowed only for applications which have device type iPhone.'), + 'required' => true, + )); + + $fieldset->addField('name', 'text', array( + 'name' => 'name', + 'label' => $this->__('Template Name'), + 'title' => $this->__('Template Name'), + 'required' => true, + 'disabled' => $model->getId() || !$this->_fieldsEnabled ? true : false, + 'note' => $this->__('Maximum length is 255'), + 'maxlength' => 255 + )); + + $fieldset->addField('push_title', 'text', array( + 'name' => 'push_title', + 'label' => $this->__('Push Title'), + 'title' => $this->__('Push Title'), + 'required' => true, + 'disabled' => !$this->_fieldsEnabled ? true : false, + 'note' => $this->__('Maximum length is 140'), + 'maxlength' => 140 + )); + + $this->_dependentFields['message_title'] = $fieldset->addField('message_title', 'text', array( + 'name' => 'message_title', + 'label' => $this->__('Message Title'), + 'title' => $this->__('Message Title'), + 'required' => true, + 'disabled' => !$this->_fieldsEnabled ? true : false, + 'note' => $this->__('Maximum length is 255'), + 'maxlength' => 255 + )); + + $widgetFilters = array('is_email_compatible' => 1); + $wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig(array( +// 'add_widgets' => true, +// 'add_variables' => true, + 'widget_filters' => $widgetFilters + )); + + $this->_dependentFields['content'] = $fieldset->addField('content', 'editor', array( + 'label' => $this->__('Template Content'), + 'title' => $this->__('Template Content'), + 'name' => 'content', + 'style' => 'height:30em;', + 'state' => 'html', + 'required' => true, +// 'disabled' => false, + 'disabled' => !$this->_fieldsEnabled ? true : false, + 'config' => $wysiwygConfig + )); + + $form->setValues($model->getData()); + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php new file mode 100755 index 0000000000..5b885ac17f --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php @@ -0,0 +1,158 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Template_Grid extends Mage_Adminhtml_Block_Widget_Grid +{ + + /** + * Constructor + * + * Setting grid_id, sort order and sort direction + */ + public function __construct() + { + parent::__construct(); + $this->setId('app_template_grid'); + $this->setDefaultSort('created_at'); + $this->setDefaultDir('ASC'); + $this->setSaveParametersInSession(true); + } + + /** + * Setting collection to show + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareCollection() + { + $collection = Mage::getModel('xmlconnect/template')->getCollection(); + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * Configuration of grid + * + * @return Mage_Adminhtml_Block_Widget_Grid + */ + protected function _prepareColumns() + { + $this->addColumn('id', array( + 'header' => $this->__('ID'), + 'align' => 'center', + 'index' => 'id', + 'width' => '40px' + )); + + $this->addColumn('name', array( + 'header' => $this->__('Template Name'), + 'align' => 'left', + 'index' => 'name' + )); + + $this->addColumn('created_at', array( + 'header' => $this->__('Date Created'), + 'align' => 'left', + 'index' => 'created_at', + 'type' => 'datetime' + )); + + $this->addColumn('modified_at', array( + 'header' => $this->__('Date Updated'), + 'align' => 'left', + 'index' => 'modified_at', + 'type' => 'datetime' + )); + + $this->addColumn('app_code', array( + 'header' => $this->__('Application'), + 'index' => 'app_code', + 'type' => 'options', + 'align' => 'left', + 'options' => Mage::helper('xmlconnect')->getApplications(), + 'renderer' => 'xmlconnect/adminhtml_template_grid_renderer_application', + )); + + $this->addColumn('push_title', array( + 'header' => $this->__('Push Title'), + 'type' => 'text', + 'align' => 'left', + 'index' => 'push_title' + )); + + $this->addColumn('message_title', array( + 'header' => $this->__('Message Title'), + 'type' => 'text', + 'align' => 'left', + 'index' => 'message_title' + )); + + $this->addColumn('action', array( + 'header' => $this->__('Action'), + 'type' => 'action', + 'getter' => 'getId', + 'actions' => array( + array( + 'caption' => $this->__('Preview'), + 'url' => array( + 'base' => '*/*/previewTemplate' + ), + 'popup' => true, + 'field' => 'id' + ), + array( + 'caption' => $this->__('Queue Message'), + 'url' => array( + 'base' => '*/*/queueMessage', + ), + 'field' => 'template_id' + ), + ), + 'filter' => false, + 'sortable' => false, + )); + + return parent::_prepareColumns(); + } + + /** + * Configure row click url + * + * @param Mage_Catalog_Model_Template|Varien_Object $row + * @return string + */ + public function getRowUrl($row) + { + return $this->getUrl('*/*/editTemplate', array('id' => $row->getId())); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php new file mode 100755 index 0000000000..86ee846a02 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php @@ -0,0 +1,50 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Application extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + $str = htmlspecialchars($row->getAppName()); + if ($str == '') { + $str = ' --- '; + } + return $str; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php new file mode 100755 index 0000000000..883460115a --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php @@ -0,0 +1,69 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Template_Preview extends Mage_Adminhtml_Block_Widget +{ + /** + * Retrieve processed template + * + * @return string + */ + protected function _toHtml() + { + if ((int)$this->getRequest()->getParam('queue_preview')) { + $id = $this->getRequest()->getParam('queue_preview'); + /* @var $template Mage_XmlConnect_Model_Queue */ + $template = Mage::getModel('xmlconnect/queue'); + } else { + $id = (int)$this->getRequest()->getParam('id'); + /* @var $template Mage_XmlConnect_Model_Template */ + $template = Mage::getModel('xmlconnect/template'); + } + + if ($id) { + $template->load($id); + } + + $storeId = (int)$this->getRequest()->getParam('store_id'); + + if (!$storeId) { + $storeId = Mage::app()->getDefaultStoreView()->getId(); + } + + $template->emulateDesign($storeId); + $templateProcessed = $template->getProcessedTemplate(array(), true); + $template->revertDesign(); + + return $templateProcessed; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php new file mode 100755 index 0000000000..884e772f92 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php @@ -0,0 +1,70 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form extends Mage_Adminhtml_Block_Widget_Form +{ + + /** + * Preparing from for revision page + * + * @return Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(array( + 'id' => 'preview_form', + 'action' => $this->getUrl('*/*/drop', array('_current' => true)), + 'method' => 'post' + )); + + if ($data = $this->getFormData()) { + + $mapper = array('preview_store_id' => 'store_id'); + + foreach ($data as $key => $value) { + if(array_key_exists($key, $mapper)) { + $name = $mapper[$key]; + } else { + $name = $key; + } + $form->addField($key, 'hidden', array('name' => $name)); + } + $form->setValues($data); + } + + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } +} + diff --git a/app/code/core/Mage/XmlConnect/Block/Cart.php b/app/code/core/Mage/XmlConnect/Block/Cart.php index 5b08d67d99..366e64b85b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart.php @@ -69,9 +69,7 @@ protected function _toHtml() $iconXml = $itemXml->addChild('icon', $icon); - $baseUrl = Mage::getBaseUrl('media'); - $path = str_replace($baseUrl, '', $icon); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); + $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php b/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php index 29bf967e48..cbd5c55c85 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php @@ -53,10 +53,7 @@ protected function _toHtml() $iconXml = $itemXmlObj->addChild('icon', $icon); - $baseUrl = Mage::getBaseUrl('media'); - $path = str_replace($baseUrl, '', $icon); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); - + $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); $itemXmlObj->addChild('entity_id', $_item->getId()); diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php index 59dc468cab..836f8a91f6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php @@ -33,18 +33,24 @@ */ class Mage_XmlConnect_Block_Cart_Paypal_Mep_Totals extends Mage_Checkout_Block_Cart_Totals { - /** + /** * Render cart totals xml * * @return string */ protected function _toHtml() { - $paypalCart = Mage::getModel('paypal/cart', array($this->getQuote())); + $quote = $this->getQuote(); $totalsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element(''); - foreach ($paypalCart->getTotals(true) as $code => $amount) { - $currencyAmount = $this->helper('core')->currency($amount, false, false); - $totalsXmlObj->addChild($code, Mage::helper('xmlconnect')->formatPriceForXml($currencyAmount)); + list($items, $totals) = Mage::helper('paypal')->prepareLineItems($quote); + + if (Mage::helper('paypal')->areCartLineItemsValid($items, $totals, $quote->getBaseGrandTotal())) { + foreach ($totals as $code => $amount) { + $currencyAmount = $this->helper('core')->currency($amount, false, false); + $totalsXmlObj->addChild($code, Mage::helper('xmlconnect')->formatPriceForXml($currencyAmount)); + } + } else { + Mage::throwException($this->__('Cart line items are not eligible for exporting to PayPal API')); } return $totalsXmlObj->asNiceXml(); } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog.php b/app/code/core/Mage/XmlConnect/Block/Catalog.php index 72c3920046..05cc7e47f2 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog.php @@ -50,11 +50,17 @@ class Mage_XmlConnect_Block_Catalog extends Mage_Core_Block_Template */ public function getProductSortFeildsXmlObject() { - $ordersXmlObject = new Mage_XmlConnect_Model_Simplexml_Element(''); - $sortOptions = Mage::getModel('catalog/category')->getAvailableSortByOptions(); - $sortOptions = array_slice($sortOptions, 0, self::PRODUCT_SORT_FIELDS_NUMBER); + $ordersXmlObject = new Mage_XmlConnect_Model_Simplexml_Element(''); + /* @var $category Mage_Catalog_Model_Category */ + $category = Mage::getModel('catalog/category'); + $sortOptions = $category->getAvailableSortByOptions(); + $sortOptions = array_slice($sortOptions, 0, self::PRODUCT_SORT_FIELDS_NUMBER); + $defaultSort = $category->getDefaultSortBy(); foreach ($sortOptions as $code => $name) { $item = $ordersXmlObject->addChild('item'); + if ($code == $defaultSort) { + $item->addAttribute('isDefault', 1); + } $item->addChild('code', $code); $item->addChild('name', $ordersXmlObject->xmlentities(strip_tags($name))); } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php index af9e9010d6..91f1134ad4 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php @@ -46,22 +46,19 @@ protected function _toHtml() if ($categoryId === null) { $categoryId = Mage::app()->getStore()->getRootCategoryId(); } + + $productsXmlObj = $productListBlock = false; + $categoryModel = Mage::getModel('catalog/category')->load($categoryId); if ($categoryModel->getId()) { $hasMoreProductItems = 0; - $productsXmlObj = $productListBlock = null; - /** - * Return products list if there are no child categories - */ - if (!$categoryModel->hasChildren()) { - $productListBlock = $this->getChild('product_list'); - if ($productListBlock) { - $layer = Mage::getSingleton('catalog/layer'); - $productsXmlObj = $productListBlock->setCategory($categoryModel) - ->setLayer($layer) - ->getProductsXmlObject(); - $hasMoreProductItems = (int)$productListBlock->getHasProductItems(); - } + $productListBlock = $this->getChild('product_list'); + if ($productListBlock && $categoryModel->getLevel() > 1) { + $layer = Mage::getSingleton('catalog/layer'); + $productsXmlObj = $productListBlock->setCategory($categoryModel) + ->setLayer($layer) + ->getProductsXmlObject(); + $hasMoreProductItems = (int)$productListBlock->getHasProductItems(); } $infoBlock = $this->getChild('category_info'); @@ -71,11 +68,6 @@ protected function _toHtml() $categoryInfoXmlObj->addChild('has_more_items', $hasMoreProductItems); $categoryXmlObj->appendChild($categoryInfoXmlObj); } - - if ($productListBlock && $productsXmlObj) { - $categoryXmlObj->appendChild($productsXmlObj); - } - } $categoryCollection = Mage::getResourceModel('xmlconnect/category_collection'); @@ -83,28 +75,30 @@ protected function _toHtml() ->setOrder('position', 'ASC') ->addParentIdFilter($categoryId); + // subcategories are exists if (sizeof($categoryCollection)) { $itemsXmlObj = $categoryXmlObj->addChild('items'); - } - foreach ($categoryCollection->getItems() as $item) { - $itemXmlObj = $itemsXmlObj->addChild('item'); - $itemXmlObj->addChild('label', $categoryXmlObj->xmlentities(strip_tags($item->getName()))); - $itemXmlObj->addChild('entity_id', $item->getEntityId()); - $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products'); - if (!is_null($categoryId)) { - $itemXmlObj->addChild('parent_id', $item->getParentId()); - } - $icon = Mage::helper('xmlconnect/catalog_category_image')->initialize($item, 'thumbnail') - ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('category')); + foreach ($categoryCollection->getItems() as $item) { + $itemXmlObj = $itemsXmlObj->addChild('item'); + $itemXmlObj->addChild('label', $categoryXmlObj->xmlentities(strip_tags($item->getName()))); + $itemXmlObj->addChild('entity_id', $item->getEntityId()); + $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products'); + if (!is_null($categoryId)) { + $itemXmlObj->addChild('parent_id', $item->getParentId()); + } + $icon = Mage::helper('xmlconnect/catalog_category_image')->initialize($item, 'thumbnail') + ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('category')); - $iconXml = $itemXmlObj->addChild('icon', $icon); + $iconXml = $itemXmlObj->addChild('icon', $icon); - $baseUrl = Mage::getBaseUrl('media'); - $path = str_replace($baseUrl, '', $icon); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); + $file = Mage::helper('xmlconnect')->urlToPath($icon); + $iconXml->addAttribute('modification_time', filemtime($file)); + } + } - $iconXml->addAttribute('modification_time', filemtime($file)); + if ($productListBlock && $productsXmlObj) { + $categoryXmlObj->appendChild($productsXmlObj); } return $categoryXmlObj->asNiceXml(); diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php index 50395a53a0..9782ebea06 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php @@ -45,20 +45,20 @@ public function getCategoryInfoXmlObject() $infoXmlObj = new Mage_XmlConnect_Model_Simplexml_Element(''); $category = $this->getCategory(); if ($category && is_object($category) && $category->getId()) { - $title = $infoXmlObj->xmlentities(strip_tags($category->getParentCategory()->getName())); - if ($category->getParentCategory()->getLevel() == 1) { - /** - * @var string $title - * - * Copied data from "getDefaultApplicationDesignTabs()" method in "Mage_XmlConnect_Helper_Data" - */ - $title = Mage::helper('xmlconnect')->__('Shop'); + /** + * @var string $title + * + * Copied data from "getDefaultApplicationDesignTabs()" method in "Mage_XmlConnect_Helper_Data" + */ + $title = $this->__('Shop'); + if ($category->getParentCategory()->getLevel() > 1) { + $title = $infoXmlObj->xmlentities(strip_tags($category->getParentCategory()->getName())); } $infoXmlObj->addChild('parent_title', $title); - $pId = $category->getParentId(); - if ($category->getLevel() == 1) { - $pId = 0; + $pId = 0; + if ($category->getLevel() > 1) { + $pId = $category->getParentId(); } $infoXmlObj->addChild('parent_id', $pId); } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php index 77a8eb9d9d..071081ac57 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php @@ -61,16 +61,12 @@ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNod $propertyToResizeName = 'image'; } - $icon = clone Mage::helper('catalog/image')->init($product, $propertyToResizeName) ->resize($imageToResize); $iconXml = $item->addChild('icon', $icon); - $baseUrl = Mage::getBaseUrl('media'); - $path = str_replace($baseUrl, '', $icon); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); - + $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); $item->addChild('in_stock', (int)$product->isSalable()); @@ -119,9 +115,9 @@ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNod /** * Get MinSaleQty for product - * + * * @param Mage_Catalog_Model_Product $product - * @return int|null + * @return int|null */ protected function _getMinimalQty($product) { @@ -142,7 +138,7 @@ protected function _toHtml() ->load($this->getRequest()->getParam('id', 0)); if (!$product) { - throw new Mage_Core_Exception(Mage::helper('xmlconnect')->__('Selected product is unavailable.')); + throw new Mage_Core_Exception($this->__('Selected product is unavailable.')); } else { $this->setProduct($product); $productXmlObj = $this->productToXmlObject($product, 'product'); @@ -153,7 +149,11 @@ protected function _toHtml() $productXmlObj->appendChild($relatedXmlObj); } } + + $productXmlObj->appendChild($this->getChild('xmlconnect.catalog.product.options') + ->getProductOptionsXmlObject($product) + ); + return $productXmlObj->asNiceXml(); } - } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php index ec1d5c17a2..046764ff70 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php @@ -51,7 +51,7 @@ public function addAdditionalData(Mage_Catalog_Model_Product $product, Mage_XmlC $attributesXmlObj = $productXmlObject->addChild('additional_attributes'); foreach ($additionalData as $data) { $_attrXmlObject = $attributesXmlObj->addChild('item'); - $_attrXmlObject->addChild('label', $this->htmlEscape(Mage::helper('xmlconnect')->__($data['label']))); + $_attrXmlObject->addChild('label', $this->htmlEscape($data['label'])); $_attrXmlObject->addChild('value', Mage::helper('catalog/output')->productAttribute($product, $data['value'], $data['code'])); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php index 09d083baae..070d976648 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php @@ -64,9 +64,7 @@ protected function _toHtml() $fileNode->addAttribute('type', 'big'); $fileNode->addAttribute('url', $bigImage); - $baseUrl = Mage::getBaseUrl('media'); - $path = str_replace($baseUrl, '', $bigImage); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); + $file = Mage::helper('xmlconnect')->urlToPath($bigImage); $fileNode->addAttribute('id', ($id = $item->getId()) ? (int) $id : 0); $fileNode->addAttribute('modification_time', filemtime($file)); @@ -81,9 +79,7 @@ protected function _toHtml() $fileNode->addAttribute('type', 'small'); $fileNode->addAttribute('url', $smallImage); - $path = str_replace($baseUrl, '', $smallImage); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); - + $file = Mage::helper('xmlconnect')->urlToPath($smallImage); $fileNode->addAttribute('modification_time', filemtime($file)); } return $imagesNode->asNiceXml(); diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php index 14071ebbfb..d37663bcda 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php @@ -59,7 +59,7 @@ public function getProductsXmlObject() $collection = $this->_getProductCollection(); if (!$collection) { - return $productsXmlObj; + return false; } foreach ($collection->getItems() as $product) { $productXmlObj = $this->productToXmlObject($product); @@ -160,7 +160,7 @@ protected function _getProductCollection() $collection->getSelect()->limit($count, $offset); $collection->setFlag('require_stock_items', true); - + $this->_productCollection = $collection; } return $this->_productCollection; diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php index 18c2edf39d..e71bf3e0f5 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php @@ -80,7 +80,6 @@ public function getProductCustomOptionsXmlObject(Mage_Catalog_Model_Product $pro return $xmlModel; } - foreach ($product->getOptions() as $option) { $optionNode = $optionsNode->addChild('option'); $type = $this->_getOptionTypeForXmlByRealType($option->getType()); @@ -171,6 +170,26 @@ protected function _getOptionTypeForXmlByRealType($realType) return $type; } + /** + * Create product custom options Mage_XmlConnect_Model_Simplexml_Element object + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_XmlConnect_Model_Simplexml_Element | false + */ + public function getProductOptionsXmlObject(Mage_Catalog_Model_Product $product) + { + if ($product->getId()) { + $type = $product->getTypeId(); + if (isset($this->_renderers[$type])) { + $renderer = $this->getLayout()->createBlock($this->_renderers[$type]); + if ($renderer) { + return $renderer->getProductOptionsXml($product, true); + } + } + } + return false; + } + /** * Generate product options xml * diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php index 8f40ecdc50..528d77de16 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php @@ -38,17 +38,17 @@ class Mage_XmlConnect_Block_Catalog_Product_Options_Bundle extends Mage_XmlConne * Generate bundle product options xml * * @param Mage_Catalog_Model_Product $product - * @return string + * @param bool $isObject + * @return string | Mage_XmlConnect_Model_Simplexml_Element */ - public function getProductOptionsXml(Mage_Catalog_Model_Product $product) + public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false) { $xmlModel = $this->getProductCustomOptionsXmlObject($product); $optionsXmlObj = $xmlModel->options; - $options = array(); if (!$product->isSaleable()) { - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } /** @@ -62,7 +62,7 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product) ); $bundleOptions = $optionCollection->appendSelections($selectionCollection, false, false); if (!sizeof($bundleOptions)) { - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } foreach ($bundleOptions as $_option) { @@ -117,6 +117,6 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product) } } - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php index 012dd6102b..e2c67b01c6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php @@ -38,16 +38,17 @@ class Mage_XmlConnect_Block_Catalog_Product_Options_Configurable extends Mage_Xm * Generate bundle product options xml * * @param Mage_Catalog_Model_Product $product - * @return string + * @param bool $isObject + * @return string | Mage_XmlConnect_Model_Simplexml_Element */ - public function getProductOptionsXml(Mage_Catalog_Model_Product $product) + public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false) { $xmlModel = $this->getProductCustomOptionsXmlObject($product); $optionsXmlObj = $xmlModel->options; $options = array(); if (!$product->isSaleable()) { - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } /** @@ -55,7 +56,7 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product) */ $_attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product); if (!sizeof($_attributes)) { - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } $_allowProducts = array(); @@ -144,7 +145,7 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product) } } - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php index fed7957b6d..8a85721d76 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php @@ -38,26 +38,27 @@ class Mage_XmlConnect_Block_Catalog_Product_Options_Grouped extends Mage_XmlConn * Generate bundle product options xml * * @param Mage_Catalog_Model_Product $product - * @return string + * @param bool $isObject + * @return string | Mage_XmlConnect_Model_Simplexml_Element */ - public function getProductOptionsXml(Mage_Catalog_Model_Product $product) + public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false) { $xmlModel = new Mage_XmlConnect_Model_Simplexml_Element(''); $optionsNode = $xmlModel->addChild('options'); if (!$product->getId()) { - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } $xmlModel->addAttribute('id', $product->getId()); if (!$product->isSaleable()) { - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } /** * Grouped (associated) products */ $_associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product); if (!sizeof($_associatedProducts)) { - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } foreach ($_associatedProducts as $_item) { if (!$_item->isSaleable()) { @@ -87,6 +88,6 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product) } } - return $xmlModel->asNiceXml(); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php index abda11053c..0e5d900f1e 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php @@ -38,10 +38,12 @@ class Mage_XmlConnect_Block_Catalog_Product_Options_Simple extends Mage_XmlConne * Generate simple product options xml * * @param Mage_Catalog_Model_Product $product - * @return string + * @param bool $isObject + * @return string | Mage_XmlConnect_Model_Simplexml_Element */ - public function getProductOptionsXml(Mage_Catalog_Model_Product $product) + public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false) { - return $this->getProductCustomOptionsXmlObject($product)->asNiceXml(); + $xmlModel = $this->getProductCustomOptionsXmlObject($product); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php index 208ad60a71..177528118d 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php @@ -38,10 +38,12 @@ class Mage_XmlConnect_Block_Catalog_Product_Options_Virtual extends Mage_XmlConn * Generate virtual product options xml * * @param Mage_Catalog_Model_Product $product - * @return string + * @param bool $isObject + * @return string | Mage_XmlConnect_Model_Simplexml_Element */ - public function getProductOptionsXml(Mage_Catalog_Model_Product $product) + public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false) { - return $this->getProductCustomOptionsXmlObject($product)->asNiceXml(); + $xmlModel = $this->getProductCustomOptionsXmlObject($product); + return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php index c26d593ee1..f8493c9184 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php @@ -58,8 +58,11 @@ public function reviewToXmlObject(Mage_Review_Model_Review $review, $itemNodeNam $detail = $item->xmlentities($review->getDetail()); if ($itemNodeName == 'item') { $remainder = ''; - $detail = Mage::helper('core/string') - ->truncate($detail, self::REVIEW_DETAIL_TRUNCATE_LEN, '', $remainder, false); + $deviceType = Mage::helper('xmlconnect')->getApplication()->getType(); + if ($deviceType != Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD) { + $detail = Mage::helper('core/string') + ->truncate($detail, self::REVIEW_DETAIL_TRUNCATE_LEN, '', $remainder, false); + } } $item->addChild('detail', $detail); diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php index 89a7601c03..3f115ac50e 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php @@ -76,7 +76,7 @@ protected function _toHtml() /** * Filters */ - $showFiltersAndOrders = true; + $showFiltersAndOrders = (bool) count($productsXmlObj); $reguest = $this->getRequest(); foreach ($reguest->getParams() as $key => $value) { if (0 === strpos($key, parent::REQUEST_SORT_ORDER_PARAM_REFIX) || diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php index 9ce3451bfd..8546a3a658 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php @@ -112,28 +112,32 @@ protected function _toHtml() $xml = << - - - + + + EOT; - if ($isAllowedGuestCheckout) { + if ($isAllowedGuestCheckout && !Mage::getSingleton('customer/session')->isLoggedIn() && $addressType == 'billing') { $xml .= << + + + + + EOT; } $xml .= << - - - + + + + $countryOptionsXml - - - - - - + + + + + + EOT; return $xml; diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php index f34a2ca85c..e63056a0ee 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php @@ -62,10 +62,7 @@ protected function _toHtml() $iconXml = $itemXml->addChild('icon', $icon); - $baseUrl = Mage::getBaseUrl('media'); - $path = str_replace($baseUrl, '', $icon); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); - + $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); /** diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php index fa8ee71d30..85ef7418e8 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php @@ -59,6 +59,7 @@ public function getQuote() * Render payment methods xml * * @return string + * @throw Mage_Core_Exception */ protected function _toHtml() { @@ -151,7 +152,9 @@ protected function _toHtml() } $renderer->addPaymentFormToXmlObj($methodItemXmlObj); } - + if (!count($usedMethods)) { + Mage::throwException($this->__('Sorry, no payment options are available for this order at this time.')); + } return $methodsXmlObj->asNiceXml(); } diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php index de1ac3a9fb..c3ec5f4b79 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php @@ -58,7 +58,7 @@ protected function _toHtml() if ($_rate->getErrorMessage()) { $rateXmlObj->addChild('error_message', $methodsXmlObj->xmlentities(strip_tags($_rate->getErrorMessage()))); } else { - $price = Mage::helper('tax')->getShippingPrice($_rate->getPrice(), false, $this->getAddress()); + $price = Mage::helper('tax')->getShippingPrice($_rate->getPrice(), Mage::helper('tax')->displayShippingPriceIncludingTax(), $this->getAddress()); $formattedPrice = $store->convertPrice($price, true, false); $rateXmlObj->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml($store->convertPrice($price, false, false))); $rateXmlObj->addAttribute('formated_price', $formattedPrice); @@ -66,7 +66,7 @@ protected function _toHtml() } } } else { - Mage::throwException(Mage::helper('xmlconnect')->__('Sorry, no quotes are available for this order at this time.')); + Mage::throwException($this->__('Sorry, no quotes are available for this order at this time.')); } return $methodsXmlObj->asNiceXml(); } diff --git a/app/code/core/Mage/XmlConnect/Block/Configuration.php b/app/code/core/Mage/XmlConnect/Block/Configuration.php index 14623f747e..bf310fb953 100644 --- a/app/code/core/Mage/XmlConnect/Block/Configuration.php +++ b/app/code/core/Mage/XmlConnect/Block/Configuration.php @@ -93,7 +93,7 @@ protected function _buildRecursive($section, $subtree) } else { $value = (string)$value; if ($value != '') { - $section->addChild($key, $value); + $section->addChild($key, Mage::helper('core')->htmlEscape($value)); } } } @@ -107,7 +107,7 @@ protected function _buildRecursive($section, $subtree) protected function _toHtml() { $xml = new Mage_XmlConnect_Model_Simplexml_Element(''); - $this->_buildRecursive($xml, $this->_app->getRenderConf()); + $this->_buildRecursive($xml, Mage::helper('xmlconnect')->excludeXmlConfigKeys($this->_app->getRenderConf())); return $xml->asNiceXml(); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php b/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php index c485389f65..d5adffe20c 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php @@ -107,25 +107,25 @@ protected function _toHtml() $xml = << -
- - - - - +
+ + + + +
- - - - + + + + $countryOptionsXml - - - - - + + + + +
EOT; diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php b/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php index 16be94dd51..e3ff77ff71 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php @@ -50,13 +50,13 @@ protected function _toHtml() if ($billingAddress && $billingAddress->getId()) { $item = $addressXmlObj->addChild('item'); - $item->addAttribute('label', Mage::helper('xmlconnect')->__('Default Billing Address')); + $item->addAttribute('label', $this->__('Default Billing Address')); $item->addAttribute('default_billing', 1); $this->prepareAddressData($billingAddress, $item); } if ($shippingAddress && $shippingAddress->getId()) { $item = $addressXmlObj->addChild('item'); - $item->addAttribute('label', Mage::helper('xmlconnect')->__('Default Shipping Address')); + $item->addAttribute('label', $this->__('Default Shipping Address')); $item->addAttribute('default_shipping', 1); $this->prepareAddressData($shippingAddress, $item); } @@ -64,7 +64,7 @@ protected function _toHtml() if ($_additionalAddresses) { foreach ($_additionalAddresses as $_address) { $item = $addressXmlObj->addChild('item'); - $item->addAttribute('label', Mage::helper('xmlconnect')->__('Additional Address')); + $item->addAttribute('label', $this->__('Additional Address')); $item->addAttribute('additional', 1); $this->prepareAddressData($_address, $item); } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form.php index fc95df38f7..fb1f94ef94 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form.php @@ -54,23 +54,23 @@ protected function _toHtml() if ($editFlag) { $passwordManageXml = ' - +
- - - + + + - password + password
'; } else { $passwordManageXml = ' - - + + - password + password '; @@ -79,11 +79,11 @@ protected function _toHtml() $xml = <<
- - - + + + - + $passwordManageXml diff --git a/app/code/core/Mage/XmlConnect/Block/Home.php b/app/code/core/Mage/XmlConnect/Block/Home.php index 2368baa0a6..dfa4180be2 100644 --- a/app/code/core/Mage/XmlConnect/Block/Home.php +++ b/app/code/core/Mage/XmlConnect/Block/Home.php @@ -69,9 +69,8 @@ protected function _toHtml() $iconXml = $itemXmlObj->addChild('icon', $icon); - $baseUrl = Mage::getBaseUrl('media'); - $path = str_replace($baseUrl, '', $icon); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); + $file = Mage::helper('xmlconnect')->urlToPath($icon); + $iconXml->addAttribute('modification_time', filemtime($file)); } diff --git a/app/code/core/Mage/XmlConnect/Block/Wishlist.php b/app/code/core/Mage/XmlConnect/Block/Wishlist.php index 70ea51dddb..5d487f3b61 100644 --- a/app/code/core/Mage/XmlConnect/Block/Wishlist.php +++ b/app/code/core/Mage/XmlConnect/Block/Wishlist.php @@ -82,10 +82,7 @@ protected function _toHtml() $iconXml = $itemXmlObj->addChild('icon', $icon); - $baseUrl = Mage::getBaseUrl('media'); - $path = str_replace($baseUrl, '', $icon); - $file = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); - + $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); diff --git a/app/code/core/Mage/XmlConnect/Controller/Action.php b/app/code/core/Mage/XmlConnect/Controller/Action.php index 73211c4eb3..3b8eb87340 100644 --- a/app/code/core/Mage/XmlConnect/Controller/Action.php +++ b/app/code/core/Mage/XmlConnect/Controller/Action.php @@ -24,19 +24,48 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - abstract class Mage_XmlConnect_Controller_Action extends Mage_Core_Controller_Front_Action { + /** + * Message status `error` + * + * @var string + */ const MESSAGE_STATUS_ERROR = 'error'; + + /** + * Message status `warning` + * + * @var string + */ const MESSAGE_STATUS_WARNING = 'warning'; + + /** + * Message status `success` + * + * @var string + */ const MESSAGE_STATUS_SUCCESS = 'success'; + /** + * Message type `alert` + * + * @var string + */ const MESSAGE_TYPE_ALERT = 'alert'; + + /** + * Message type `prompt` + * + * @var string + */ const MESSAGE_TYPE_PROMPT = 'prompt'; /** * Declare content type header * Validate current application + * + * @return void */ public function preDispatch() { @@ -56,6 +85,14 @@ public function preDispatch() $this->setFlag('', self::FLAG_NO_DISPATCH, true); return; } + /** + * Check is website offline + */ + if ((int)Mage::getStoreConfig('general/restriction/is_active') && (int)Mage::getStoreConfig('general/restriction/mode') == 0) { + $this->_message(Mage::helper('xmlconnect')->__('Website is offline.'), self::MESSAGE_STATUS_SUCCESS); + $this->setFlag('', self::FLAG_NO_DISPATCH, true); + return; + } $appModel = Mage::getModel('xmlconnect/application')->loadByCode($appCode); $appModel->setScreenSize($screenSize); if ($appModel && $appModel->getId()) { @@ -71,6 +108,8 @@ public function preDispatch() /** * Validate response body + * + * @return void */ public function postDispatch() { @@ -91,6 +130,7 @@ public function postDispatch() * @param string $status * @param string $type * @param string $action + * @return void */ protected function _message($text, $status, $type='', $action='') { diff --git a/app/code/core/Mage/XmlConnect/Helper/Android.php b/app/code/core/Mage/XmlConnect/Helper/Android.php new file mode 100755 index 0000000000..e70d94742c --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Helper/Android.php @@ -0,0 +1,406 @@ +_tabs)) { + $this->_tabs = array( + array( + 'label' => Mage::helper('xmlconnect')->__('Home'), + 'image' => 'tab_home_android.png', + 'action' => 'Home', + 'menu' => self::TAGS_ID_FOR_TITLE_BAR, + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Search'), + 'image' => 'tab_search_android.png', + 'action' => 'Search', + 'menu' => self::TAGS_ID_FOR_TITLE_BAR, + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Account'), + 'image' => 'tab_account_android.png', + 'action' => 'Account', + 'menu' => self::TAGS_ID_FOR_TITLE_BAR, + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Shop'), + 'image' => 'tab_shop_android.png', + 'action' => 'Shop', + 'menu' => self::TAGS_ID_FOR_OPTION_MENU, + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Cart'), + 'image' => 'tab_cart_android.png', + 'action' => 'Cart', + 'menu' => self::TAGS_ID_FOR_OPTION_MENU, + ), + array( + 'label' => Mage::helper('xmlconnect')->__('More Info'), + 'image' => 'tab_info_android.png', + 'action' => 'AboutUs', + 'menu' => self::TAGS_ID_FOR_OPTION_MENU, + ), + ); + } + return $this->_tabs; + } + + /** + * Default application configuration + * + * @return array + */ + public function getDefaultConfiguration() + { + return array( + 'native' => array( + 'body' => array( + 'backgroundColor' => '#ABABAB', + 'scrollBackgroundColor' => '#EDEDED', + ), + 'itemActions' => array( + 'relatedProductBackgroundColor' => '#404040', + ), + 'fonts' => array( + 'Title1' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '14', + 'color' => '#FEFEFE', + ), + 'Title2' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '12', + 'color' => '#222222', + ), + 'Title3' => array( + 'name' => 'HelveticaNeue', + 'size' => '13', + 'color' => '#000000', + ), + 'Title4' => array( + 'name' => 'HelveticaNeue', + 'size' => '12', + 'color' => '#FFFFFF', + ), + 'Title5' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '13', + 'color' => '#dc5f02', + ), + 'Title6' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '16', + 'color' => '#222222', + ), + 'Title7' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '13', + 'color' => '#000000', + ), + 'Title8' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '11', + 'color' => '#FFFFFF', + ), + 'Title9' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '12', + 'color' => '#FFFFFF', + ), + 'Text1' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '12', + 'color' => '#777777', + ), + 'Text2' => array( + 'name' => 'HelveticaNeue', + 'size' => '10', + 'color' => '#555555', + ), + ), + ), + ); + } + + /** + * List of allowed fonts for Android application + * + * @return array + */ + public function getFontList() + { + return array( + array( + 'value' => 'HiraKakuProN-W3', + 'label' => 'HiraKakuProN-W3', + ), + array( + 'value' => 'Courier', + 'label' => 'Courier', + ), + array( + 'value' => 'Courier-BoldOblique', + 'label' => 'Courier-BoldOblique', + ), + array( + 'value' => 'Courier-Oblique', + 'label' => 'Courier-Oblique', + ), + array( + 'value' => 'Courier-Bold', + 'label' => 'Courier-Bold', + ), + array( + 'value' => 'ArialMT', + 'label' => 'ArialMT', + ), + array( + 'value' => 'Arial-BoldMT', + 'label' => 'Arial-BoldMT', + ), + array( + 'value' => 'Arial-BoldItalicMT', + 'label' => 'Arial-BoldItalicMT', + ), + array( + 'value' => 'Arial-ItalicMT', + 'label' => 'Arial-ItalicMT', + ), + array( + 'value' => 'STHeitiTC-Light', + 'label' => 'STHeitiTC-Light', + ), + array( + 'value' => 'STHeitiTC-Medium', + 'label' => 'STHeitiTC-Medium', + ), + array( + 'value' => 'AppleGothic', + 'label' => 'AppleGothic', + ), + array( + 'value' => 'CourierNewPS-BoldMT', + 'label' => 'CourierNewPS-BoldMT', + ), + array( + 'value' => 'CourierNewPS-ItalicMT', + 'label' => 'CourierNewPS-ItalicMT', + ), + array( + 'value' => 'CourierNewPS-BoldItalicMT', + 'label' => 'CourierNewPS-BoldItalicMT', + ), + array( + 'value' => 'CourierNewPSMT', + 'label' => 'CourierNewPSMT', + ), + array( + 'value' => 'Zapfino', + 'label' => 'Zapfino', + ), + array( + 'value' => 'HiraKakuProN-W6', + 'label' => 'HiraKakuProN-W6', + ), + array( + 'value' => 'ArialUnicodeMS', + 'label' => 'ArialUnicodeMS', + ), + array( + 'value' => 'STHeitiSC-Medium', + 'label' => 'STHeitiSC-Medium', + ), + array( + 'value' => 'STHeitiSC-Light', + 'label' => 'STHeitiSC-Light', + ), + array( + 'value' => 'AmericanTypewriter', + 'label' => 'AmericanTypewriter', + ), + array( + 'value' => 'AmericanTypewriter-Bold', + 'label' => 'AmericanTypewriter-Bold', + ), + array( + 'value' => 'Helvetica-Oblique', + 'label' => 'Helvetica-Oblique', + ), + array( + 'value' => 'Helvetica-BoldOblique', + 'label' => 'Helvetica-BoldOblique', + ), + array( + 'value' => 'Helvetica', + 'label' => 'Helvetica', + ), + array( + 'value' => 'Helvetica-Bold', + 'label' => 'Helvetica-Bold', + ), + array( + 'value' => 'MarkerFelt-Thin', + 'label' => 'MarkerFelt-Thin', + ), + array( + 'value' => 'HelveticaNeue', + 'label' => 'HelveticaNeue', + ), + array( + 'value' => 'HelveticaNeue-Bold', + 'label' => 'HelveticaNeue-Bold', + ), + array( + 'value' => 'DBLCDTempBlack', + 'label' => 'DBLCDTempBlack', + ), + array( + 'value' => 'Verdana-Bold', + 'label' => 'Verdana-Bold', + ), + array( + 'value' => 'Verdana-BoldItalic', + 'label' => 'Verdana-BoldItalic', + ), + array( + 'value' => 'Verdana', + 'label' => 'Verdana', + ), + array( + 'value' => 'Verdana-Italic', + 'label' => 'Verdana-Italic', + ), + array( + 'value' => 'TimesNewRomanPSMT', + 'label' => 'TimesNewRomanPSMT', + ), + array( + 'value' => 'TimesNewRomanPS-BoldMT', + 'label' => 'TimesNewRomanPS-BoldMT', + ), + array( + 'value' => 'TimesNewRomanPS-BoldItalicMT', + 'label' => 'TimesNewRomanPS-BoldItalicMT', + ), + array( + 'value' => 'TimesNewRomanPS-ItalicMT', + 'label' => 'TimesNewRomanPS-ItalicMT', + ), + array( + 'value' => 'Georgia-Bold', + 'label' => 'Georgia-Bold', + ), + array( + 'value' => 'Georgia', + 'label' => 'Georgia', + ), + array( + 'value' => 'Georgia-BoldItalic', + 'label' => 'Georgia-BoldItalic', + ), + array( + 'value' => 'Georgia-Italic', + 'label' => 'Georgia-Italic', + ), + array( + 'value' => 'STHeitiJ-Medium', + 'label' => 'STHeitiJ-Medium', + ), + array( + 'value' => 'STHeitiJ-Light', + 'label' => 'STHeitiJ-Light', + ), + array( + 'value' => 'ArialRoundedMTBold', + 'label' => 'ArialRoundedMTBold', + ), + array( + 'value' => 'TrebuchetMS-Italic', + 'label' => 'TrebuchetMS-Italic', + ), + array( + 'value' => 'TrebuchetMS', + 'label' => 'TrebuchetMS', + ), + array( + 'value' => 'Trebuchet-BoldItalic', + 'label' => 'Trebuchet-BoldItalic', + ), + array( + 'value' => 'TrebuchetMS-Bold', + 'label' => 'TrebuchetMS-Bold', + ), + array( + 'value' => 'STHeitiK-Medium', + 'label' => 'STHeitiK-Medium', + ), + array( + 'value' => 'STHeitiK-Light', + 'label' => 'STHeitiK-Light', + ), + ); + } + + /** + * List of allowed font sizes for Android application + * + * @return array + */ + public function getFontSizes() + { + $result = array( ); + for ($i = 6; $i < 32; $i++) { + $result[] = array( + 'value' => $i, + 'label' => $i . ' pt', + ); + } + return $result; + } +} diff --git a/app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php b/app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php index 0ff82fcd65..193d20de8b 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php +++ b/app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php @@ -27,11 +27,10 @@ /** * Catalog image helper * - * @author Magento Core Team + * @author Magento Core Team */ class Mage_XmlConnect_Helper_Catalog_Category_Image extends Mage_Catalog_Helper_Image { - /** * Init * @@ -90,6 +89,4 @@ public function getPlaceholder() } return $this->_placeholder; } - - } diff --git a/app/code/core/Mage/XmlConnect/Helper/Data.php b/app/code/core/Mage/XmlConnect/Helper/Data.php index 43099e1779..d51172d1da 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Data.php +++ b/app/code/core/Mage/XmlConnect/Helper/Data.php @@ -26,6 +26,120 @@ class Mage_XmlConnect_Helper_Data extends Mage_Core_Helper_Abstract { + /** + * Push title length + * + * @var int + */ + const PUSH_TITLE_LENGTH = 140; + + /** + * Message title length + * + * @var int + */ + const MESSAGE_TITLE_LENGTH = 255; + + protected $_excludedXmlConfigKeys = array( + 'notifications/applicationMasterSecret', + ); + + /** + * Application names array + * + * @var array + */ + protected $_appNames = array(); + + /** + * Template names array + * + * @var array + */ + protected $_tplNames = array(); + + /** + * XML path to nodes to be excluded + * + * @var string + */ + const XML_NODE_CONFIG_EXCLUDE_FROM_XML = 'xmlconnect/mobile_application/nodes_excluded_from_config_xml'; + + /** + * Default device type + * + * @var string + */ + const DEVICE_TYPE_DEFAULT = 'unknown'; + + /** + * iPhone device identifier + * + * @var string + */ + const DEVICE_TYPE_IPHONE = 'iphone'; + + /** + * iPad device identifier + * + * @var string + */ + const DEVICE_TYPE_IPAD = 'ipad'; + + /** + * Android device identifier + * + * @var string + */ + const DEVICE_TYPE_ANDROID = 'android'; + + /** + * Get device helper + * + * @throws Mage_Core_Exception + * @param Mage_XmlConnect_Model_Application $application + * @return Mage_Core_Helper_Abstract + */ + public function getDeviceHelper($application = null) + { + $deviceType = null; + if (empty($application)) { + $deviceType = (string) $this->getApplication()->getType(); + } elseif ($application instanceof Mage_XmlConnect_Model_Application) { + $deviceType = (string) $application->getType(); + } + if (empty($deviceType)) { + $deviceType = self::DEVICE_TYPE_DEFAULT; + } + switch ($deviceType) { + case self::DEVICE_TYPE_IPHONE: + case self::DEVICE_TYPE_IPAD: + case self::DEVICE_TYPE_ANDROID: + $helper = Mage::helper('xmlconnect/' . $deviceType); + break; + default: + Mage::throwException(Mage::helper('xmlconnect')->__('Device doesn\'t recognized: "%s". Unable to load a helper.', $deviceType)); + break; + } + return $helper; + } + + /** + * Getter for current loaded application model + * + * @throws Mage_Core_Exception + * @return Mage_XmlConnect_Model_Application + */ + public function getApplication() + { + $model = Mage::registry('current_app'); + if (!($model instanceof Mage_XmlConnect_Model_Application)) { + Mage::throwException(Mage::helper('xmlconnect')->__('App model not loaded.')); + } + + return $model; + } + /** * Create filter object by key * @@ -97,7 +211,9 @@ public function getCountryOptionsArray() static public function getSupportedDevices() { $devices = array ( - 'iphone' => Mage::helper('xmlconnect')->__('iPhone') + self::DEVICE_TYPE_IPAD => Mage::helper('xmlconnect')->__('iPad'), + self::DEVICE_TYPE_IPHONE => Mage::helper('xmlconnect')->__('iPhone'), + self::DEVICE_TYPE_ANDROID => Mage::helper('xmlconnect')->__('Android') ); return $devices; @@ -138,55 +254,17 @@ public function getDeviceTypeOptions() /** * Get default application tabs * + * @param string * @return array */ public function getDefaultApplicationDesignTabs() { - if (!isset($this->_tabs)) { - $this->_tabs = array( - array( - 'label' => Mage::helper('xmlconnect')->__('Home'), - 'image' => 'tab_home.png', - 'action' => 'Home', - ), - array( - 'label' => Mage::helper('xmlconnect')->__('Shop'), - 'image' => 'tab_shop.png', - 'action' => 'Shop', - ), - array( - 'label' => Mage::helper('xmlconnect')->__('Search'), - 'image' => 'tab_search.png', - 'action' => 'Search', - ), - array( - 'label' => Mage::helper('xmlconnect')->__('Cart'), - 'image' => 'tab_cart.png', - 'action' => 'Cart', - ), - array( - 'label' => Mage::helper('xmlconnect')->__('More'), - 'image' => 'tab_more.png', - 'action' => 'More', - ), - array( - 'label' => Mage::helper('xmlconnect')->__('Account'), - 'image' => 'tab_account.png', - 'action' => 'Account', - ), - array( - 'label' => Mage::helper('xmlconnect')->__('More Info'), - 'image' => 'tab_page.png', - 'action' => 'AboutUs', - ), - ); - } - return $this->_tabs; + return $this->getDeviceHelper()->getDefaultDesignTabs(); } /** * Return array for tabs like label -> action array - * + * * @return array */ protected function _getTabLabelActionArray() @@ -202,7 +280,7 @@ protected function _getTabLabelActionArray() /** * Return Translated tab label for given $action - * + * * @param string $action * @return string|bool */ @@ -215,7 +293,7 @@ public function getTabLabel($action) /** * Merges $changes array to $target array recursive, overwriting existing key, and adding new one - * + * * @param mixed $target * @param mixed $changes * @return array @@ -256,6 +334,7 @@ static public function arrayMergeRecursive($target, $changes) public function htmlize($body) { return << Mage::helper('xmlconnect')->__('Push message'), + Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL => Mage::helper('xmlconnect')->__('AirMail message'), + ); + + return $messages; + } + + /** + * Retrieve supported message types as "html select options" + * + * @return array + */ + public function getMessageTypeOptions() + { + $options = array(); + $messages = self::getSupportedMessageTypes(); + foreach ($messages as $type => $label) { + $options[] = array('value' => $type, 'label' => $label); + } + return $options; + } + + /** + * Get push title length + * + * @return int + */ + public function getPushTitleLength() + { + return self::PUSH_TITLE_LENGTH; + } + + /** + * Get message title length + * + * @return int + */ + public function getMessageTitleLength() + { + return self::MESSAGE_TITLE_LENGTH; + } + + /** + * Retrieve applications as "html select options" + * + * @return array + */ + public function getApplicationOptions() + { + $options = array(); + foreach (Mage::getModel('xmlconnect/application')->getCollection() as $app) { + if (self::isTemplateAllowedForApplication($app)) { + $options[] = array('value' => $app->getCode(), 'label' => $app->getName()); + } + } + if (count($options) > 1) { + $options[] = array('value' => '', 'label' => Mage::helper('xmlconnect')->__('Please Select Application')); + } + return $options; + } + + /** + * Get applications array like `code` as `name` + * + * @param + * @staticvar array $apps + * @return array + */ + public function getApplications() + { + static $apps = array(); + + if (empty($apps)) { + foreach (Mage::getModel('xmlconnect/application')->getCollection() as $app) { + $apps[$app->getCode()] = $app->getName(); + } + } + return $apps; + } + + /** + * Check if creating AirMail template for the application is allowed + * + * @param Mage_XmlConnect_Model_Application $application + * @return boolean + */ + public static function isTemplateAllowedForApplication($application = null) + { + return $application instanceof Mage_XmlConnect_Model_Application ? + in_array($application->getType(), array(self::DEVICE_TYPE_IPHONE)) : + false; + } + + /** + * Send broadcast message + * + * @param Mage_XmlConnect_Model_Queue $queue + */ + public function sendBroadcastMessage(Mage_XmlConnect_Model_Queue $queue) + { + if ($queue->getStatus() != Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) { + return; + } + + try { + $appCode = $queue->getAppCode(); + $app = Mage::getModel('xmlconnect/application')->load($appCode, 'code'); + + if (!$app->getId()) { + Mage::throwException(Mage::helper('xmlconnect')->__('Can\'t load application with code "%s"', $appCode)); + } + + $userpwd = $app->getUserpwd(); + + $sendType = $queue->getData('type'); + switch ($sendType) { + case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL: + $broadcastUrl = Mage::getStoreConfig('xmlconnect/' . Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL . '/broadcast_url'); + $params = $queue->getAirmailBroadcastParams(); + break; + + case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH: + default: + $broadcastUrl = Mage::getStoreConfig('xmlconnect/' . Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH . '/broadcast_url'); + $params = $queue->getPushBroadcastParams(); + break; + } + + $ch = curl_init($broadcastUrl); + + $httpHeaders = $this->getHttpHeaders(); + + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_USERPWD, $userpwd); + curl_setopt($ch, CURLOPT_TIMEOUT, 60); + + // Execute the request. + $result = curl_exec($ch); + $succeeded = curl_errno($ch) == 0 ? true : false; + + // close cURL resource, and free up system resources + curl_close($ch); + + if ($succeeded && (is_null($result) || strtolower($result) == 'null')) { + $queue->setStatus(Mage_XmlConnect_Model_Queue::STATUS_COMPLETED); + } + $queue->setIsSent(true); + + return; + } catch (Exception $e) { + Mage::logException($e); + throw $e; + } + } + + /** + * Get headers for broadcast message + * + * @return string + */ + public function getHttpHeaders() + { + $httpHeaders = array('Content-Type: application/json'); + return $httpHeaders; + } + + /** + * Remove from array the unnecessary parameters by given keys + * + * @param array $data Source array + * @param array $excludedKeys Keys to be excluded from array. Keys must be in xPath notation + * @return array + */ + public function excludeXmlConfigKeys($data, $excludedKeys = array()) + { + $excludedKeys = $this->getExcludedXmlConfigKeys(); + if (!empty($excludedKeys)) { + foreach ($excludedKeys as $keyToExclude) { + if (strpos($keyToExclude, '/')) { + $keys = array(); + foreach (explode('/', $keyToExclude) as $key) { + $key = trim($key); + if (!empty($key)) { + $keys[] = $key; + } + } + if (!empty($keys)) { + $keys = '$data["' . implode('"]["', $keys) . '"]'; + eval('if (isset(' . $keys . ')) unset(' . $keys . ');'); + } + } elseif (!empty($keyToExclude) && isset($data[$keyToExclude])) { + unset($data[$keyToExclude]); + } + } + } + return $data; + } + + /** + * Get excluded keys as array + * + * @return array + */ + public function getExcludedXmlConfigKeys() + { + $toExclude = Mage::getStoreConfig(self::XML_NODE_CONFIG_EXCLUDE_FROM_XML); + $nodes = array(); + foreach ($toExclude as $value) { + $nodes[] = trim($value, '/'); + } + + return $nodes; + } + + /** + * Returns Application name by it's code + * @param string $appCode + * @return string + */ + public function getApplicationName($appCode = null) + { + if (empty($appCode)) { + return ''; + } + if (!isset($this->_appNames[$appCode])) { + $app = Mage::getModel('xmlconnect/application')->loadByCode($appCode); + if ($app->getId()) { + $this->_appNames[$appCode] = $app->getName(); + } else { + return ''; + } + } + return $this->_appNames[$appCode]; + } + + /** + * Returns Application name by it's code + * @param string $appCode + * @return string + */ + public function getTemplateName($templateId = null) + { + if (empty($templateId)) { + return ''; + } + if (!isset($this->_tplNames[$templateId])) { + $template = Mage::getModel('xmlconnect/template')->load($templateId); + if ($template->getId()) { + $this->_tplNames[$templateId] = $template->getName(); + } else { + return ''; + } + } + return $this->_tplNames[$templateId]; + } + + /** + * Set value into multidimensional array 'conf/native/navigationBar/icon' + * + * @param &array $target // pointer to target array + * @param string $fieldPath // 'conf/native/navigationBar/icon' + * @param mixed $fieldValue // 'Some Value' || 12345 || array(1=>3, 'aa'=>43) + * @param string $delimiter // path delimiter + * @return null + */ + public function _injectFieldToArray(&$target, $fieldPath, $fieldValue, $delimiter = '/') + { + $nameParts = explode($delimiter, $fieldPath); + foreach ($nameParts as $next) { + if (!isset($target[$next])) { + $target[$next] = array(); + } + $target =& $target[$next]; + } + $target = $fieldValue; + return null; + } + + /** + * Convert Url link to file path for images + * + * @param string $icon + * @return string + */ + public function urlToPath($icon) + { + $baseUrl = Mage::getBaseUrl('media'); + $path = str_replace($baseUrl, '', $icon); + $filePath = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path); + return $filePath; + + } + + /** + * Validate config body field is not empty + * + * @param string $field + * @param array $native + * @return bool + */ + public function validateConfFieldNotEmpty($field, $native) + { + if ( ($native === false) + || (!isset($native['body']) || !is_array($native['body']) + || !isset($native['body'][$field]) + || !Zend_Validate::is($native['body'][$field], 'NotEmpty'))) { + return false; + } + return true; + } } diff --git a/app/code/core/Mage/XmlConnect/Helper/Image.php b/app/code/core/Mage/XmlConnect/Helper/Image.php index f182f4c19f..71a5c34636 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Image.php +++ b/app/code/core/Mage/XmlConnect/Helper/Image.php @@ -105,7 +105,7 @@ public function handleUpload($field, &$target) */ protected function _getScreenSize() { - return Mage::registry('current_app')->getScreenSize(); + return Mage::registry('current_app')->getScreenSize(); } /** @@ -201,7 +201,6 @@ protected function _handleResize($fieldPath, $file) $image->keepFrame(true); $image->keepAspectRatio(true); $image->backgroundColor(array(255, 255, 255)); -// $image->keepAspectRatio(false); $image->resize($width, $height); $image->save(null, basename($file)); } @@ -216,7 +215,7 @@ protected function _forcedConvertPng($field) { $file =& $_FILES[$field]; - $file['name'] = preg_replace('/\.(gif|jp[e]g)$/i', '.png', $file['name']); + $file['name'] = preg_replace('/\.(gif|jpeg|jpg)$/i', '.png', $file['name']); list($x, $x, $fileType) = getimagesize($file['tmp_name']); if ($fileType != IMAGETYPE_PNG ) { @@ -283,11 +282,11 @@ public function getFileCustomDirSuffixAsUrl($confPath, $fileName) /** * Return correct size for given $imageName and device screen_size - * + * * @param string $imageName * @return int */ - public function getImageSizeForContent($imageName) + public function getImageSizeForContent($imageName) { $size = 0; if (!isset($this->_content)) { @@ -303,13 +302,13 @@ public function getImageSizeForContent($imageName) } } } - $size = isset($this->_content[$imageName]) ? (int) $this->_content[$imageName] : 0; + $size = isset($this->_content[$imageName]) ? (int) $this->_content[$imageName] : 0; return $size; } /** * Return setting for interface images (image size limits) - * + * * @return array */ public function getInterfaceImageLimits() @@ -344,6 +343,45 @@ public function getImageSizeForInterface($imagePath) return $size; } + /** + * Retrieve thumbnail image url + * + * @param int $width + * @return string|null + */ + public function getCustomSizeImageUrl($imagePath, $width = 100, $height = 100) + { + $customDirRoot = Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'custom'; + $screenSize = $width . 'x' . $height; + $customDir = $customDirRoot . DS . $screenSize; + $this->_verifyDirExist($customDir); + $file = Mage::helper('xmlconnect')->getApplication()->getData($imagePath); + + if (!file_exists($customDir . basename($file))) { + $image = new Varien_Image($file); + $widthOriginal = $image->getOriginalWidth(); + $heightOriginal = $image->getOriginalHeight(); + + if ($width != $widthOriginal) { + $widthOriginal = $width; + } + + if ($height != $heightOriginal) { + $heightOriginal = $height; + } + + if (($widthOriginal != $image->getOriginalWidth()) || + ($heightOriginal != $image->getOriginalHeight()) ) { + $image->keepTransparency(true); + $image->keepFrame(true); + $image->keepAspectRatio(true); + $image->backgroundColor(array(255, 255, 255)); + $image->resize($widthOriginal, $heightOriginal); + $image->save($customDir, basename($file)); + } + } + return Mage::getBaseUrl('media') . "xmlconnect/custom/{$screenSize}/" . basename($file); + } /** * Ensure correct $screenSize value @@ -353,7 +391,6 @@ public function getImageSizeForInterface($imagePath) */ public function filterScreenSize($screenSize) { - $screenSize = preg_replace('/[^0-9A-z_]/', '', $screenSize); if (isset($this->_imageLimits[$screenSize])) { return $screenSize; @@ -379,14 +416,14 @@ public function filterScreenSize($screenSize) if (!empty($source)) { $screenSize = $resolution . (empty($version) ? '' : self::XMLCONNECT_GLUE.$version); } else { - $screenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT; + $screenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT; } return $screenSize; } /** * Return correct size array for given device screen_size(320x480/640x960_a) - * + * * @param string $screenSize * @return array */ @@ -473,13 +510,13 @@ public function getImageLimits($screenSize = Mage_XmlConnect_Model_Application:: $imageLimits = array(); } - $this->_imageLimits[$screenSize] = $imageLimits; + $this->_imageLimits[$screenSize] = $imageLimits; return $imageLimits; } /** * Return reference to the $path in $array - * + * * @param array $array * @param string $path * @return &mixed //(reference) @@ -546,7 +583,7 @@ public function getCustomSizeUploadDir($screenSize) /** * Return originalSizeUploadDir path - * + * * @return string */ public function getOriginalSizeUploadDir() @@ -558,7 +595,7 @@ public function getOriginalSizeUploadDir() /** * Return oldUpload dir path (media/xmlconnect) - * + * * @return string */ public function getOldUploadDir() @@ -570,7 +607,7 @@ public function getOldUploadDir() /** * Return default size upload dir path - * + * * @return string */ public function getDefaultSizeUploadDir() @@ -608,7 +645,12 @@ public function getInterfaceImagesPaths($imagePath = null) $paths = array ( 'conf/native/navigationBar/icon' => 'smallIcon_1_6.png', 'conf/native/body/bannerImage' => 'banner_1_2.png', + 'conf/native/body/bannerImageIpad' => 'banner_ipad.png', + 'conf/native/body/bannerImageAndroid' => 'banner_android.png', 'conf/native/body/backgroundImage' => 'accordion_open.png', + 'conf/native/body/backgroundImageIpadLandscape' => 'accordion_open_ipad_l.png', + 'conf/native/body/backgroundImageIpadPortret' => 'accordion_open_ipad_p.png', + 'conf/native/body/backgroundImageAndroid' => 'accordion_open_android.png', ); if ($imagePath == null) { return $paths; @@ -618,5 +660,4 @@ public function getInterfaceImagesPaths($imagePath = null) return null; } } - } diff --git a/app/code/core/Mage/XmlConnect/Helper/Ipad.php b/app/code/core/Mage/XmlConnect/Helper/Ipad.php new file mode 100755 index 0000000000..fbe46b1d4b --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Helper/Ipad.php @@ -0,0 +1,442 @@ +_tabs)) { + $this->_tabs = array( + array( + 'label' => Mage::helper('xmlconnect')->__('Home'), + 'image' => 'tab_home.png', + 'action' => 'Home', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Shop'), + 'image' => 'tab_shop.png', + 'action' => 'Shop', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Search'), + 'image' => 'tab_search.png', + 'action' => 'Search', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Cart'), + 'image' => 'tab_cart.png', + 'action' => 'Cart', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Account'), + 'image' => 'tab_account_ipad.png', + 'action' => 'Account', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('More Info'), + 'image' => 'tab_page.png', + 'action' => 'AboutUs', + ), + ); + } + return $this->_tabs; + } + + /** + * Default application configuration + * + * @return array + */ + public function getDefaultConfiguration() + { + return array( + 'native' => array( + 'body' => array( + 'backgroundColor' => '#ABABAB', + 'scrollBackgroundColor' => '#EDEDED', + ), + 'itemActions' => array( + 'relatedProductBackgroundColor' => '#404040', + ), + 'fonts' => array( + 'Title1' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '14', + 'color' => '#FEFEFE', + ), + 'Title2' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '12', + 'color' => '#222222', + ), + 'Title3' => array( + 'name' => 'HelveticaNeue', + 'size' => '23', + 'color' => '#000000', + ), + 'Title4' => array( + 'name' => 'HelveticaNeue', + 'size' => '12', + 'color' => '#FFFFFF', + ), + 'Title5' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '13', + 'color' => '#dc5f02', + ), + 'Title6' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '16', + 'color' => '#222222', + ), + 'Title7' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '13', + 'color' => '#000000', + ), + 'Title8' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '11', + 'color' => '#FFFFFF', + ), + 'Title9' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '12', + 'color' => '#FFFFFF', + ), + 'Text1' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '12', + 'color' => '#777777', + ), + 'Text2' => array( + 'name' => 'HelveticaNeue', + 'size' => '10', + 'color' => '#555555', + ), + ), + ), + ); + } + + /** + * List of allowed fonts for iPad application + * + * @return array + */ + public function getFontList() + { + return array( + array( + 'value' => 'HiraKakuProN-W3', + 'label' => 'HiraKakuProN-W3', + ), + array( + 'value' => 'Courier', + 'label' => 'Courier', + ), + array( + 'value' => 'Courier-BoldOblique', + 'label' => 'Courier-BoldOblique', + ), + array( + 'value' => 'Courier-Oblique', + 'label' => 'Courier-Oblique', + ), + array( + 'value' => 'Courier-Bold', + 'label' => 'Courier-Bold', + ), + array( + 'value' => 'ArialMT', + 'label' => 'ArialMT', + ), + array( + 'value' => 'Arial-BoldMT', + 'label' => 'Arial-BoldMT', + ), + array( + 'value' => 'Arial-BoldItalicMT', + 'label' => 'Arial-BoldItalicMT', + ), + array( + 'value' => 'Arial-ItalicMT', + 'label' => 'Arial-ItalicMT', + ), + array( + 'value' => 'STHeitiTC-Light', + 'label' => 'STHeitiTC-Light', + ), + array( + 'value' => 'STHeitiTC-Medium', + 'label' => 'STHeitiTC-Medium', + ), + array( + 'value' => 'AppleGothic', + 'label' => 'AppleGothic', + ), + array( + 'value' => 'CourierNewPS-BoldMT', + 'label' => 'CourierNewPS-BoldMT', + ), + array( + 'value' => 'CourierNewPS-ItalicMT', + 'label' => 'CourierNewPS-ItalicMT', + ), + array( + 'value' => 'CourierNewPS-BoldItalicMT', + 'label' => 'CourierNewPS-BoldItalicMT', + ), + array( + 'value' => 'CourierNewPSMT', + 'label' => 'CourierNewPSMT', + ), + array( + 'value' => 'Zapfino', + 'label' => 'Zapfino', + ), + array( + 'value' => 'HiraKakuProN-W6', + 'label' => 'HiraKakuProN-W6', + ), + array( + 'value' => 'ArialUnicodeMS', + 'label' => 'ArialUnicodeMS', + ), + array( + 'value' => 'STHeitiSC-Medium', + 'label' => 'STHeitiSC-Medium', + ), + array( + 'value' => 'STHeitiSC-Light', + 'label' => 'STHeitiSC-Light', + ), + array( + 'value' => 'AmericanTypewriter', + 'label' => 'AmericanTypewriter', + ), + array( + 'value' => 'AmericanTypewriter-Bold', + 'label' => 'AmericanTypewriter-Bold', + ), + array( + 'value' => 'Helvetica-Oblique', + 'label' => 'Helvetica-Oblique', + ), + array( + 'value' => 'Helvetica-BoldOblique', + 'label' => 'Helvetica-BoldOblique', + ), + array( + 'value' => 'Helvetica', + 'label' => 'Helvetica', + ), + array( + 'value' => 'Helvetica-Bold', + 'label' => 'Helvetica-Bold', + ), + array( + 'value' => 'MarkerFelt-Thin', + 'label' => 'MarkerFelt-Thin', + ), + array( + 'value' => 'HelveticaNeue', + 'label' => 'HelveticaNeue', + ), + array( + 'value' => 'HelveticaNeue-Bold', + 'label' => 'HelveticaNeue-Bold', + ), + array( + 'value' => 'DBLCDTempBlack', + 'label' => 'DBLCDTempBlack', + ), + array( + 'value' => 'Verdana-Bold', + 'label' => 'Verdana-Bold', + ), + array( + 'value' => 'Verdana-BoldItalic', + 'label' => 'Verdana-BoldItalic', + ), + array( + 'value' => 'Verdana', + 'label' => 'Verdana', + ), + array( + 'value' => 'Verdana-Italic', + 'label' => 'Verdana-Italic', + ), + array( + 'value' => 'TimesNewRomanPSMT', + 'label' => 'TimesNewRomanPSMT', + ), + array( + 'value' => 'TimesNewRomanPS-BoldMT', + 'label' => 'TimesNewRomanPS-BoldMT', + ), + array( + 'value' => 'TimesNewRomanPS-BoldItalicMT', + 'label' => 'TimesNewRomanPS-BoldItalicMT', + ), + array( + 'value' => 'TimesNewRomanPS-ItalicMT', + 'label' => 'TimesNewRomanPS-ItalicMT', + ), + array( + 'value' => 'Georgia-Bold', + 'label' => 'Georgia-Bold', + ), + array( + 'value' => 'Georgia', + 'label' => 'Georgia', + ), + array( + 'value' => 'Georgia-BoldItalic', + 'label' => 'Georgia-BoldItalic', + ), + array( + 'value' => 'Georgia-Italic', + 'label' => 'Georgia-Italic', + ), + array( + 'value' => 'STHeitiJ-Medium', + 'label' => 'STHeitiJ-Medium', + ), + array( + 'value' => 'STHeitiJ-Light', + 'label' => 'STHeitiJ-Light', + ), + array( + 'value' => 'ArialRoundedMTBold', + 'label' => 'ArialRoundedMTBold', + ), + array( + 'value' => 'TrebuchetMS-Italic', + 'label' => 'TrebuchetMS-Italic', + ), + array( + 'value' => 'TrebuchetMS', + 'label' => 'TrebuchetMS', + ), + array( + 'value' => 'Trebuchet-BoldItalic', + 'label' => 'Trebuchet-BoldItalic', + ), + array( + 'value' => 'TrebuchetMS-Bold', + 'label' => 'TrebuchetMS-Bold', + ), + array( + 'value' => 'STHeitiK-Medium', + 'label' => 'STHeitiK-Medium', + ), + array( + 'value' => 'STHeitiK-Light', + 'label' => 'STHeitiK-Light', + ), + ); + } + + /** + * List of allowed font sizes for iPad application + * + * @return array + */ + public function getFontSizes() + { + $result = array( ); + for ($i = 6; $i < 32; $i++) { + $result[] = array( + 'value' => $i, + 'label' => $i . ' pt', + ); + } + return $result; + } +} diff --git a/app/code/core/Mage/XmlConnect/Helper/Iphone.php b/app/code/core/Mage/XmlConnect/Helper/Iphone.php index 1cf20fb9e5..890e9d2ae5 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Iphone.php +++ b/app/code/core/Mage/XmlConnect/Helper/Iphone.php @@ -26,6 +26,57 @@ class Mage_XmlConnect_Helper_Iphone extends Mage_Core_Helper_Abstract { + + /** + * Get default application tabs + * + * @param string + * @return array + */ + public function getDefaultDesignTabs() + { + if (!isset($this->_tabs)) { + $this->_tabs = array( + array( + 'label' => Mage::helper('xmlconnect')->__('Home'), + 'image' => 'tab_home.png', + 'action' => 'Home', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Shop'), + 'image' => 'tab_shop.png', + 'action' => 'Shop', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Search'), + 'image' => 'tab_search.png', + 'action' => 'Search', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Cart'), + 'image' => 'tab_cart.png', + 'action' => 'Cart', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('More'), + 'image' => 'tab_more.png', + 'action' => 'More', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('Account'), + 'image' => 'tab_account.png', + 'action' => 'Account', + ), + array( + 'label' => Mage::helper('xmlconnect')->__('More Info'), + 'image' => 'tab_page.png', + 'action' => 'AboutUs', + ), + ); + } + return $this->_tabs; + } + /** * Default application configuration * diff --git a/app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Baseurl.php b/app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Baseurl.php index cbebbf51a7..2827d17793 100644 --- a/app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Baseurl.php +++ b/app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Baseurl.php @@ -24,7 +24,6 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - class Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Baseurl extends Mage_Adminhtml_Model_System_Config_Backend_Baseurl { /** diff --git a/app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Currency/Default.php b/app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Currency/Default.php index 36749aa27b..43bad9e22e 100644 --- a/app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Currency/Default.php +++ b/app/code/core/Mage/XmlConnect/Model/Adminhtml/System/Config/Backend/Currency/Default.php @@ -24,7 +24,6 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - class Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Currency_Default extends Mage_Adminhtml_Model_System_Config_Backend_Currency_Default { /** diff --git a/app/code/core/Mage/XmlConnect/Model/Application.php b/app/code/core/Mage/XmlConnect/Model/Application.php index 20d60294a8..50cadfc731 100644 --- a/app/code/core/Mage/XmlConnect/Model/Application.php +++ b/app/code/core/Mage/XmlConnect/Model/Application.php @@ -24,7 +24,6 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * @method Mage_XmlConnect_Model_Mysql4_Application _getResource() * @method Mage_XmlConnect_Model_Mysql4_Application getResource() @@ -54,25 +53,31 @@ */ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract { - /** * Application code cookie name + * + * @var string */ const APP_CODE_COOKIE_NAME = 'app_code'; /** * Device screen size name + * + * @var string */ const APP_SCREEN_SIZE_NAME = 'screen_size'; - /** * Device screen size name + * + * @var string */ const APP_SCREEN_SIZE_DEFAULT = '320x480'; /** * Device screen size source name + * + * @var string */ const APP_SCREEN_SOURCE_DEFAULT = 'default'; @@ -104,9 +109,92 @@ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract */ protected $_imageIds = array('icon', 'loader_image', 'logo', 'big_logo'); + /** + * Last submitted data from history table + * + * @var null|array + */ + protected $_lastParams; + + /** + * Application submit info + * + * @var array + */ + protected $submit_params = array(); + + /** + * Application submit action type + * + * @var bool + */ + protected $is_resubmit_action = false; + + /** + * Full application code + * + * @var null|string + */ + protected $code; + + /** + * Main configuration of current application + * + * @var null|array + */ + protected $conf; + + /** + * Submission/Resubmission key max length + * + * @var int + */ + const APP_MAX_KEY_LENGTH = 40; + + /** + * XML path to config with an email address + * for contact to receive credentials + * of Urban Airship notifications + * + * @var string + */ + const XML_PATH_CONTACT_CREDENTIALS_EMAIL = 'xmlconnect/mobile_application/urbanairship_credentials_email'; + + /** + * XML path to config with Urban Airship Terms of Service URL + * + * @var string + */ + const XML_PATH_URBAN_AIRSHIP_TOS_URL = 'xmlconnect/mobile_application/urbanairship_terms_of_service_url'; + + /** + * XML path to config copyright data + * + * @var string + */ + const XML_PATH_DESIGN_FOOTER_COPYRIGHT = 'design/footer/copyright'; + + /** + * XML path to config restriction status + * (EE module) + * + * @var string + */ + const XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE = 'general/restriction/is_active'; + + /** + * XML path to config restriction mode + * (EE module) + * + * @var string + */ + const XML_PATH_GENERAL_RESTRICTION_MODE = 'general/restriction/mode'; + /** * Initialize application + * + * @return void */ protected function _construct() { @@ -168,7 +256,7 @@ protected function _flatArray($subtree, $prefix=null) * @param array $b * @return array */ - protected function _configMerge (array $a, array $b) + protected function _configMerge(array $a, array $b) { $result = array(); $keys = array_unique(array_merge(array_keys($a), array_keys($b))); @@ -188,12 +276,13 @@ protected function _configMerge (array $a, array $b) /** * Set default configuration data + * + * @return void */ public function loadDefaultConfiguration() { - $this->setType('iphone'); $this->setCode($this->getCodePrefix()); - $this->setConf(Mage::helper('xmlconnect/iphone')->getDefaultConfiguration()); + $this->setConf(Mage::helper('xmlconnect')->getDeviceHelper()->getDefaultConfiguration()); } /** @@ -235,7 +324,7 @@ public function prepareConfiguration() */ public function getRenderConf() { - $result = Mage::helper('xmlconnect/iphone')->getDefaultConfiguration(); + $result = Mage::helper('xmlconnect')->getDeviceHelper()->getDefaultConfiguration(); $result = $result['native']; $extra = array(); if (isset($this->_data['conf'])) { @@ -290,23 +379,29 @@ public function getRenderConf() $result['general']['updateTimeUTC'] = strtotime($this->getUpdatedAt()); $result['general']['browsingMode'] = $this->getBrowsingMode(); $result['general']['currencyCode'] = Mage::app()->getStore($this->getStoreId())->getDefaultCurrencyCode(); - $result['general']['secureBaseUrl'] = Mage::getStoreConfig('web/secure/base_url', $this->getStoreId()); + $result['general']['secureBaseUrl'] = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $this->getStoreId()); $maxRecipients = 0; $allowGuest = 0; - if (Mage::getStoreConfig('sendfriend/email/enabled')) { - $maxRecipients = Mage::getStoreConfig('sendfriend/email/max_recipients'); - $allowGuest = Mage::getStoreConfig('sendfriend/email/allow_guest'); + if (Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_ENABLED)) { + $maxRecipients = Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_MAX_RECIPIENTS); + $allowGuest = Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_ALLOW_FOR_GUEST); } $result['general']['emailToFriendMaxRecepients'] = $maxRecipients; $result['general']['emailAllowGuest'] = $allowGuest; $result['general']['primaryStoreLang'] = Mage::app() ->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE); $result['general']['magentoVersion'] = Mage::getVersion(); - $result['general']['copyright'] = Mage::getStoreConfig('design/footer/copyright', $this->getStoreId()); + $result['general']['copyright'] = Mage::getStoreConfig(self::XML_PATH_DESIGN_FOOTER_COPYRIGHT, $this->getStoreId()); $result['general']['isAllowedGuestCheckout'] = Mage::getSingleton('checkout/session') ->getQuote()->isAllowedGuestCheckout(); + if (!Mage::getStoreConfigFlag('wishlist/general/active')) { + $result['general']['wishlistEnable'] = '0'; + } else { + $result['general']['wishlistEnable'] = '1'; + } + /** * PayPal configuration */ @@ -315,10 +410,14 @@ public function getRenderConf() $isActive = 0; if (isset($result['paypal']) && isset($result['paypal']['isActive'])) { - $isActive = (int)($result['paypal']['isActive'] && Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null, $this->getStoreId())); + $isActive = (int)($result['paypal']['isActive'] && Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null)); } $result['paypal']['isActive'] = $isActive; + if ((int)Mage::getStoreConfig(self::XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE)) { + $result['website_restrictions']['mode'] = (int) Mage::getStoreConfig(self::XML_PATH_GENERAL_RESTRICTION_MODE); + } + return $result; } @@ -416,10 +515,15 @@ protected function _beforeSave() */ public function loadConfiguration() { - $configuration = $this->getConfiguration(); - if (!empty($configuration)) { - $configuration = unserialize($configuration); - $this->setData('conf', $configuration); + static $isConfigurationLoaded = null; + + if (is_null($isConfigurationLoaded)) { + $configuration = $this->getConfiguration(); + if (!empty($configuration)) { + $configuration = unserialize($configuration); + $this->setData('conf', $configuration); + $isConfigurationLoaded = true; + } } return $this; } @@ -557,6 +661,17 @@ public function validateSubmit($params) $errors[] = Mage::helper('xmlconnect')->__('Please enter the Title.'); } + if (isset($params['title'])) { + if ($this->getType() == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE) { + $strRules = array('max' => '12'); + } else { + $strRules = array('max' => '200'); + } + if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) { + $errors[] = Mage::helper('xmlconnect')->__('"Title" is more than %d characters long', $strRules['max']); + } + } + if (!Zend_Validate::is(isset($params['copyright']) ? $params['copyright'] : null, 'NotEmpty')) { $errors[] = Mage::helper('xmlconnect')->__('Please enter the Copyright.'); } @@ -572,14 +687,18 @@ public function validateSubmit($params) } if ($this->getIsResubmitAction()) { - if (!Zend_Validate::is( - isset($params['resubmission_activation_key']) ? $params['resubmission_activation_key'] : null, - 'NotEmpty')) { + $resubmissionKey = isset($params['resubmission_activation_key']) ? $params['resubmission_activation_key'] : null; + if (!Zend_Validate::is($resubmissionKey, 'NotEmpty')) { $errors[] = Mage::helper('xmlconnect')->__('Please enter the Resubmission Key.'); + } else if (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, self::APP_MAX_KEY_LENGTH))) { + $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided'); } } else { - if (!Zend_Validate::is(isset($params['key']) ? $params['key'] : null, 'NotEmpty')) { - $errors[] = Mage::helper('xmlconnect')->__('Please enter the Activation Key.'); + $key = isset($params['key']) ? $params['key'] : null; + if (!Zend_Validate::is($key, 'NotEmpty')) { + $errors[] = Mage::helper('xmlconnect')->__('Please enter the Activation Key.'); + } else if (!Zend_Validate::is($key, 'StringLength', array(1, self::APP_MAX_KEY_LENGTH))) { + $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided'); } } @@ -592,6 +711,7 @@ public function validateSubmit($params) /** * Check config for valid values * + * @throws Mage_Core_Exception * @return bool|array */ protected function _validateConf() @@ -607,18 +727,42 @@ protected function _validateConf() $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Logo in Header" field from Design Tab.'); } - if ( ($native === false) - || (!isset($native['body']) || !is_array($native['body']) - || !isset($native['body']['bannerImage']) - || !Zend_Validate::is($native['body']['bannerImage'], 'NotEmpty'))) { - $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen" field from Design Tab.'); - } + $deviceType = Mage::helper('xmlconnect')->getApplication()->getType(); + switch ($deviceType) { + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE: + if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('bannerImage', $native)) { + $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen" field from Design Tab.'); + } - if (($native === false) - || (!isset($native['body']) || !is_array($native['body']) - || !isset($native['body']['backgroundImage']) - || !Zend_Validate::is($native['body']['backgroundImage'], 'NotEmpty'))) { - $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "App Background" field from Design Tab.'); + if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('backgroundImage', $native)) { + $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "App Background" field from Design Tab.'); + } + break; + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD: + if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('bannerImageIpad', $native)) { + $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen" field from Design Tab.'); + } + + if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('backgroundImageIpadLandscape', $native)) { + $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "App Background (landscape mode)" field from Design Tab.'); + } + + if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('backgroundImageIpadPortret', $native)) { + $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "App Background (portrait mode)" field from Design Tab.'); + } + break; + case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID: + if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('bannerImageAndroid', $native)) { + $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen" field from Design Tab.'); + } + + if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('backgroundImageAndroid', $native)) { + $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "App Background" field from Design Tab.'); + } + break; + default: + Mage::throwException(Mage::helper('xmlconnect')->__('Device doesn\'t recognized: "%s". Unable to load a helper.', $deviceType)); + break; } if (empty($errors)) { @@ -635,7 +779,6 @@ protected function _validateConf() */ public function prepareSubmitParams($data) { - $params = array(); if (isset($data['conf']) && is_array($data['conf'])) { @@ -646,7 +789,12 @@ public function prepareSubmitParams($data) $params['name'] = $this->getName(); $params['code'] = $this->getCode(); $params['type'] = $this->getType(); - $params['url'] = Mage::getBaseUrl() . 'xmlconnect/configuration/index/app_code/' . $this->getCode(); + $params['url'] = Mage::getUrl('xmlconnect/configuration/index', array( + '_store' => $this->getStoreId(), + '_nosid' => true, + 'app_code' => $this->getCode() + )); + $params['magentoversion'] = Mage::getVersion(); if (isset($params['country']) && is_array($params['country'])) { @@ -709,7 +857,6 @@ public function getActivationKey() if (isset($this->_data['conf']) && is_array($this->_data['conf']) && isset($this->_data['conf']['submit_text']) && is_array($this->_data['conf']['submit_text']) && isset($this->_data['conf']['submit_text']['key'])) { - $key = $this->_data['conf']['submit_text']['key']; } return $key; @@ -725,4 +872,44 @@ public function updateAllAppsUpdatedAtParameter() $this->_getResource()->updateAllAppsUpdatedAtParameter(); return $this; } + + /** + * Getter return concatenated user and password + * + * @return string + */ + public function getUserpwd() + { + return $this->loadConfiguration()->getAppKey() . ':' . $this->getAppMasterSecret(); + } + + /** + * Getter for Application Key + * + * @return string + */ + public function getAppKey() + { + return $this->getData('conf/native/notifications/applicationKey'); + } + + /** + * Getter for Application Secret + * + * @return string + */ + public function getAppSecret() + { + return $this->getData('conf/native/notifications/applicationSecret'); + } + + /** + * Getter for Application Master Secret + * + * @return string + */ + public function getAppMasterSecret() + { + return $this->getData('conf/native/notifications/applicationMasterSecret'); + } } diff --git a/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php b/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php index 7753cae571..bcbef70361 100644 --- a/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php +++ b/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php @@ -29,11 +29,10 @@ * * @category Mage * @package Mage_Catalog - * @author Magento Core Team + * @author Magento Core Team */ class Mage_XmlConnect_Model_Catalog_Category_Image extends Mage_Catalog_Model_Product_Image { - /** * Set filenames for base file and new file * @@ -162,6 +161,8 @@ protected function _getWatermarkFilePath() /** * Clear catalog cache + * + * @return void */ public function clearCache() { diff --git a/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Media/Config.php b/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Media/Config.php index cce12e6e7f..6ecb4ebd65 100644 --- a/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Media/Config.php +++ b/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Media/Config.php @@ -24,7 +24,6 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Catalog category media config * @@ -35,7 +34,7 @@ class Mage_XmlConnect_Model_Catalog_Category_Media_Config extends Mage_Catalog_Model_Product_Media_Config { /** - * Getter , return Catalog baseMediaPath + * Getter, return Catalog baseMediaPath * * @return string */ @@ -73,5 +72,4 @@ public function getBaseTmpMediaUrl() { return Mage::getBaseUrl('media') . 'tmp/catalog/category'; } - } diff --git a/app/code/core/Mage/XmlConnect/Model/History.php b/app/code/core/Mage/XmlConnect/Model/History.php index 19e10dd801..30e49b92dd 100644 --- a/app/code/core/Mage/XmlConnect/Model/History.php +++ b/app/code/core/Mage/XmlConnect/Model/History.php @@ -23,6 +23,7 @@ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * @method Mage_XmlConnect_Model_Mysql4_History _getResource() * @method Mage_XmlConnect_Model_Mysql4_History getResource() @@ -45,6 +46,8 @@ class Mage_XmlConnect_Model_History extends Mage_Core_Model_Abstract { /** * Initialize application + * + * @return void */ protected function _construct() { diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php index a42814d38a..c45d96db9f 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php @@ -27,6 +27,8 @@ class Mage_XmlConnect_Model_Mysql4_Application extends Mage_Core_Model_Mysql4_Ab { /** * Constructor, setting table and index field + * + * @return void */ protected function _construct() { diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php index 9e94ea516e..bc2285828d 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php @@ -27,6 +27,8 @@ class Mage_XmlConnect_Model_Mysql4_Application_Collection extends Mage_Core_Mode { /** * Constructor, setting table + * + * @return void */ protected function _construct() { diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/History.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/History.php index ec2a49a662..257823525d 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/History.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/History.php @@ -27,11 +27,12 @@ class Mage_XmlConnect_Model_Mysql4_History extends Mage_Core_Model_Mysql4_Abstra { /** * Constructor, setting table and index field + * + * @return void */ protected function _construct() { $this->_init('xmlconnect/history', 'history_id'); - } /** @@ -62,7 +63,6 @@ protected function _afterLoad(Mage_Core_Model_Abstract $object) * Returns array of existing images * * @param int $id - application instance Id - * * @return array */ public function getLastParams($id) @@ -81,5 +81,4 @@ public function getLastParams($id) } return $paramArray; } - } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php index 4c727d9e75..3539764f86 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php @@ -30,7 +30,7 @@ * * @category Mage * @package Mage_XmlConnect - * @author Magento Core Team + * @author Magento Core Team */ class Mage_XmlConnect_Model_Mysql4_History_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php new file mode 100755 index 0000000000..404d258d01 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php @@ -0,0 +1,37 @@ +_init('xmlconnect/queue', 'id'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php new file mode 100755 index 0000000000..353e3930c3 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php @@ -0,0 +1,103 @@ + + */ +class Mage_XmlConnect_Model_Mysql4_Queue_Collection + extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + /** + * Internal constructor + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/queue'); + } + + /** + * Initialize collection select + * + * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->_joinTemplateName() + ->_joinApplicationName(); + return $this; + } + + /** + * Join Template Name to collection + * + * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection + */ + protected function _joinTemplateName() + { + $this->getSelect() + ->joinLeft(array('t' => $this->getTable('xmlconnect/template')), 't.id = template_id', array( + 'template_name' => 't.name', + )); + return $this; + } + + /** + * Join Application Name to collection + * + * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection + */ + protected function _joinApplicationName() + { + $this->getSelect() + ->joinLeft(array('app' => $this->getTable('xmlconnect/application')), 'app.code = main_table.app_code', array( + 'application_name' => 'app.name', + )); + return $this; + } + + /** + * Add filter by only ready fot sending item + * + * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection + */ + public function addOnlyForSendingFilter() + { + $this->getSelect() + ->where('main_table.status in (?)', array(Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE)) + ->where('main_table.exec_time < ?', Mage::getSingleton('core/date')->gmtDate()) + ->order(new Zend_Db_Expr('main_table.exec_time ' . Zend_Db_Select::SQL_ASC)); + + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php new file mode 100755 index 0000000000..691632aa5a --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php @@ -0,0 +1,37 @@ +_init('xmlconnect/template', 'id'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php new file mode 100755 index 0000000000..a1810df109 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php @@ -0,0 +1,72 @@ + + */ +class Mage_XmlConnect_Model_Mysql4_Template_Collection + extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + /** + * Internal constructor + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/template'); + } + + /** + * Initialize collection select + * + * @return Mage_XmlConnect_Model_Mysql4_Template_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->_joinApplicationName(); + return $this; + } + + /** + * Join Application Name to collection + * + * @return Mage_XmlConnect_Model_Mysql4_Template_Collection + */ + protected function _joinApplicationName() + { + $this->getSelect() + ->joinLeft(array('app' => $this->getTable('xmlconnect/application')), 'app.code = app_code', array( + 'app_name' => 'app.name', + )); + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Observer.php b/app/code/core/Mage/XmlConnect/Model/Observer.php index a49b2afbb7..0955974c0b 100644 --- a/app/code/core/Mage/XmlConnect/Model/Observer.php +++ b/app/code/core/Mage/XmlConnect/Model/Observer.php @@ -44,6 +44,18 @@ class Mage_XmlConnect_Model_Observer 'currency/options/default' ); + /** + * Stop website stub or private sales restriction + * + * @param Varien_Event_Observer $observer + */ + public function restrictWebsite($observer) + { + if (Mage::app()->getRequest()->getModuleName() == 'xmlconnect') { + $observer->getEvent()->getResult()->setShouldProceed(false); + } + } + /** * Update all applications "updated at" parameter with current date on save some configurations * @@ -52,8 +64,57 @@ class Mage_XmlConnect_Model_Observer public function changeUpdatedAtParamOnConfigSave($observer) { $configData = $observer->getEvent()->getConfigData(); - if ($configData && (int)$configData->isValueChanged() && in_array($configData->getPath(), $this->_appDependOnConfigFieldPathes)) { + if ($configData + && (int)$configData->isValueChanged() + && in_array($configData->getPath(), $this->_appDependOnConfigFieldPathes) + ) + { Mage::getModel('xmlconnect/application')->updateAllAppsUpdatedAtParameter(); } } + + /** + * Send a message if Start Date (Queue Date) is empty + * + * @param Varien_Event_Observer $observer + */ + public function sendMessageImmediately($observer) + { + $message = $observer->getEvent()->getData('queueMessage'); + if ($message instanceof Mage_XmlConnect_Model_Queue + && (strtolower($message->getExecTime()) == 'null' + || !$message->getExecTime() + ) + ) + { + $message->setExecTime(Mage::getSingleton('core/date')->gmtDate()); + Mage::helper('xmlconnect')->sendBroadcastMessage($message); + return true; + } + + return false; + } + + /** + * Send sheduled messages + * + * @param mixed $schedule + */ + public function scheduledSend($schedule = null) + { + $countOfQueue = Mage::getStoreConfig(Mage_XmlConnect_Model_Queue::XML_PATH_CRON_MESSAGES_COUNT); + + $collection = Mage::getModel('xmlconnect/queue')->getCollection() + ->addOnlyForSendingFilter() + ->setPageSize($countOfQueue) + ->setCurPage(1) + ->load(); + + foreach ($collection as $message) { + if ($message->getId()) { + Mage::helper('xmlconnect')->sendBroadcastMessage($message); + $message->save(); + } + } + } } diff --git a/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mep.php b/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mep.php index 384c169a9b..eac72efb4b 100644 --- a/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mep.php +++ b/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mep.php @@ -37,6 +37,11 @@ class Mage_XmlConnect_Model_Payment_Method_Paypal_Mep extends Mage_Paypal_Model_ */ const MEP_METHOD_CODE = 'paypal_mep'; + /** + * Payment method code + * + * @var string + */ protected $_code = self::MEP_METHOD_CODE; protected $_canUseInternal = false; @@ -64,8 +69,19 @@ public function getConfigPaymentAction() */ public function isAvailable($quote = null) { + $storeId = false; + $model = Mage::registry('current_app'); + + if (($model instanceof Mage_XmlConnect_Model_Application)) { + $storeId = $model->getStoreId(); + } + + if (!$storeId) { + $storeId = $quote ? $quote->getStoreId() : Mage::app()->getStore()->getId(); + } + return Mage::getModel('paypal/config') - ->setStoreId(Mage::app()->getStore()->getId()) + ->setStoreId($storeId) ->isMethodAvailable(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS); } diff --git a/app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php b/app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php index aeef37f69b..92cb6de107 100644 --- a/app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php +++ b/app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php @@ -41,7 +41,7 @@ class Mage_XmlConnect_Model_Paypal_Mep_Checkout /** * Payment method type * - * @var unknown_type + * @var string */ protected $_methodType = Mage_XmlConnect_Model_Payment_Method_Paypal_Mep::MEP_METHOD_CODE; @@ -62,8 +62,10 @@ class Mage_XmlConnect_Model_Paypal_Mep_Checkout /** * Set quote instances - * + * + * @throws Mage_Core_Exception * @param array $params + * @return void */ public function __construct($params = array()) { @@ -270,6 +272,8 @@ public function getLastOrderId() /** * Make sure addresses will be saved without validation errors + * + * @return void */ protected function _ignoreAddressValidation() { diff --git a/app/code/core/Mage/XmlConnect/Model/Queue.php b/app/code/core/Mage/XmlConnect/Model/Queue.php new file mode 100755 index 0000000000..fb22a7218e --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Queue.php @@ -0,0 +1,296 @@ +_init('xmlconnect/queue'); + } + + /** + * Load object data + * + * @param integer $id + * @return Mage_Core_Model_Abstract + */ + public function load($id, $field=null) + { + parent::load($id, $field); + + if ($this->getTemplateId()) { + $this->setName( + Mage::getModel('xmlconnect/template')->load($this->getTemplateId())->getName() + ); + } + return $this; + } + + /** + * Get template type + * + * @return int + */ + public function getType() + { + return self::TYPE_HTML; + } + + /** + * Getter for application type + * @return string + */ + public function getApplicationType() + { + if (empty($this->_appType) && $this->getAppCode()) { + $app = Mage::getModel('xmlconnect/application')->loadByCode($this->getAppCode()); + $this->_appType = $app->getId() ? $app->getType() : null; + } + + return $this->_appType; + } + + /** + * Getter for application name + * + * @return string + */ + public function getAppName() + { + return $this->getApplicationName() ? $this->getApplicationName() : Mage::helper('xmlconnect')->getApplicationName($this->getAppCode()); + } + + /** + * Getter for template name + * + * @return string + */ + public function getTplName() + { + return $this->getTemplateName() ? $this->getTemplateName() : Mage::helper('xmlconnect')->getTemplateName($this->getTemplateId()); + } + + /** + * Retrieve processed template + * + * @param array $variables + * @param bool $usePreprocess + * @return string + */ + public function getProcessedTemplate(array $variables = array(), $usePreprocess = false) + { + /* @var $processor Mage_Widget_Model_Template_Filter */ + $processor = Mage::getModel('widget/template_filter'); + + $variables['this'] = $this; + + if (Mage::app()->isSingleStoreMode()) { + $processor->setStoreId(Mage::app()->getStore()); + } else { + $processor->setStoreId(1); + } + + $htmlDescription = '
%s:
'; + + switch ($this->getData('type')) { + case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL: + $html = sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Push title')) . $this->getPushTitle(); + $html .= sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Message title')) . $this->getMessageTitle(); + $html .= sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Message content')) . $processor->filter($this->getContent()); + break; + case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH: + default: + $html = sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Push title')) . $this->getPushTitle(); + break; + } + return $html; + } + + /** + * Reset all model data + * + * @return Mage_XmlConnect_Model_Queue + */ + public function reset() + { + $this->setData(array()); + $this->setOrigData(); + + return $this; + } + + + /** + * Get JSON-encoded params for broadcast AirMail + * Format of JSON data: + * { + * "push": { + * "aps": { + * "alert": "New message!" + * } + * }, + * "title": "Message title", + * "message": "Your full message here.", + * "extra": { + * "some_key": "some_value" + * } + * } + * + * @return string + */ + public function getAirmailBroadcastParams() + { + $notificationType = Mage::getStoreConfig(sprintf(Mage_XmlConnect_Model_Queue::XML_PATH_NOTIFICATION_TYPE, $this->getApplicationType())); + + $payload = array( + 'push' => array( + $notificationType => array( + 'alert' => $this->getPushTitle(), + ) + ), + 'title' => $this->getMessageTitle(), + 'message' => $this->getContent(), + ); + return Mage::helper('core')->jsonEncode($payload); + } + + /** + * Get JSON-encoded params for broadcast Push Notification + * Format of JSON data: + * { + * "aps": { + * "badge": 15, + * "alert": "Hello from Urban Airship!", + * "sound": "cat.caf" + * }, + * "exclude_tokens": [ + * "device token you want to skip", + * "another device token you want to skip" + * ] + * } + * + * @return string + */ + public function getPushBroadcastParams() + { + $notificationType = Mage::getStoreConfig(sprintf(Mage_XmlConnect_Model_Queue::XML_PATH_NOTIFICATION_TYPE, $this->getApplicationType())); + + $payload = array( + $notificationType => array( +// 'badge' => 'auto', + 'alert' => $this->getPushTitle(), + 'sound' => 'default' + ) + ); + return Mage::helper('core')->jsonEncode($payload); + } + + /** + * Save object data + * + * @return Mage_Core_Model_Abstract + */ + public function save() + { + if (!$this->getIsSent() && $this->getStatus() == self::STATUS_IN_QUEUE) { + try { + Mage::dispatchEvent('before_save_message_queue', array('queueMessage' => $this)); + } catch (Exception $e) { + Mage::logException($e); + } + } + return parent::save(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php index 3898687512..704d3c2ab0 100644 --- a/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php @@ -28,7 +28,7 @@ * * XmlConnect fixed Varien SimpleXML Element class * - * @author Magento Core Team + * @author Magento Core Team */ class Mage_XmlConnect_Model_Simplexml_Element extends Varien_Simplexml_Element { @@ -78,9 +78,7 @@ public function xmlAttribute($value = null) $value = $this; } $value = (string)$value; - $value = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $value); - return $value; } } diff --git a/app/code/core/Mage/XmlConnect/Model/Tabs.php b/app/code/core/Mage/XmlConnect/Model/Tabs.php index 67d222ba77..24ae0df0b8 100644 --- a/app/code/core/Mage/XmlConnect/Model/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Model/Tabs.php @@ -68,9 +68,18 @@ protected function _translateLabel(&$tabItems) { if (is_array($tabItems)) { foreach ($tabItems as $id => $tab) { - if (isset($tab->label)) { - $temp = $tabItems[$id]; - $temp->label = Mage::helper('xmlconnect')->getTabLabel($tab->action); + $tempTab = $tabItems[$id]; + + if (is_array($tab)) { + if (isset($tab['label'])) { + $tempTab['label'] = Mage::helper('xmlconnect')->getTabLabel($tab['action']); + } else { + $tempTab['label'] = ''; + } + } else { + if (isset($tab->label)) { + $tempTab->label = Mage::helper('xmlconnect')->getTabLabel($tab->action); + } } } } @@ -109,6 +118,7 @@ public function getRenderTabs() $tab->image = Mage::getDesign()->getSkinUrl('images/xmlconnect/' . $tab->image); $result[] = $tab; } + return $result; } } diff --git a/app/code/core/Mage/XmlConnect/Model/Template.php b/app/code/core/Mage/XmlConnect/Model/Template.php new file mode 100755 index 0000000000..41da27eccc --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Template.php @@ -0,0 +1,76 @@ +_init('xmlconnect/template'); + } + + /** + * Get template type + * + * @return int + */ + public function getType() + { + return self::TYPE_HTML; + } + + /** + * Retrieve processed template + * + * @param array $variables + * @param bool $usePreprocess + * @return string + */ + public function getProcessedTemplate(array $variables = array(), $usePreprocess = false) + { + /* @var $processor Mage_Widget_Model_Template_Filter */ + $processor = Mage::getModel('widget/template_filter'); + + $variables['this'] = $this; + + if (Mage::app()->isSingleStoreMode()) { + $processor->setStoreId(Mage::app()->getStore()); + } else { + $processor->setStoreId(1); + } + + $htmlDescription = '
%s:
'; + $html = sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Push title')) . $this->getPushTitle(); + $html .= sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Message title')) . $this->getMessageTitle(); + $html .= sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Message content')) . $processor->filter($this->getContent()); + + return $html; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Theme.php b/app/code/core/Mage/XmlConnect/Model/Theme.php index 97d8970273..8bf1e632db 100644 --- a/app/code/core/Mage/XmlConnect/Model/Theme.php +++ b/app/code/core/Mage/XmlConnect/Model/Theme.php @@ -34,6 +34,8 @@ class Mage_XmlConnect_Model_Theme * Load Theme xml from $file * * @param string $file + * @throws Mage_Core_Exception + * @return void */ public function __construct($file) { diff --git a/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php b/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php index 36aee8290c..c39f990291 100644 --- a/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php +++ b/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php @@ -28,11 +28,12 @@ class Mage_XmlConnect_Adminhtml_MobileController extends Mage_Adminhtml_Controll { /** * Initialize application - * + * * @param string $paramName + * @param string $type * @return Mage_XmlConnect_Model_Application */ - protected function _initApp($paramName = 'application_id') + protected function _initApp($paramName = 'application_id', $type = false) { $id = (int) $this->getRequest()->getParam($paramName); $app = Mage::getModel('xmlconnect/application'); @@ -42,7 +43,10 @@ protected function _initApp($paramName = 'application_id') $app->loadConfiguration(); } } else { + $app->setType($type); + Mage::register('current_app', $app); $app->loadDefaultConfiguration(); + Mage::unregister('current_app'); } Mage::register('current_app', $app); return $app; @@ -63,35 +67,12 @@ protected function _restoreSessionFilesFormData($data) } foreach ($filesData as $filePath => $fileName) { $target =& $data; - $this->_injectFieldToArray($target, $filePath, $fileName); + Mage::helper('xmlconnect')->_injectFieldToArray($target, $filePath, $fileName); } } return $data; } - - /** - * Set value into multidimensional array 'conf/native/navigationBar/icon' - * - * @param &array $target // pointer to target array - * @param string $fieldPath //'conf/native/navigationBar/icon' - * @param mixed $fieldValue // 'Some Value' || 12345 || array(1=>3, 'aa'=>43) - * @param string $delimiter // path delimiter - * @return null - */ - protected function _injectFieldToArray(&$target, $fieldPath, $fieldValue, $delimiter = '/') - { - $nameParts = explode($delimiter, $fieldPath); - foreach ($nameParts as $next) { - if (!isset($target[$next])) { - $target[$next] = array(); - } - $target =& $target[$next]; - } - $target = $fieldValue; - return null; - } - /** * Mobile applications management * @@ -109,7 +90,10 @@ public function indexAction() */ public function newAction() { - $this->_forward('edit'); + Mage::getSingleton('adminhtml/session')->setData('new_application', true); + $this->loadLayout(); + $this->_setActiveMenu('xmlconnect/mobile'); + $this->renderLayout(); } /** @@ -120,7 +104,7 @@ public function submissionAction() try { $app = $this->_initApp(); if (!$app->getId()) { - $this->_getSession()->addError(Mage::helper('xmlconnect')->__('App does not exist.')); + $this->_getSession()->addError($this->__('App does not exist.')); $this->_redirect('*/*/'); return; } @@ -143,7 +127,7 @@ public function submissionAction() $this->_redirect('*/*/'); } } catch (Exception $e) { - $this->_getSession()->addException($e, Mage::helper('xmlconnect')->__('Can\'t open submission form.')); + $this->_getSession()->addException($e, $this->__('Can\'t open submission form.')); if (isset($app)) { $this->_redirect('*/*/edit', array('application_id' => $app->getId())); } else { @@ -162,20 +146,33 @@ public function editAction() $redirectBack = false; try { $id = (int) $this->getRequest()->getParam('application_id'); - $app = $this->_initApp(); + $type = $this->getRequest()->getParam('type'); + $app = $this->_initApp('application_id', $type); if (!$app->getId() && $id) { - $this->_getSession()->addError(Mage::helper('xmlconnect')->__('App does not exist.')); + $this->_getSession()->addError($this->__('App does not exist.')); $this->_redirect('*/*/'); return; } - $app->loadSubmit(); - if ((bool) Mage::getSingleton('adminhtml/session')->getLoadSessionFlag(true)) { - $newAppData = $this->_restoreSessionFilesFormData(Mage::getSingleton('adminhtml/session')->getFormData(true)); - if (!empty($newAppData)) { - $app->setData(Mage::helper('xmlconnect')->arrayMergeRecursive($app->getData(), $newAppData)); - } + + $newAppData = $this->_restoreSessionFilesFormData(Mage::getSingleton('adminhtml/session')->getFormData(true)); + if (!empty($newAppData)) { + $app->setData(Mage::helper('xmlconnect')->arrayMergeRecursive($app->getData(), $newAppData)); } + + if ($app->getId() || $app->getType()) { + Mage::getSingleton('adminhtml/session')->setData('new_application', false); + } else { + $this->_redirect('*/*/new'); + } + + $devArray = Mage::helper('xmlconnect')->getSupportedDevices(); + if (array_key_exists($app->getType(), $devArray)) { + $deviceTitle = $devArray[$app->getType()]; + } + $deviceTitle = isset($deviceTitle) ? $deviceTitle : $app->getType(); + $app->setDevtype($deviceTitle); + $app->loadSubmit(); $this->loadLayout(); $this->_setActiveMenu('xmlconnect/mobile'); $this->renderLayout(); @@ -183,7 +180,7 @@ public function editAction() $this->_getSession()->addError($e->getMessage()); $redirectBack = true; } catch (Exception $e) { - $this->_getSession()->addError(Mage::helper('xmlconnect')->__('Unable to load application form.')); + $this->_getSession()->addError($this->__('Unable to load application form.')); $redirectBack = true; Mage::logException($e); } @@ -228,6 +225,7 @@ public function submissionPostAction() 'created_at' => Mage::getModel('core/date')->date(), 'store_id' => $app->getStoreId(), 'title' => isset($params['title']) ? $params['title'] : '', + 'name' => $app->getName(), 'code' => $app->getCode(), 'activation_key' => isset($params['resubmission_activation_key']) ? $params['resubmission_activation_key'] : $params['key'], @@ -235,7 +233,7 @@ public function submissionPostAction() $history->save(); $app->getResource()->updateApplicationStatus($app->getId(), Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS); - $this->_getSession()->addSuccess(Mage::helper('xmlconnect')->__('App has been submitted.')); + $this->_getSession()->addSuccess($this->__('App has been submitted.')); $this->_clearSessionData(); $this->_redirect('*/*/edit', array('application_id' => $app->getId())); } else { @@ -251,7 +249,7 @@ public function submissionPostAction() $this->_redirect('*/*/'); } } catch (Exception $e) { - $this->_getSession()->addException($e, Mage::helper('xmlconnect')->__('Can\'t submit application.')); + $this->_getSession()->addException($e, $this->__('Can\'t submit application.')); Mage::logException($e); if (isset($app)) { Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true); @@ -338,7 +336,7 @@ protected function _processPostRequest() if (is_array($message)) { $message = implode(' ,', $message); } - Mage::throwException(Mage::helper('xmlconnect')->__('Submit App failure. %s', $message)); + Mage::throwException($this->__('Submit App failure. %s', $message)); } } catch (Exception $e) { throw $e; @@ -351,17 +349,25 @@ protected function _processPostRequest() public function saveAction() { $data = $this->getRequest()->getPost(); - $redirectBack = $this->getRequest()->getParam('back', false); $redirectSubmit = $this->getRequest()->getParam('submitapp', false); $app = false; $isError = false; + $devType = false; if ($data) { Mage::getSingleton('adminhtml/session')->setFormData($data); try { $id = $this->getRequest()->getParam('application_id'); - $app = $this->_initApp(); + if (!$id && isset($data['devtype'])) { + $devArray = Mage::helper('xmlconnect')->getSupportedDevices(); + $devType = array_search($data['devtype'], $devArray); + if ($devType === false) { + $this->_getSession()->addError($this->__('Wrong device type.')); + $isError = true; + } + } + $app = $this->_initApp('application_id', $devType); if (!$app->getId() && $id) { - $this->_getSession()->addError(Mage::helper('xmlconnect')->__('App does not exist.')); + $this->_getSession()->addError($this->__('App does not exist.')); $this->_redirect('*/*/'); return; } @@ -374,29 +380,30 @@ public function saveAction() } $isError = true; } + if (!$isError) { $this->_saveThemeAction($data, 'current_theme'); $app->save(); - $this->_getSession()->addSuccess(Mage::helper('xmlconnect')->__('App has been saved.')); + $this->_getSession()->addSuccess($this->__('App has been saved.')); $this->_clearSessionData(); } } catch (Mage_Core_Exception $e) { $this->_getSession()->addException($e, $e->getMessage()); $isError = true; - $redirectBack = true; } catch (Exception $e) { - $this->_getSession()->addException($e, Mage::helper('xmlconnect')->__('Unable to save app.')); + $this->_getSession()->addException($e, $this->__('Unable to save app.')); $isError = true; - $redirectBack = true; Mage::logException($e); } } - if (!$isError && $app->getId() && $redirectSubmit) { + if (!$isError && is_object($app) && $app->getId() && $redirectSubmit) { $this->_redirect('*/*/submission', array('application_id' => $app->getId())); - } else if ($isError || ($app->getId() && $redirectBack)) { - if ($isError) { - Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true); - } + } else if ($isError && $app->getId()) { + Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true); + $this->_redirect('*/*/edit', array('application_id' => $app->getId())); + } else if ($isError && !$app->getId() && $app->getType()) { + $this->_redirect('*/*/edit', array('type' => $app->getType())); + } else if ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', array('application_id' => $app->getId())); } else { $this->_redirect('*/*/'); @@ -423,19 +430,19 @@ protected function _saveThemeAction($data, $paramId = 'saveTheme') if (isset($data['conf'])) { $convertedConf = $data['conf']; } else { - $response = array('error' => true, 'message' => Mage::helper('xmlconnect')->__('Cannot save theme "%s". Incorrect data received', $themeName)); + $response = array('error' => true, 'message' => $this->__('Cannot save theme "%s". Incorrect data received', $themeName)); } } $theme->importAndSaveData($convertedConf); $response = Mage::helper('xmlconnect/theme')->getAllThemesArray(true); } else { - $response = array('error' => true, 'message' => Mage::helper('xmlconnect')->__('Cannot load theme "%s".', $themeName)); + $response = array('error' => true, 'message' => $this->__('Cannot load theme "%s".', $themeName)); } } else { $response = Mage::helper('xmlconnect/theme')->getAllThemesArray(true); } } else { - $response = array('error' => true, 'message' => Mage::helper('xmlconnect')->__('Theme name is not set.')); + $response = array('error' => true, 'message' => $this->__('Theme name is not set.')); } } catch (Mage_Core_Exception $e) { $response = array( @@ -445,7 +452,7 @@ protected function _saveThemeAction($data, $paramId = 'saveTheme') } catch (Exception $e) { $response = array( 'error' => true, - 'message' => Mage::helper('xmlconnect')->__('Can\'t save theme.') + 'message' => $this->__('Can\'t save theme.') ); } if (is_array($response)) { @@ -488,7 +495,6 @@ protected function _convertPost($data) public function saveThemeAction() { $data = $this->getRequest()->getPost(); - $response = false; $this->_saveThemeAction($data); } @@ -509,7 +515,7 @@ public function resetThemeAction() } catch (Exception $e) { $response = array( 'error' => true, - 'message' => Mage::helper('xmlconnect')->__('Can\'t reset theme.') + 'message' => $this->__('Can\'t reset theme.') ); } if (is_array($response)) { @@ -526,6 +532,14 @@ public function previewHomeAction() $this->_previewAction('preview_home_content'); } + /** + * Preview Home landscape mode action handler + */ + public function previewHomeHorAction() + { + $this->_previewAction('preview_home_hor_content'); + } + /** * Preview Catalog action handler */ @@ -534,6 +548,43 @@ public function previewCatalogAction() $this->_previewAction('preview_catalog_content'); } + /** + * Preview Catalog landscape mode action handler + */ + public function previewCatalogHorAction() + { + $this->_previewAction('preview_catalog_hor_content'); + } + + /** + * Preview Product Info action handler + */ + public function previewProductinfoAction() + { + $this->_previewAction('preview_productinfo_content'); + } + + /** + * Preview AirMail Queue Template action handler + */ + public function previewQueueAction() + { + $message = $this->_initMessage(); + if ($message->getId()) { + $this->getRequest()->setParam('queue_preview', $message->getId()); + } + $this->_forward('previewTemplate'); + } + + /** + * Preview AirMail Template action handler + */ + public function previewTemplateAction() + { + $this->loadLayout('adminhtml_mobile_template_preview'); + $this->renderLayout(); + } + /** * Preview action implementation * @@ -542,15 +593,17 @@ public function previewCatalogAction() protected function _previewAction($block) { $redirectBack = false; - $app = false; + try { - $app = $this->_initApp(); + $deviceTitle = $this->getRequest()->getParam('devtype'); + $deviceType = array_search($deviceTitle, Mage::helper('xmlconnect')->getSupportedDevices()); + $app = $this->_initApp('application_id', $deviceType); if (!$this->getRequest()->getParam('submission_action')) { $app->addData($this->_preparePostData($this->getRequest()->getPost())); } $app->addData($this->_processUploadedFiles($app->getData())); - $this->loadLayout(FALSE); + $this->loadLayout(false); $preview = $this->getLayout()->getBlock($block); $preview->setConf($app->getRenderConf()); $this->renderLayout(); @@ -559,10 +612,10 @@ protected function _previewAction($block) $this->_getSession()->addException($e, $e->getMessage()); $redirectBack = true; } catch (Exception $e) { - $this->_getSession()->addException($e, Mage::helper('xmlconnect')->__('Unable to process preview.')); + $this->_getSession()->addException($e, $this->__('Unable to process preview.')); $redirectBack = true; } - if (isset($app) && $redirectBack) { + if (isset($app) && is_object($app) && $redirectBack) { $this->_redirect('*/*/edit', array('application_id' => $app->getId())); } else { $this->_redirect('*/*/'); @@ -570,7 +623,7 @@ protected function _previewAction($block) } /** - * Delete action + * Delete app action */ public function deleteAction() { @@ -578,18 +631,53 @@ public function deleteAction() $app = $this->_initApp(); if (!$app->getIsSubmitted()) { $app->delete(); - $this->_getSession()->addSuccess(Mage::helper('xmlconnect')->__('App has been deleted.')); + $this->_getSession()->addSuccess($this->__('App has been deleted.')); } else { - Mage::throwException(Mage::helper('xmlconnect')->__('It\'s not allowed to delete submitted application.')); + Mage::throwException($this->__('It\'s not allowed to delete submitted application.')); } } catch (Mage_Core_Exception $e) { $this->_getSession()->addException($e, $e->getMessage()); } catch (Exception $e) { - $this->_getSession()->addException($e, Mage::helper('xmlconnect')->__('Unable to find an app to delete.')); + $this->_getSession()->addException($e, $this->__('Unable to find an app to delete.')); } $this->_redirect('*/*/'); } + /** + * Delete template action + */ + public function deleteTemplateAction() + { + // check if we know what should be deleted + if ($id = $this->getRequest()->getParam('id')) { + try { + // init template and delete + Mage::getModel('xmlconnect/template')->load($id)->delete(); + + // display success message + Mage::getSingleton('adminhtml/session')->addSuccess( + $this->__('Template has been deleted.') + ); + + // go to grid + $this->_redirect('*/*/template'); + return; + + } catch (Exception $e) { + // display error message + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + // go back to edit form + $this->_redirect('*/*/template', array('id' => $id)); + return; + } + } + + // display error message + Mage::getSingleton('adminhtml/session')->addError( + $this->__('Unable to find template to delete.') + ); + } + /** * Check the permission to run it * @@ -648,7 +736,7 @@ protected function _processUploadedFiles($data, $restore = false) } } foreach ($this->_uploadedFiles as $fieldPath => $fileName) { - $this->_injectFieldToArray($data, $fieldPath, $fileName); + Mage::helper('xmlconnect')->_injectFieldToArray($data, $fieldPath, $fileName); } Mage::getSingleton('adminhtml/session')->setUploadedFilesFormData($this->_uploadedFiles); if ($restore === true) { @@ -657,14 +745,8 @@ protected function _processUploadedFiles($data, $restore = false) return $data; } - - - - - /** * Prepare post data - * * Retains previous data in the object. * * @param array $arr @@ -727,6 +809,395 @@ public function submissionHistoryGridAction() $this->loadLayout(); $this->renderLayout(); } + + /** + * Initialize message queue + * + * @param string $paramName + * @return Mage_XmlConnect_Model_Queue + */ + protected function _initMessage($paramName = 'id') + { + $id = (int) $this->getRequest()->getParam($paramName); + $message = Mage::getModel('xmlconnect/queue')->load($id); + Mage::unregister('current_message'); + Mage::register('current_message', $message); + return $message; + } + + /** + * Initialize Template object + * + * @param string $paramName + * @return Mage_XmlConnect_Model_Template + */ + protected function _initTemplate($paramName = 'id') + { + $id = (int) $this->getRequest()->getParam($paramName); + $template = Mage::getModel('xmlconnect/template')->load($id); + Mage::unregister('current_template'); + Mage::register('current_template', $template); + return $template; + } + + /** + * List AirMail message queue grid + */ + public function queueAction() + { + $this->loadLayout(); + $this->_setActiveMenu('xmlconnect/queue'); + $this->renderLayout(); + } + + /** + * Edit message action + */ + public function editQueueAction() + { + $message = $this->_initMessage(); + if ($message->getId()) { + $this->getRequest()->setParam('template_id', $message->getTemplateId()); + $this->_initTemplate('template_id'); + } + $this->_forward('queueMessage'); + } + + /** + * Filtering posted data. Converting localized data if needed + * + * @param array + * @return array + */ + protected function _filterPostData($data) + { + $data = $this->_filterDateTime($data, array('exec_time')); + return $data; + } + + /** + * Cancel queue action + * + * @return void + */ + public function cancelQueueAction() + { + try { + $id = $this->getRequest()->getParam('id'); + $message = $this->_initMessage(); + if (!$message->getId() && $id) { + $this->_getSession()->addError($this->__('Queue does not exist.')); + $this->_redirect('*/*/'); + return; + } + $message->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED); + $message->save(); + } catch (Mage_Core_Exception $e) { + $this->_getSession()->addException($e, $e->getMessage()); + } catch (Exception $e) { + $this->_getSession()->addException($e, $this->__('Unable to cancel queue.')); + Mage::logException($e); + } + + $this->_redirect('*/*/queue'); + } + + /** + * Delete queue action + * + * @return void + */ + public function deleteQueueAction() + { + try { + $id = $this->getRequest()->getParam('id'); + $message = $this->_initMessage(); + if (!$message->getId() && $id) { + $this->_getSession()->addError($this->__('Queue does not exist.')); + $this->_redirect('*/*/'); + return; + } + $message->setStatus(Mage_XmlConnect_Model_Queue::STATUS_DELETED); + $message->save(); + } catch (Mage_Core_Exception $e) { + $this->_getSession()->addException($e, $e->getMessage()); + } catch (Exception $e) { + $this->_getSession()->addException($e, $this->__('Unable to delete queue.')); + Mage::logException($e); + } + + $this->_redirect('*/*/queue'); + } + + /** + * Cancel selected queue action + * + * @return void + */ + public function massCancelQueueAction() + { + $queueIds = $this->getRequest()->getParam('queue'); + if(!is_array($queueIds)) { + Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select message(s).')); + } else { + try { + $queue = Mage::getModel('xmlconnect/queue'); + foreach ($queueIds as $queueId) { + $queue->reset() + ->load((int)$queueId) + ->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED) + ->save(); + } + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('adminhtml')->__('Total of %d record(s) were canceled.', count($queueIds)) + ); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } + } + + $this->_redirect('*/*/queue'); + } + + /** + * Delete selected queue action + * + * @return void + */ + public function massDeleteQueueAction() + { + $queueIds = $this->getRequest()->getParam('queue'); + if(!is_array($queueIds)) { + Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select message(s).')); + } else { + try { + $queue = Mage::getModel('xmlconnect/queue'); + foreach ($queueIds as $queueId) { + $queue->reset() + ->load($queueId) + ->setStatus(Mage_XmlConnect_Model_Queue::STATUS_DELETED) + ->save(); + } + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('adminhtml')->__( + 'Total of %d record(s) were deleted.', count($queueIds) + ) + ); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } + } + + $this->_redirect('*/*/queue'); + } + + /** + * Save AirMail message action + */ + public function saveMessageAction() + { + $data = $this->_filterPostData($this->getRequest()->getPost()); + $isError = false; + $message = false; + + if ($data) { + try { + $template = $this->_initTemplate('template_id'); + $message = $this->_initMessage(); + + if (!$template->getId() && !$message->getTemplateId()) { + $this->_getSession()->addError( + $this->__('Template for new AirMail Message does not exist.') + ); + $this->_redirect('*/*/queue'); + return; + } + $temporaryObject = new Varien_Object(); + $temporaryObject->setData($data); + + if ($temporaryObject->getTemplateId()) { + $message->setTemplateId($temporaryObject->getTemplateId()); + } else { + $message->setTemplateId($template->getId()); + } + + if (!$message->getId()) { + // set status for new messages only + $message->setStatus(Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE); + } elseif ($message->getStatus() != Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) { + $this->_getSession()->addError( + $this->__('Message can not be edited when it\'s status NOT is "IN QUEUE".') + ); + $this->_redirect('*/*/queue'); + return; + } + + switch ($temporaryObject->getType()) { + case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL: + $message->setData('type', Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL); + break; + + case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH: + default: + $message->setData('type', Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH); + break; + } + if ($temporaryObject->getExecTime()) { + $message->setExecTime(Mage::getSingleton('core/date')->gmtDate(null, $temporaryObject->getExecTime())); + } else { + $message->setExecTime(new Zend_Db_Expr('NULL')); + } + if ($template->getId()) { + $message->setAppCode($template->getAppCode()); + } + $message->setPushTitle($temporaryObject->getPushTitle()); + $message->setMessageTitle($temporaryObject->getMessageTitle()); + $message->setContent($temporaryObject->getContent()); + $message->save(); + } catch (Mage_Core_Exception $e) { + $this->_getSession()->addException($e, $e->getMessage()); + $isError = true; + } catch (Exception $e) { + $this->_getSession()->addException($e, $this->__('Unable to save message.')); + $isError = true; + Mage::logException($e); + } + } + + if ($isError) { + if ($isError) { + Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true); + } + $redirectParams = array(); + if ($message && $message->getId()) { + $redirectParams['id'] = $message->getId(); + } else { + $redirectParams['template_id'] = (int) $this->getRequest()->getParam('template_id'); + } + $this->_redirect('*/*/queueMessage', $redirectParams); + } else { + $this->_redirect('*/*/queue'); + } + + } + + /** + * Temlate grid + */ + public function templateAction() + { + $this->loadLayout(); + $this->_setActiveMenu('xmlconnect/template'); + $this->renderLayout(); + } + + /** + * Create new template action + */ + public function newTemplateAction() + { + $this->_forward('editTemplate'); + } + + /** + * Edit template action + */ + public function editTemplateAction() + { + $template = $this->_initTemplate(); + + $applicationsFound = Mage::helper('xmlconnect')->getApplicationOptions(); + if (!$template->getId() && empty($applicationsFound)) { + $this->_getSession()->addError( + $this->__('Template creation is allowed only for applications which have device type iPhone, but this kind of applications has not been found.') + ); + $this->_redirect('*/*/template'); + return; + } + + $this->loadLayout(); + $this->_setActiveMenu('xmlconnect/templates'); + $this->renderLayout(); + } + + /** + * Save template action + */ + public function saveTemplateAction() + { + $data = $this->getRequest()->getPost(); + $template = false; + $isError = false; + if ($data) { + Mage::getSingleton('adminhtml/session')->setFormData($data); + try { + $id = $this->getRequest()->getParam('id'); + $template = $this->_initTemplate(); + if (!$template->getId() && $id) { + $this->_getSession()->addError($this->__('Template does not exist.')); + $this->_redirect('*/*/'); + return; + } + $template->setModifiedAt(Mage::getSingleton('core/date')->gmtDate())->addData($data); + $template->save(); + } catch (Mage_Core_Exception $e) { + $this->_getSession()->addException($e, $e->getMessage()); + $isError = true; + } catch (Exception $e) { + $this->_getSession()->addException($e, $this->__('Unable to save template.')); + $isError = true; + Mage::logException($e); + } + } + + if ($isError && ($template && $template->getId())) { + Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true); + $this->_redirect('*/*/editTemplate', array('id' => $template->getId())); + } else { + $this->_redirect('*/*/template'); + } + } + + /** + * Add message to queue action + */ + public function queueMessageAction() + { + $message = $this->_initMessage(); + if (!$message->getId()) { + $template = $this->_initTemplate('template_id'); + if (!$template->getId()) { + $this->_getSession()->addError( + $this->__('Template for new AirMail Message does not exist.') + ); + $this->_redirect('*/*/template'); + } + } + + $this->loadLayout(); + if ($message->getId()) { + $title = $this->__('Edit AirMail Message'); + } else { + $title = $this->__('New AirMail Message'); + } + $this->_addBreadcrumb( + $this->__('AirMail Message Queue'), + $this->__('AirMail Message Queue'), + $this->getUrl('*/*/queue') + ); + $this->_addBreadcrumb($title, $title); + + $this->_setActiveMenu('xmlconnect/queue'); + $this->renderLayout(); + } + + /** + * Edit queue message action + */ + public function editMessageAction() + { + $this->_forward('queueMessage'); + } } diff --git a/app/code/core/Mage/XmlConnect/controllers/CartController.php b/app/code/core/Mage/XmlConnect/controllers/CartController.php index 9974097be3..66b3e0b99b 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CartController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CartController.php @@ -27,13 +27,14 @@ /** * XmlConnect shopping cart controller * - * @author Magento Core Team + * @author Magento Core Team */ - class Mage_XmlConnect_CartController extends Mage_XmlConnect_Controller_Action { /** * Shopping cart display action + * + * @return void */ public function indexAction() { @@ -56,7 +57,7 @@ public function indexAction() } /** - * if customer enteres shopping cart we should mark quote + * if customer enters shopping cart we should mark quote * as modified bc he can has checkout page in another window. */ $this->_getSession()->setCartWasUpdated(true); @@ -67,6 +68,8 @@ public function indexAction() /** * Update shoping cart data action + * + * @return void */ public function updateAction() { @@ -89,11 +92,11 @@ public function updateAction() ->save(); } $this->_getSession()->setCartWasUpdated(true); - $this->_message(Mage::helper('xmlconnect')->__('Cart has been updated.'), parent::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Cart has been updated.'), parent::MESSAGE_STATUS_SUCCESS); } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t update cart.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t update cart.'), self::MESSAGE_STATUS_ERROR); } } @@ -153,29 +156,27 @@ public function addAction() * Check product availability */ if (!$product) { - $this->_message(Mage::helper('xmlconnect')->__('Product is unavailable.'), parent::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Product is unavailable.'), parent::MESSAGE_STATUS_ERROR); return; } if ($product->isConfigurable()) { $request = $this->_getProductRequest($params); - $cartCandidates = $product->getTypeInstance(true)->prepareForCart($request, $product); + /** * Hardcoded Configurable product default + * Set min required qty for a product if it's need */ - $minSaleQty = ((isset($params['qty']) ? $params['qty'] : 0) > 1) ? $params['qty'] : 1; - if (is_array($cartCandidates)) { - foreach ($cartCandidates as $candidate) { - $current = $candidate->getStockItem()->getMinSaleQty(); - if ($minSaleQty < $current) { - $minSaleQty = $current; - } - } - } - if ($minSaleQty) { - $params['qty'] = $minSaleQty; + $qty = isset($params['qty']) ? $params['qty'] : 0; + $requestedQty = ($qty > 1) ? $qty : 1; + $subProduct = $product->getTypeInstance(true)->getProductByAttributes($request->getSuperAttribute(), $product); + + if ($requestedQty < ($requiredQty = $subProduct->getStockItem()->getMinSaleQty())) { + $requestedQty = $requiredQty; } + + $params['qty'] = $requestedQty; } $cart->addProduct($product, $params); @@ -195,9 +196,9 @@ public function addAction() ); if (!$this->_getSession()->getNoCartRedirect(true)) { - $message = Mage::helper('xmlconnect')->__('%s has been added to your cart.', Mage::helper('core')->htmlEscape($product->getName())); + $message = $this->__('%s has been added to your cart.', Mage::helper('core')->htmlEscape($product->getName())); if ($cart->getQuote()->getHasError()) { - $message .= Mage::helper('xmlconnect')->__(' But cart has some errors.'); + $message .= $this->__(' But cart has some errors.'); } $this->_message($message, parent::MESSAGE_STATUS_SUCCESS); } @@ -208,12 +209,14 @@ public function addAction() $this->_message(implode("\n", array_unique(explode("\n", $e->getMessage()))), parent::MESSAGE_STATUS_ERROR); } } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t add item to shopping cart.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t add item to shopping cart.'), self::MESSAGE_STATUS_ERROR); } } /** * Delete shoping cart item action + * + * @return void */ public function deleteAction() { @@ -221,17 +224,19 @@ public function deleteAction() if ($id) { try { $this->_getCart()->removeItem($id)->save(); - $this->_message(Mage::helper('xmlconnect')->__('Item has been deleted from cart.'), parent::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Item has been deleted from cart.'), parent::MESSAGE_STATUS_SUCCESS); } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), parent::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t remove the item.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t remove the item.'), self::MESSAGE_STATUS_ERROR); } } } /** * Initialize coupon + * + * @return void */ public function couponAction() { @@ -239,7 +244,7 @@ public function couponAction() * No reason continue with empty shopping cart */ if (!$this->_getQuote()->getItemsCount()) { - $this->_message(Mage::helper('xmlconnect')->__('Shopping cart is empty.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Shopping cart is empty.'), self::MESSAGE_STATUS_ERROR); return; } @@ -250,7 +255,7 @@ public function couponAction() $oldCouponCode = $this->_getQuote()->getCouponCode(); if (!strlen($couponCode) && !strlen($oldCouponCode)) { - $this->_message(Mage::helper('xmlconnect')->__('Coupon code is empty.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Coupon code is empty.'), self::MESSAGE_STATUS_ERROR); return; } @@ -262,23 +267,25 @@ public function couponAction() if ($couponCode) { if ($couponCode == $this->_getQuote()->getCouponCode()) { - $this->_message(Mage::helper('xmlconnect')->__('Coupon code %s was applied.', strip_tags($couponCode)), parent::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Coupon code %s was applied.', strip_tags($couponCode)), parent::MESSAGE_STATUS_SUCCESS); } else { - $this->_message(Mage::helper('xmlconnect')->__('Coupon code %s is not valid.', strip_tags($couponCode)), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Coupon code %s is not valid.', strip_tags($couponCode)), self::MESSAGE_STATUS_ERROR); } } else { - $this->_message(Mage::helper('xmlconnect')->__('Coupon code was canceled.'), parent::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Coupon code was canceled.'), parent::MESSAGE_STATUS_SUCCESS); } } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t apply the coupon code.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t apply the coupon code.'), self::MESSAGE_STATUS_ERROR); } } /** * Get shopping cart summary and flag is_virtual + * + * @return void */ public function infoAction() { diff --git a/app/code/core/Mage/XmlConnect/controllers/CatalogController.php b/app/code/core/Mage/XmlConnect/controllers/CatalogController.php index 8568c78e33..ea04fef8c2 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CatalogController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CatalogController.php @@ -27,13 +27,14 @@ /** * XmlConnect catalog controller * - * @author Magento Core Team + * @author Magento Core Team */ - class Mage_XmlConnect_CatalogController extends Mage_XmlConnect_Controller_Action { /** * Category list + * + * @return void */ public function categoryAction() { @@ -43,6 +44,8 @@ public function categoryAction() /** * Filter product list + * + * @return void */ public function filtersAction() { @@ -53,12 +56,14 @@ public function filtersAction() $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { Mage::logException($e); - $this->_message(Mage::helper('xmlconnect')->__('An error occurred while loading category filters.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('An error occurred while loading category filters.'), self::MESSAGE_STATUS_ERROR); } } /** * Product information + * + * @return void */ public function productAction() { @@ -69,13 +74,15 @@ public function productAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Unable to load product info.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Unable to load product info.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } /** * Product options list + * + * @return void */ public function productOptionsAction() { @@ -83,9 +90,10 @@ public function productOptionsAction() $this->renderLayout(); } - /** * Product gallery images list + * + * @return void */ public function productGalleryAction() { @@ -95,6 +103,8 @@ public function productGalleryAction() /** * Product reviews list + * + * @return void */ public function productReviewsAction() { @@ -104,6 +114,8 @@ public function productReviewsAction() /** * Add new review + * + * @return void */ public function productReviewAction() { @@ -113,6 +125,8 @@ public function productReviewAction() /** * Perform search products + * + * @return void */ public function searchAction() { @@ -160,6 +174,8 @@ public function searchAction() /** * Retrieve suggestions based on search query + * + * @return void */ public function searchSuggestAction() { @@ -181,12 +197,12 @@ public function sendEmailAction() $session = Mage::getSingleton('customer/session'); if (!$helper->isEnabled()) { - $this->_message(Mage::helper('xmlconnect')->__('Tell a Friend is disabled.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Tell a Friend is disabled.'), self::MESSAGE_STATUS_ERROR); return $this; } if (!$helper->isAllowForGuest() && !$session->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return $this; } @@ -195,13 +211,13 @@ public function sendEmailAction() */ $productId = (int)$this->getRequest()->getParam('product_id'); if (!$productId) { - $this->_message(Mage::helper('xmlconnect')->__('No product selected.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('No product selected.'), self::MESSAGE_STATUS_ERROR); return $this; } $product = Mage::getModel('catalog/product') ->load($productId); if (!$product->getId() || !$product->isVisibleInCatalog()) { - $this->_message(Mage::helper('xmlconnect')->__('Selected product is unavailable.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Selected product is unavailable.'), self::MESSAGE_STATUS_ERROR); return $this; } @@ -218,14 +234,14 @@ public function sendEmailAction() Mage::register('send_to_friend_model', $model); if ($model->getMaxSendsToFriend()) { -// $this->_message(Mage::helper('xmlconnect')->__('Messages cannot be sent more than %d times in an hour.', $model->getMaxSendsToFriend()), self::MESSAGE_STATUS_WARNING); +// $this->_message($this->__('Messages cannot be sent more than %d times in an hour.', $model->getMaxSendsToFriend()), self::MESSAGE_STATUS_WARNING); // return $this; } - $data = $this->getRequest()->getPost(); + $data = $this->getRequest()->getPost(); if (!$data) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return $this; } @@ -254,21 +270,21 @@ public function sendEmailAction() $validate = $model->validate(); if ($validate === true) { $model->send(); - $this->_message(Mage::helper('xmlconnect')->__('Tell a Friend link has been sent.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Tell a Friend link has been sent.'), self::MESSAGE_STATUS_SUCCESS); return; } else { if (is_array($validate)) { $this->_message(implode(' ', $validate), self::MESSAGE_STATUS_ERROR); return; } else { - $this->_message(Mage::helper('xmlconnect')->__('There were some problems with the data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('There were some problems with the data.'), self::MESSAGE_STATUS_ERROR); return; } } } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Some emails were not sent.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Some emails were not sent.'), self::MESSAGE_STATUS_ERROR); } return $this; diff --git a/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php b/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php index 8ed89734e4..1eba240c62 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php @@ -44,7 +44,7 @@ public function preDispatch() if (!Mage::getSingleton('customer/session')->isLoggedIn() && !Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout()) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } } @@ -61,19 +61,21 @@ public function getOnepage() /** * Onepage Checkout page + * + * @return void */ public function indexAction() { if (!Mage::helper('checkout')->canOnepageCheckout()) { - $this->_message(Mage::helper('xmlconnect')->__('Onepage checkout is disabled.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Onepage checkout is disabled.'), self::MESSAGE_STATUS_ERROR); return; } $quote = $this->getOnepage()->getQuote(); if ($quote->getHasError()) { - $this->_message(Mage::helper('xmlconnect')->__('Cart has some errors.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Cart has some errors.'), self::MESSAGE_STATUS_ERROR); return; } else if (!$quote->hasItems()) { - $this->_message(Mage::helper('xmlconnect')->__('Cart is empty.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Cart is empty.'), self::MESSAGE_STATUS_ERROR); return; } else if (!$quote->validateMinimumAmount()) { $error = Mage::getStoreConfig('sales/minimum_order/error_message'); @@ -89,6 +91,8 @@ public function indexAction() /** * Display customer new billing addrress form + * + * @return void */ public function newBillingAddressFormAction() { @@ -98,6 +102,8 @@ public function newBillingAddressFormAction() /** * Display customer new shipping addrress form + * + * @return void */ public function newShippingAddressFormAction() { @@ -107,6 +113,8 @@ public function newShippingAddressFormAction() /** * Billing addresses list action + * + * @return void */ public function billingAddressAction() { @@ -116,11 +124,13 @@ public function billingAddressAction() /** * Save billing address to current quote using onepage model + * + * @return void */ public function saveBillingAddressAction() { if (!$this->getRequest()->isPost()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } @@ -131,7 +141,7 @@ public function saveBillingAddressAction() } $result = $this->getOnepage()->saveBilling($data, $customerAddressId); if (!isset($result['error'])) { - $this->_message(Mage::helper('xmlconnect')->__('Billing address has been set.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Billing address has been set.'), self::MESSAGE_STATUS_SUCCESS); } else { if (!is_array($result['message'])) { $result['message'] = array($result['message']); @@ -142,6 +152,8 @@ public function saveBillingAddressAction() /** * Shipping addresses list action + * + * @return void */ public function shippingAddressAction() { @@ -151,11 +163,13 @@ public function shippingAddressAction() /** * Save shipping address to current quote using onepage model + * + * @return void */ public function saveShippingAddressAction() { if (!$this->getRequest()->isPost()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } @@ -163,7 +177,7 @@ public function saveShippingAddressAction() $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false); $result = $this->getOnepage()->saveShipping($data, $customerAddressId); if (!isset($result['error'])) { - $this->_message(Mage::helper('xmlconnect')->__('Shipping address has been set.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Shipping address has been set.'), self::MESSAGE_STATUS_SUCCESS); } else { if (!is_array($result['message'])) { $result['message'] = array($result['message']); @@ -174,11 +188,13 @@ public function saveShippingAddressAction() /** * Get shipping methods for current quote + * + * @return void */ public function shippingMethodsAction() { try { - $result = array('error' => Mage::helper('xmlconnect')->__('Error.')); + $result = array('error' => $this->__('Error.')); $this->getOnepage()->getQuote()->getShippingAddress()->setCollectShippingRates(true); $this->getOnepage()->getQuote()->collectTotals()->save(); $this->loadLayout(false); @@ -192,18 +208,20 @@ public function shippingMethodsAction() /** * Shipping method save action + * + * @return void */ public function saveShippingMethodAction() { if (!$this->getRequest()->isPost()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } $data = $this->getRequest()->getPost('shipping_method', ''); $result = $this->getOnepage()->saveShippingMethod($data); if (!isset($result['error'])) { - $this->_message(Mage::helper('xmlconnect')->__('Shipping method has been set.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Shipping method has been set.'), self::MESSAGE_STATUS_SUCCESS); } else { if (!is_array($result['message'])) { $result['message'] = array($result['message']); @@ -216,6 +234,8 @@ public function saveShippingMethodAction() /** * Save checkout method + * + * @return void */ public function saveMethodAction() { @@ -223,7 +243,7 @@ public function saveMethodAction() $method = (string) $this->getRequest()->getPost('method'); $result = $this->getOnepage()->saveCheckoutMethod($method); if (!isset($result['error'])) { - $this->_message(Mage::helper('xmlconnect')->__('Payment Method has been set.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Payment Method has been set.'), self::MESSAGE_STATUS_SUCCESS); } else { if (!is_array($result['message'])) { $result['message'] = array($result['message']); @@ -235,20 +255,30 @@ public function saveMethodAction() /** * Get payment methods action + * + * @return void */ public function paymentMethodsAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + return; + } catch (Mage_Core_Exception $e) { + $result['error'] = $e->getMessage(); + } + $this->_message($result['error'], self::MESSAGE_STATUS_ERROR); } /** * Save payment action + * + * @return void */ public function savePaymentAction() { if (!$this->getRequest()->isPost()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } try { @@ -256,7 +286,7 @@ public function savePaymentAction() $result = array(); $data = $this->getRequest()->getPost('payment', array()); $result = $this->getOnepage()->savePayment($data); - $this->_message(Mage::helper('xmlconnect')->__('Payment method was successfully set.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Payment method was successfully set.'), self::MESSAGE_STATUS_SUCCESS); return; } catch (Mage_Payment_Exception $e) { $result['error'] = $e->getMessage(); @@ -264,13 +294,15 @@ public function savePaymentAction() $result['error'] = $e->getMessage(); } catch (Exception $e) { Mage::logException($e); - $result['error'] = Mage::helper('xmlconnect')->__('Unable to set payment method.'); + $result['error'] = $this->__('Unable to set payment method.'); } $this->_message($result['error'], self::MESSAGE_STATUS_ERROR); } /** * Order summary info action + * + * @return void */ public function orderReviewAction() { @@ -281,11 +313,13 @@ public function orderReviewAction() /** * Create order action + * + * @return void */ public function saveOrderAction() { if (!$this->getRequest()->isPost()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } @@ -293,7 +327,7 @@ public function saveOrderAction() if ($requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds()) { $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array())); if ($diff = array_diff($requiredAgreements, $postedAgreements)) { - $error = Mage::helper('xmlconnect')->__('Please agree to all the terms and conditions before placing the order.'); + $error = $this->__('Please agree to all the terms and conditions before placing the order.'); $this->_message($error, self::MESSAGE_STATUS_ERROR); return; } @@ -308,9 +342,9 @@ public function saveOrderAction() $orderId = $this->getOnepage()->getLastOrderId(); - $text = Mage::helper('xmlconnect')->__('Thank you for your purchase! '); - $text .= Mage::helper('xmlconnect')->__('Your order # is: %s. ', $orderId); - $text .= Mage::helper('xmlconnect')->__('You will receive an order confirmation email with details of your order and a link to track its progress.'); + $text = $this->__('Thank you for your purchase! '); + $text .= $this->__('Your order # is: %s. ', $orderId); + $text .= $this->__('You will receive an order confirmation email with details of your order and a link to track its progress.'); $message->addChild('text', $text); $message->addChild('order_id', $orderId); @@ -327,7 +361,7 @@ public function saveOrderAction() } catch (Exception $e) { Mage::logException($e); Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage()); - $error = Mage::helper('xmlconnect')->__('An error occurred while processing your order. Please contact us or try again later.'); + $error = $this->__('An error occurred while processing your order. Please contact us or try again later.'); } $this->getOnepage()->getQuote()->save(); diff --git a/app/code/core/Mage/XmlConnect/controllers/CmsController.php b/app/code/core/Mage/XmlConnect/controllers/CmsController.php index 99140755a2..99cd88b583 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CmsController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CmsController.php @@ -27,14 +27,14 @@ /** * XmlConnect cms page controller * - * @author Magento Core Team + * @author Magento Core Team */ - class Mage_XmlConnect_CmsController extends Mage_XmlConnect_Controller_Action { - /** * Declare content type header + * + * @return void */ public function preDispatch() { @@ -45,6 +45,7 @@ public function preDispatch() /** * Category list * + * @return void */ public function pageAction() { diff --git a/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php b/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php index 2c1d58d593..117549433f 100644 --- a/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php +++ b/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php @@ -27,13 +27,14 @@ /** * XmlConnect index controller * - * @author Magento Core Team + * @author Magento Core Team */ - class Mage_XmlConnect_ConfigurationController extends Mage_Core_Controller_Front_Action { /** * Declare content type header + * + * @return void */ public function preDispatch() { @@ -44,6 +45,7 @@ public function preDispatch() /** * Initialize application * + * @throws Mage_Core_Exception * @return Mage_XmlConnect_Model_Application */ protected function _initApp() @@ -60,11 +62,11 @@ protected function _initApp() Mage::getSingleton('core/locale')->emulate($app->getStoreId()); $app->setScreenSize($screenSize); if (!$app->getId()) { - Mage::throwException(Mage::helper('xmlconnect')->__('App with specified code does not exist.')); + Mage::throwException($this->__('App with specified code does not exist.')); } $app->loadConfiguration(); } else { - Mage::throwException(Mage::helper('xmlconnect')->__('App code required.')); + Mage::throwException($this->__('App code required.')); } Mage::register('current_app', $app); return $app; @@ -72,6 +74,8 @@ protected function _initApp() /** * Default action + * + * @return void */ public function indexAction() { @@ -92,8 +96,8 @@ public function indexAction() foreach ($cookieToSetArray as $item) { if (!isset($_COOKIE[$item['cookieName']]) || (isset($_COOKIE[$item['cookieName']]) && - ($_COOKIE[$item['cookieName']] != $this->getRequest()->getParam($item['paramName']))) - ) { + ($_COOKIE[$item['cookieName']] != $this->getRequest()->getParam($item['paramName'])) + )) { /** * @todo add management of cookie expire to application admin panel */ @@ -123,7 +127,7 @@ public function indexAction() } catch (Exception $e) { $message = new Mage_XmlConnect_Model_Simplexml_Element(''); $message->addChild('status', Mage_XmlConnect_Controller_Action::MESSAGE_STATUS_ERROR); - $message->addChild('text', Mage::helper('xmlconnect')->__('Can\'t show configuration.')); + $message->addChild('text', $this->__('Can\'t show configuration.')); Mage::logException($e); $this->getResponse()->setBody($message->asNiceXml()); } diff --git a/app/code/core/Mage/XmlConnect/controllers/CustomerController.php b/app/code/core/Mage/XmlConnect/controllers/CustomerController.php index 27f0e0feb2..089678ee1d 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CustomerController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CustomerController.php @@ -27,9 +27,8 @@ /** * XmlConnect customer controller * - * @author Magento Core Team + * @author Magento Core Team */ - class Mage_XmlConnect_CustomerController extends Mage_XmlConnect_Controller_Action { /** @@ -42,7 +41,7 @@ public function loginAction() $session = $this->_getSession(); $request = $this->getRequest(); if ($session->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('You are already logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('You are already logged in.'), self::MESSAGE_STATUS_ERROR); return; } @@ -54,9 +53,9 @@ public function loginAction() if ($session->getCustomer()->getIsJustConfirmed()) { $session->getCustomer()->sendNewAccountEmail('confirmed'); } - $this->_message(Mage::helper('xmlconnect')->__('Authentication complete.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Authentication complete.'), self::MESSAGE_STATUS_SUCCESS); } else { - $this->_message(Mage::helper('xmlconnect')->__('Invalid login or password.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Invalid login or password.'), self::MESSAGE_STATUS_ERROR); } } catch (Mage_Core_Exception $e) { switch ($e->getCode()) { @@ -71,26 +70,27 @@ public function loginAction() } $this->_message($message, self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Customer authentication problem.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer authentication problem.'), self::MESSAGE_STATUS_ERROR); } } else { - $this->_message(Mage::helper('xmlconnect')->__('Login and password are required.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Login and password are required.'), self::MESSAGE_STATUS_ERROR); } } /** * Customer logout * + * @return void */ public function logoutAction() { try { $this->_getSession()->logout(); - $this->_message(Mage::helper('xmlconnect')->__('Logout complete.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Logout complete.'), self::MESSAGE_STATUS_SUCCESS); } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Customer logout problem.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer logout problem.'), self::MESSAGE_STATUS_ERROR); } } @@ -105,7 +105,7 @@ public function formAction() $editFlag = (int)$this->getRequest()->getParam('edit'); if ($editFlag == 1) { if (!$this->_getSession()->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } $customer = $this->_getSession()->getCustomer(); @@ -123,7 +123,7 @@ public function formAction() public function editAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } if ($this->getRequest()->isPost()) { @@ -154,11 +154,11 @@ public function editAction() $confPass = $this->getRequest()->getPost('confirmation'); if (empty($currPass) || empty($newPass) || empty($confPass)) { - $errors[] = Mage::helper('xmlconnect')->__('Password fields cannot be empty.'); + $errors[] = $this->__('Password fields cannot be empty.'); } if ($newPass != $confPass) { - $errors[] = Mage::helper('xmlconnect')->__('Please make sure your passwords match.'); + $errors[] = $this->__('Please make sure your passwords match.'); } $oldPass = $this->_getSession()->getCustomer()->getPasswordHash(); @@ -171,7 +171,7 @@ public function editAction() if ($customer->hashPassword($currPass, $salt) == $oldPass) { $customer->setPassword($newPass); } else { - $errors[] = Mage::helper('xmlconnect')->__('Invalid current password.'); + $errors[] = $this->__('Invalid current password.'); } } @@ -186,15 +186,19 @@ public function editAction() try { $customer->save(); $this->_getSession()->setCustomer($customer); - $this->_message(Mage::helper('xmlconnect')->__('Account information has been saved.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Account information has been saved.'), self::MESSAGE_STATUS_SUCCESS); return; } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t save the customer.'), self::MESSAGE_STATUS_ERROR); + if ($e instanceof Mage_Eav_Model_Entity_Attribute_Exception) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } else { + $this->_message($this->__('Can\'t save the customer.'), self::MESSAGE_STATUS_ERROR); + } } } else { - $this->_message(Mage::helper('xmlconnect')->__('POST data is not valid.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('POST data is not valid.'), self::MESSAGE_STATUS_ERROR); } } @@ -208,7 +212,7 @@ public function saveAction() $session = $this->_getSession(); $request = $this->getRequest(); if ($session->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('You are already logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('You are already logged in.'), self::MESSAGE_STATUS_ERROR); return; } @@ -258,7 +262,7 @@ public function saveAction() if ($customer->isConfirmationRequired()) { $customer->sendNewAccountEmail('confirmation', $session->getBeforeAuthUrl()); - $message = Mage::helper('xmlconnect')->__('Account confirmation is required. Please check your email for the confirmation link.'); + $message = $this->__('Account confirmation is required. Please check your email for the confirmation link.'); $messageXmlObj = new Mage_XmlConnect_Model_Simplexml_Element(''); $messageXmlObj->addChild('status', self::MESSAGE_STATUS_SUCCESS); $messageXmlObj->addChild('text', $message); @@ -268,28 +272,28 @@ public function saveAction() } else { $session->setCustomerAsLoggedIn($customer); $customer->sendNewAccountEmail('registered'); - $this->_message(Mage::helper('xmlconnect')->__('Thank you for registering!'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Thank you for registering!'), self::MESSAGE_STATUS_SUCCESS); return; } } else { if (is_array($errors)) { $message = implode("\n", $errors); } else { - $message = Mage::helper('xmlconnect')->__('Invalid customer data.'); + $message = $this->__('Invalid customer data.'); } $this->_message($message, self::MESSAGE_STATUS_ERROR); return ; } } catch (Mage_Core_Exception $e) { if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) { - $message = Mage::helper('xmlconnect')->__('An account with this email address already exists.'); + $message = $this->__('An account with this email address already exists.'); $session->setEscapeMessages(false); } else { $message = $e->getMessage(); } $this->_message($message, self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t save the customer.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t save the customer.'), self::MESSAGE_STATUS_ERROR); } } } @@ -304,7 +308,7 @@ public function forgotPasswordAction() $email = $this->getRequest()->getPost('email'); if ($email) { if (!Zend_Validate::is($email, 'EmailAddress')) { - $this->_message(Mage::helper('xmlconnect')->__('Invalid email address.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Invalid email address.'), self::MESSAGE_STATUS_ERROR); return; } $customer = Mage::getModel('customer/customer') @@ -316,19 +320,19 @@ public function forgotPasswordAction() $newPassword = $customer->generatePassword(); $customer->changePassword($newPassword, false); $customer->sendPasswordReminderEmail(); - $this->_message(Mage::helper('xmlconnect')->__('A new password has been sent.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('A new password has been sent.'), self::MESSAGE_STATUS_SUCCESS); return; } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Problem changing or sending password.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Problem changing or sending password.'), self::MESSAGE_STATUS_ERROR); } } else { - $this->_message(Mage::helper('xmlconnect')->__('This email address was not found in our records.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('This email address was not found in our records.'), self::MESSAGE_STATUS_ERROR); } } else { - $this->_message(Mage::helper('xmlconnect')->__('Customer email not specified.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer email not specified.'), self::MESSAGE_STATUS_ERROR); } } @@ -340,7 +344,7 @@ public function forgotPasswordAction() public function addressAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } @@ -363,7 +367,7 @@ public function addressAction() public function addressFormAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } @@ -376,7 +380,7 @@ public function addressFormAction() if ($addressId) { $address->load($addressId); if ($address->getCustomerId() != $this->_getSession()->getCustomerId()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified address does not exist.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified address does not exist.'), self::MESSAGE_STATUS_ERROR); return ; } } @@ -393,7 +397,7 @@ public function addressFormAction() public function deleteAddressAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } @@ -404,16 +408,16 @@ public function deleteAddressAction() // Validate address_id <=> customer_id if ($address->getCustomerId() != $this->_getSession()->getCustomerId()) { - $this->_message(Mage::helper('xmlconnect')->__('Address does not belong to this customer.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Address does not belong to this customer.'), self::MESSAGE_STATUS_ERROR); return; } try { $address->delete(); - $this->_message(Mage::helper('xmlconnect')->__('Address has been deleted.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Address has been deleted.'), self::MESSAGE_STATUS_SUCCESS); } catch (Exception $e) { Mage::logException($e); - $this->_message(Mage::helper('xmlconnect')->__('An error occurred while deleting the address.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('An error occurred while deleting the address.'), self::MESSAGE_STATUS_ERROR); } } } @@ -426,7 +430,7 @@ public function deleteAddressAction() public function saveAddressAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } @@ -473,25 +477,25 @@ public function saveAddressAction() $message = new Mage_XmlConnect_Model_Simplexml_Element(''); $message->addChild('status', self::MESSAGE_STATUS_SUCCESS); - $message->addChild('text', Mage::helper('xmlconnect')->__('Address has been saved.')); + $message->addChild('text', $this->__('Address has been saved.')); $message->addChild('address_id', $address->getId()); $this->getResponse()->setBody($message->asNiceXml()); return; } else { - if (is_array($addressValidation)) { - $this->_message(implode('. ', $addressValidation), self::MESSAGE_STATUS_ERROR); + if (is_array($errors)) { + $this->_message(implode('. ', $errors), self::MESSAGE_STATUS_ERROR); } else { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t save address.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t save address.'), self::MESSAGE_STATUS_ERROR); } } } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { Mage::logException($e); - $this->_message(Mage::helper('xmlconnect')->__('Can\'t save address.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t save address.'), self::MESSAGE_STATUS_ERROR); } } else { - $this->_message(Mage::helper('xmlconnect')->__('Address data not specified.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Address data not specified.'), self::MESSAGE_STATUS_ERROR); } } @@ -503,7 +507,7 @@ public function saveAddressAction() public function orderListAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } @@ -513,6 +517,8 @@ public function orderListAction() /** * Check if customer is loggined + * + * @return void */ public function isLogginedAction() { diff --git a/app/code/core/Mage/XmlConnect/controllers/IndexController.php b/app/code/core/Mage/XmlConnect/controllers/IndexController.php index 784929b953..c73d409dda 100644 --- a/app/code/core/Mage/XmlConnect/controllers/IndexController.php +++ b/app/code/core/Mage/XmlConnect/controllers/IndexController.php @@ -27,20 +27,18 @@ /** * XmlConnect index controller * - * @author Magento Core Team + * @author Magento Core Team */ - class Mage_XmlConnect_IndexController extends Mage_XmlConnect_Controller_Action { - /** * Default action * + * @return void */ public function indexAction() { $this->loadLayout(false); $this->renderLayout(); } - } diff --git a/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php b/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php index 8ed7196993..a76563964d 100644 --- a/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php +++ b/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php @@ -57,36 +57,40 @@ public function preDispatch() if (!Mage::getSingleton('customer/session')->isLoggedIn() && !Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout()) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } } /** * Start MEP Checkout + * + * @return void */ public function indexAction() { try { $this->_initCheckout(); $reservedOrderId = $this->_checkout->initCheckout(); - $this->_message(Mage::helper('xmlconnect')->__('Checkout has been initialized.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Checkout has been initialized.'), self::MESSAGE_STATUS_SUCCESS); return; } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Unable to start MEP Checkout.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Unable to start MEP Checkout.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } /** * Save shipping address to current quote using onepage model + * + * @return void */ public function saveShippingAddressAction() { if (!$this->getRequest()->isPost()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } try { @@ -94,7 +98,7 @@ public function saveShippingAddressAction() $data = $this->getRequest()->getPost('shipping', array()); $result = $this->_checkout->saveShipping($data); if (!isset($result['error'])) { - $this->_message(Mage::helper('xmlconnect')->__('Shipping address has been set.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Shipping address has been set.'), self::MESSAGE_STATUS_SUCCESS); } else { if (!is_array($result['message'])) { $result['message'] = array($result['message']); @@ -104,13 +108,15 @@ public function saveShippingAddressAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Unable to save shipping address.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Unable to save shipping address.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } /** * Get shipping methods for current quote + * + * @return void */ public function shippingMethodsAction() { @@ -121,18 +127,20 @@ public function shippingMethodsAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Unable to get shipping methods list.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Unable to get shipping methods list.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } /** * Shipping method save action + * + * @return void */ public function saveShippingMethodAction() { if (!$this->getRequest()->isPost()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } try { @@ -142,7 +150,7 @@ public function saveShippingMethodAction() if (!isset($result['error'])) { $message = new Mage_XmlConnect_Model_Simplexml_Element(''); $message->addChild('status', self::MESSAGE_STATUS_SUCCESS); - $message->addChild('text', Mage::helper('xmlconnect')->__('Shipping method has been set.')); + $message->addChild('text', $this->__('Shipping method has been set.')); if ($this->_getQuote()->isVirtual()) { $quoteAddress = $this->_getQuote()->getBillingAddress(); } else { @@ -160,13 +168,15 @@ public function saveShippingMethodAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Unable to save shipping method.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Unable to save shipping method.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } /** * Shopping cart totals + * + * @return void */ public function cartTotalsAction() { @@ -178,18 +188,20 @@ public function cartTotalsAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Unable to collect cart totals.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Unable to collect cart totals.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } /** * Submit the order + * + * @return void */ public function saveOrderAction() { if (!$this->getRequest()->isPost()) { - $this->_message(Mage::helper('xmlconnect')->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } try { @@ -217,9 +229,9 @@ public function saveOrderAction() $orderId = $this->_checkout->getLastOrderId(); - $text = Mage::helper('xmlconnect')->__('Thank you for your purchase! '); - $text .= Mage::helper('xmlconnect')->__('Your order # is: %s. ', $orderId); - $text .= Mage::helper('xmlconnect')->__('You will receive an order confirmation email with details of your order and a link to track its progress.'); + $text = $this->__('Thank you for your purchase! '); + $text .= $this->__('Your order # is: %s. ', $orderId); + $text .= $this->__('You will receive an order confirmation email with details of your order and a link to track its progress.'); $message->addChild('text', $text); $message->addChild('order_id', $orderId); @@ -228,7 +240,7 @@ public function saveOrderAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Unable to place the order.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Unable to place the order.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } @@ -237,13 +249,14 @@ public function saveOrderAction() * Instantiate quote and checkout * * @throws Mage_Core_Exception + * @return void */ protected function _initCheckout() { $quote = $this->_getQuote(); if (!$quote->hasItems() || $quote->getHasError()) { - Mage::throwException(Mage::helper('xmlconnect')->__('Unable to initialize MEP Checkout.')); + Mage::throwException($this->__('Unable to initialize MEP Checkout.')); } if (!$quote->validateMinimumAmount()) { $error = Mage::getStoreConfig('sales/minimum_order/error_message'); diff --git a/app/code/core/Mage/XmlConnect/controllers/WishlistController.php b/app/code/core/Mage/XmlConnect/controllers/WishlistController.php index 1986c84aba..66d6e2dacc 100644 --- a/app/code/core/Mage/XmlConnect/controllers/WishlistController.php +++ b/app/code/core/Mage/XmlConnect/controllers/WishlistController.php @@ -29,10 +29,8 @@ * * @author Magento Core Team */ - class Mage_XmlConnect_WishlistController extends Mage_XmlConnect_Controller_Action { - /** * Check if customer is logged in * @@ -43,7 +41,7 @@ public function preDispatch() parent::preDispatch(); if (!$this->_getCustomerSession()->isLoggedIn()) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); - $this->_message(Mage::helper('xmlconnect')->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); return ; } } @@ -73,7 +71,7 @@ protected function _getWishlist() $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); return false; } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t create wishlist.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t create wishlist.'), self::MESSAGE_STATUS_ERROR); return false; } return $wishlist; @@ -81,6 +79,8 @@ protected function _getWishlist() /** * Display customer wishlist + * + * @return void */ public function indexAction() { @@ -91,6 +91,8 @@ public function indexAction() /** * Adding new item + * + * @return void */ public function addAction() { @@ -103,13 +105,13 @@ public function addAction() $request = $this->getRequest(); $productId = (int)$request->getParam('product'); if (!$productId) { - $this->_message(Mage::helper('xmlconnect')->__('Product was not specified.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Product was not specified.'), self::MESSAGE_STATUS_ERROR); return; } $product = Mage::getModel('catalog/product')->load($productId); if (!$product->getId() || !$product->isVisibleInCatalog()) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t specify product.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t specify product.'), self::MESSAGE_STATUS_ERROR); return; } @@ -125,17 +127,19 @@ public function addAction() Mage::helper('wishlist')->calculate(); - $message = Mage::helper('xmlconnect')->__('%1$s has been added to your wishlist.', $product->getName()); + $message = $this->__('%1$s has been added to your wishlist.', $product->getName()); $this->_message($message, self::MESSAGE_STATUS_SUCCESS); } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('An error occurred while adding item to wishlist.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('An error occurred while adding item to wishlist.'), self::MESSAGE_STATUS_ERROR); } } /** * Remove item + * + * @return void */ public function removeAction() { @@ -147,14 +151,14 @@ public function removeAction() try { $item->delete(); $wishlist->save(); - $this->_message(Mage::helper('xmlconnect')->__('Item has been removed from wishlist.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Item has been removed from wishlist.'), self::MESSAGE_STATUS_SUCCESS); } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch(Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('An error occurred while removing item from wishlist.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('An error occurred while removing item from wishlist.'), self::MESSAGE_STATUS_ERROR); } } else { - $this->_message(Mage::helper('xmlconnect')->__('Specified item does not exist in wishlist.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Specified item does not exist in wishlist.'), self::MESSAGE_STATUS_ERROR); } Mage::helper('wishlist')->calculate(); @@ -162,6 +166,8 @@ public function removeAction() /** * Clear wishlist action + * + * @return void */ public function clearAction() { @@ -173,11 +179,11 @@ public function clearAction() $item->delete(); } $wishlist->save(); - $this->_message(Mage::helper('xmlconnect')->__('Wishlist has been cleared.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Wishlist has been cleared.'), self::MESSAGE_STATUS_SUCCESS); } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch(Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('An error occurred while removing items from wishlist.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('An error occurred while removing items from wishlist.'), self::MESSAGE_STATUS_ERROR); } Mage::helper('wishlist')->calculate(); @@ -185,6 +191,8 @@ public function clearAction() /** * Update wishlist item comments + * + * @return void */ public function updateAction() { @@ -217,20 +225,20 @@ public function updateAction() try { $wishlist->save(); if ($problemsFlag) { - $message = Mage::helper('xmlconnect')->__('Wishlist has been updated. But there are accrued some errors while updating some items.'); + $message = $this->__('Wishlist has been updated. But there are accrued some errors while updating some items.'); } else { - $message = Mage::helper('xmlconnect')->__('Wishlist has been updated.'); + $message = $this->__('Wishlist has been updated.'); } $this->_message($message, self::MESSAGE_STATUS_SUCCESS); } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Items were updated. But can\'t update wishlist.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Items were updated. But can\'t update wishlist.'), self::MESSAGE_STATUS_SUCCESS); } } else { - $this->_message(Mage::helper('xmlconnect')->__('No items were updated.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('No items were updated.'), self::MESSAGE_STATUS_ERROR); } } else { - $this->_message(Mage::helper('xmlconnect')->__('No items were specifed to update.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('No items were specifed to update.'), self::MESSAGE_STATUS_ERROR); } } @@ -240,6 +248,7 @@ public function updateAction() * If Product has required options - item removed from wishlist and redirect * to product view page with message about needed defined required options * + * @return void */ public function cartAction() { @@ -253,7 +262,7 @@ public function cartAction() $item = Mage::getModel('wishlist/item')->load($itemId); if (!$item->getId() || $item->getWishlistId() != $wishlist->getId()) { - $this->_message(Mage::helper('xmlconnect')->__('Invalid item or wishlist.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Invalid item or wishlist.'), self::MESSAGE_STATUS_ERROR); return; } @@ -268,10 +277,10 @@ public function cartAction() Mage::helper('wishlist')->calculate(); - $this->_message(Mage::helper('xmlconnect')->__('Item has been added to cart.'), self::MESSAGE_STATUS_SUCCESS); + $this->_message($this->__('Item has been added to cart.'), self::MESSAGE_STATUS_SUCCESS); } catch (Mage_Core_Exception $e) { if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_NOT_SALABLE) { - $this->_message(Mage::helper('xmlconnect')->__('Product(s) currently out of stock.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Product(s) currently out of stock.'), self::MESSAGE_STATUS_ERROR); } else if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS || $e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_IS_GROUPED_PRODUCT) { $item->delete(); @@ -285,10 +294,9 @@ public function cartAction() $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } } catch (Exception $e) { - $this->_message(Mage::helper('xmlconnect')->__('Can\'t add item to shopping cart.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Can\'t add item to shopping cart.'), self::MESSAGE_STATUS_ERROR); } Mage::helper('wishlist')->calculate(); } - } diff --git a/app/code/core/Mage/XmlConnect/etc/adminhtml.xml b/app/code/core/Mage/XmlConnect/etc/adminhtml.xml index ce9192bc6b..3dc9b3d506 100644 --- a/app/code/core/Mage/XmlConnect/etc/adminhtml.xml +++ b/app/code/core/Mage/XmlConnect/etc/adminhtml.xml @@ -41,6 +41,16 @@ 20 adminhtml/mobile/history + + Message Templates + 30 + adminhtml/mobile/template + + + Message Queue + 40 + adminhtml/mobile/queue + @@ -60,6 +70,14 @@ Submission History 20 + + Message Templates + 30 + + + Message Queue + 40 + diff --git a/app/code/core/Mage/XmlConnect/etc/config.xml b/app/code/core/Mage/XmlConnect/etc/config.xml index 28a67a2846..884bb91d78 100644 --- a/app/code/core/Mage/XmlConnect/etc/config.xml +++ b/app/code/core/Mage/XmlConnect/etc/config.xml @@ -28,7 +28,7 @@ - 1.4.0.8 + 1.4.0.12 @@ -43,6 +43,8 @@ xmlconnect_application
xmlconnect_history
xmlconnect_application
+ xmlconnect_queue
+ @@ -69,6 +71,16 @@ + + + + + xmlconnect/observer + restrictWebsite + + + +
@@ -107,6 +119,14 @@ + + + + xmlconnect/observer + sendMessageImmediately + + + @@ -159,7 +179,7 @@ - 150 35 + 35 35 320 40 @@ -173,8 +193,13 @@ 320 230 + 768 294 + 320 258 90 120 320 367 + 1024 704 + 768 960 + 320 455 320 90 30 90 136 28 @@ -270,6 +295,30 @@ + <_480x800> + + default + + + / + zoom + 1.5 + + + + + <_480x854> +                 +                    default +                     +                         +                            / +                            zoom +                            1.5 +                         +                     +                 +             <_640x960> default @@ -288,12 +337,44 @@ www.magentocommerce.com/mobile/activate/ http://www.magentocommerce.com/product/mobile http://www.magentocommerce.com/product/mobile#resubmission + https://go.urbanairship.com/partners/magento/ + magentomobile@magento.com + 3 + + notifications/applicationMasterSecret + 5 + aps + + 10 + aps + + + 10 + aps + + + http://www.flurry.com/product/analytics/index.html + + + https://go.urbanairship.com/api/push/broadcast/ + + + https://go.urbanairship.com/api/airmail/send/broadcast/ + + + + + */5 * * * * + xmlconnect/observer::scheduledSend + + +
diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-install-1.4.0.8.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-install-1.4.0.8.php index c34bba35af..14dafc3aa4 100644 --- a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-install-1.4.0.8.php +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-install-1.4.0.8.php @@ -29,7 +29,7 @@ $installer->startSetup(); $installer->run(" -CREATE TABLE IF NOT EXISTS `{$installer->getTable('xmlconnect_application')}` ( +CREATE TABLE IF NOT EXISTS `{$installer->getTable('xmlconnect/application')}` ( `application_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `code` varchar(32) NOT NULL, @@ -44,7 +44,7 @@ PRIMARY KEY (`application_id`), UNIQUE KEY `UNQ_XMLCONNECT_APPLICATION_CODE` (`code`), KEY `FK_XMLCONNECT_APPLICAION_STORE` (`store_id`), - CONSTRAINT `FK_XMLCONNECT_APPLICAION_STORE` FOREIGN KEY (`store_id`) REFERENCES `{$installer->getTable('core_store')}` (`store_id`) ON DELETE SET NULL ON UPDATE SET NULL + CONSTRAINT `FK_XMLCONNECT_APPLICAION_STORE` FOREIGN KEY (`store_id`) REFERENCES `{$installer->getTable('core/store')}` (`store_id`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; CREATE TABLE IF NOT EXISTS `{$installer->getTable('xmlconnect_history')}` ( @@ -58,7 +58,7 @@ `code` varchar(255) NOT NULL, PRIMARY KEY (`history_id`), KEY `FK_XMLCONNECT_HISTORY_APPLICATION` (`application_id`), - CONSTRAINT `FK_XMLCONNECT_HISTORY_APPLICATION` FOREIGN KEY (`application_id`) REFERENCES `{$installer->getTable('xmlconnect_application')}` (`application_id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `FK_XMLCONNECT_HISTORY_APPLICATION` FOREIGN KEY (`application_id`) REFERENCES `{$installer->getTable('xmlconnect/application')}` (`application_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; "); diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.10-1.4.0.11.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.10-1.4.0.11.php new file mode 100755 index 0000000000..31e9cdeb08 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.10-1.4.0.11.php @@ -0,0 +1,32 @@ +startSetup(); + +$installer->getConnection()->addColumn($installer->getTable('xmlconnect/history'), 'name', 'VARCHAR( 255 ) NOT NULL AFTER `activation_key`'); + +$installer->endSetup(); diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.11-1.4.0.12.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.11-1.4.0.12.php new file mode 100755 index 0000000000..646a42643b --- /dev/null +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.11-1.4.0.12.php @@ -0,0 +1,40 @@ +startSetup(); + +$templateTable = $installer->getTable('xmlconnect/template'); + +$installer->getConnection()->addColumn($templateTable, 'app_code', 'VARCHAR( 32 ) NOT NULL AFTER `id`'); +$installer->getConnection()->dropColumn($templateTable, 'app_type'); + +$installer->run("SET foreign_key_checks = 0;"); +$installer->getConnection()->addConstraint('FK_APP_CODE', $templateTable, 'app_code', $installer->getTable('xmlconnect/application'), 'code'); +$installer->run("SET foreign_key_checks = 1;"); + +$installer->endSetup(); diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.8-1.4.0.9.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.8-1.4.0.9.php new file mode 100755 index 0000000000..160bcc8e34 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.8-1.4.0.9.php @@ -0,0 +1,59 @@ +startSetup(); +$queueTable = $installer->getTable('xmlconnect/queue'); +$templateTable = $installer->getTable('xmlconnect/template'); + +$installer->run("CREATE TABLE `{$queueTable}` ( +`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , +`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , +`exec_time` TIMESTAMP NOT NULL , +`template_id` INT NOT NULL , +`push_title` VARCHAR( 140 ) NOT NULL , +`message_title` VARCHAR( 255 ) NOT NULL , +`content` TEXT NOT NULL , +`status` TINYINT NOT NULL DEFAULT '0', +`type` VARCHAR( 12 ) NOT NULL , +`app_code` VARCHAR( 12 ) NOT NULL +) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"); + + +$installer->run("CREATE TABLE `{$templateTable}` ( +`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , +`app_type` VARCHAR( 32 ) NOT NULL , +`name` VARCHAR( 255 ) NOT NULL , +`push_title` VARCHAR( 141 ) NOT NULL , +`message_title` VARCHAR( 255 ) NOT NULL , +`content` TEXT NOT NULL , +`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , +`modified_at` TIMESTAMP NOT NULL +) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_bin"); + +$installer->getConnection()->addConstraint('FK_TEMPLATE_ID', $queueTable, 'template_id', $templateTable, 'id'); +$installer->endSetup(); diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.9-1.4.0.10.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.9-1.4.0.10.php new file mode 100755 index 0000000000..32b4e65dc3 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.9-1.4.0.10.php @@ -0,0 +1,32 @@ +startSetup(); + +$installer->getConnection()->changeColumn($installer->getTable('xmlconnect/queue'), 'exec_time', 'exec_time', 'TIMESTAMP NULL DEFAULT NULL'); + +$installer->endSetup(); diff --git a/app/design/adminhtml/default/default/layout/customer.xml b/app/design/adminhtml/default/default/layout/customer.xml index 91c9ff0702..eca83a4e00 100644 --- a/app/design/adminhtml/default/default/layout/customer.xml +++ b/app/design/adminhtml/default/default/layout/customer.xml @@ -36,9 +36,6 @@ mage/adminhtml/product/composite/configure.js varien/configurable.js - - - diff --git a/app/design/adminhtml/default/default/layout/pagecache.xml b/app/design/adminhtml/default/default/layout/pagecache.xml index deb570ea4f..718019da85 100644 --- a/app/design/adminhtml/default/default/layout/pagecache.xml +++ b/app/design/adminhtml/default/default/layout/pagecache.xml @@ -29,7 +29,7 @@ - + diff --git a/app/design/adminhtml/default/default/layout/sales.xml b/app/design/adminhtml/default/default/layout/sales.xml index 12d79666d7..c612fb6c76 100644 --- a/app/design/adminhtml/default/default/layout/sales.xml +++ b/app/design/adminhtml/default/default/layout/sales.xml @@ -299,6 +299,7 @@ defaultadminhtml/sales_items_renderer_default qtyadminhtml/sales_items_column_qty nameadminhtml/sales_items_column_name + @@ -330,6 +331,7 @@ defaultadminhtml/sales_items_renderer_default qtyadminhtml/sales_items_column_qty nameadminhtml/sales_items_column_name + diff --git a/app/design/adminhtml/default/default/layout/xmlconnect.xml b/app/design/adminhtml/default/default/layout/xmlconnect.xml index d2d2c0d199..f67dd9096a 100644 --- a/app/design/adminhtml/default/default/layout/xmlconnect.xml +++ b/app/design/adminhtml/default/default/layout/xmlconnect.xml @@ -45,6 +45,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + js_cssprototype/windows/themes/default.css + js_cssprototype/windows/themes/magento.css + + + + + + + + + + + + + + + @@ -64,13 +115,19 @@ + + + + general_sectionmobile_edit_tab_general design_sectionmobile_edit_tab_design content_sectionmobile_edit_tab_content payment_methodsmobile_edit_tab_payment + flurryanalytics_sectionmobile_edit_tab_flurryanalytics history_gridmobile_edit_tab_submission_history_grid + notification_sectionmobile_edit_tab_notification @@ -114,16 +171,54 @@ + + + + + - - + + home + + home + + + + home_hor + + home + + + + + + + catalog_hor + + shop + + + + - - + + catalog + + shop + + + + + productinfo + + shop + + + diff --git a/app/design/adminhtml/default/default/template/api/role_users_grid_js.phtml b/app/design/adminhtml/default/default/template/api/role_users_grid_js.phtml index edc3498994..be795783b2 100644 --- a/app/design/adminhtml/default/default/template/api/role_users_grid_js.phtml +++ b/app/design/adminhtml/default/default/template/api/role_users_grid_js.phtml @@ -56,7 +56,7 @@ checkbox[0].checked = false; checkBoxes.each(function(elem) { if (elem.value.status == 1) { - elem.value.object.checked = true; + elem.value.object.checked = true; } }); return false; @@ -90,7 +90,7 @@ warning = false; } checkBoxes.each(function(elem) { - getJsObjectName() ?>.setCheckboxChecked(elem.value.object, obj.checked); + getJsObjectName() ?>.setCheckboxChecked(elem.value.object, obj.checked); }); } diff --git a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/bundle.phtml b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/bundle.phtml index 6461e815d2..7e4a4caa30 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/bundle.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/bundle.phtml @@ -87,7 +87,7 @@ BundleControl.prototype = { this.changeSelection(selection); } } - }, + } } ProductConfigure.bundleControl = new BundleControl(getJsonConfig() ?>); diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/configure.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/configure.phtml index 492caede7e..4549e03291 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/configure.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/configure.phtml @@ -26,7 +26,7 @@ ?>