From 8f27f9d8d982b78e4bd65936100068b42f22d016 Mon Sep 17 00:00:00 2001 From: Lee Saferite Date: Thu, 29 Sep 2011 17:47:11 -0400 Subject: [PATCH] Import Magento Release 1.6.1.0-rc1 URL: http://www.magentocommerce.com/getmagento/1.6.1.0-rc1/magento-1.6.1.0-rc1.tar.bz2 SHA!: 90d87dc29a26e1c25c8c346c4283468442e6d967 --- RELEASE_NOTES.txt | 176 ++++++ app/Mage.php | 2 +- .../Block/Sales/Order/Totals/Tax.php | 3 + .../Widget/Grid/Column/Renderer/Options.php | 5 +- app/code/core/Mage/Bundle/Model/Observer.php | 24 +- .../core/Mage/Bundle/Model/Product/Type.php | 62 +-- .../Mage/Catalog/Block/Product/Abstract.php | 7 +- .../Catalog/Model/Product/Type/Abstract.php | 15 +- .../core/Mage/Checkout/Model/Type/Onepage.php | 5 + .../Checkout/controllers/CartController.php | 2 +- .../controllers/MultishippingController.php | 2 +- .../controllers/OnepageController.php | 11 +- .../Controller/Varien/Router/Standard.php | 15 +- .../core/Mage/Core/Model/Session/Abstract.php | 2 +- app/code/core/Mage/Core/Model/Store.php | 14 +- app/code/core/Mage/Core/Model/Url.php | 2 +- app/code/core/Mage/Customer/etc/config.xml | 3 +- .../GoogleCheckout/Model/Api/Xml/Callback.php | 8 +- .../controllers/RedirectController.php | 2 +- app/code/core/Mage/Paypal/Model/Api/Nvp.php | 2 +- app/code/core/Mage/Paypal/Model/Config.php | 11 +- app/code/core/Mage/Paypal/Model/Ipn.php | 2 +- .../Mage/Paypal/Model/Method/Agreement.php | 1 + .../core/Mage/Paypal/Model/Payflowlink.php | 9 +- .../core/Mage/Paypal/Model/Payflowpro.php | 4 +- app/code/core/Mage/Paypal/etc/system.xml | 2 +- .../core/Mage/Poll/Model/Resource/Poll.php | 19 +- .../Resource/Review/Customer/Collection.php | 1 + .../Resource/Review/Product/Collection.php | 4 +- .../Mage/Rss/Block/Catalog/NotifyStock.php | 82 ++- .../core/Mage/Rss/Block/Catalog/Review.php | 70 ++- app/code/core/Mage/Rss/Helper/Data.php | 19 + .../core/Mage/Sales/Model/Order/Payment.php | 3 +- .../Sales/Model/Order/Pdf/Total/Default.php | 3 + .../Sales/controllers/DownloadController.php | 23 +- app/code/core/Mage/Tax/Helper/Data.php | 75 ++- app/code/core/Mage/Tax/Model/Observer.php | 56 +- .../Model/Resource/Sales/Order/Tax/Item.php | 4 +- app/code/core/Mage/Tax/etc/config.xml | 2 +- .../sql/tax_setup/upgrade-1.6.0.2-1.6.0.3.php | 44 ++ .../Widget/Instance/Edit/Tab/Settings.php | 8 +- .../Mage/Widget/Model/Widget/Instance.php | 7 +- .../Adminhtml/Widget/InstanceController.php | 13 +- .../core/Mage/Wishlist/Model/Wishlist.php | 31 +- .../Wishlist/controllers/IndexController.php | 1 - .../XmlConnect/Block/Adminhtml/History.php | 6 +- .../Block/Adminhtml/History/Grid.php | 6 +- .../XmlConnect/Block/Adminhtml/Mobile.php | 13 +- .../Block/Adminhtml/Mobile/Edit.php | 13 +- .../Block/Adminhtml/Mobile/Edit/Form.php | 13 +- .../Adminhtml/Mobile/Edit/Submission.php | 11 +- .../Block/Adminhtml/Mobile/Edit/Tab/Cache.php | 3 +- .../Adminhtml/Mobile/Edit/Tab/Content.php | 12 +- .../Adminhtml/Mobile/Edit/Tab/Design.php | 11 +- .../Mobile/Edit/Tab/Design/Accordion.php | 11 +- .../Edit/Tab/Design/Accordion/Images.php | 8 + .../Mobile/Edit/Tab/Design/Accordion/Tabs.php | 2 +- .../Mobile/Edit/Tab/Design/Preview.php | 16 +- .../Mobile/Edit/Tab/Design/Themes.php | 3 +- .../Mobile/Edit/Tab/Flurryanalytics.php | 12 +- .../Adminhtml/Mobile/Edit/Tab/General.php | 13 +- .../Mobile/Edit/Tab/Notification.php | 12 +- .../Adminhtml/Mobile/Edit/Tab/Payment.php | 64 ++- .../Adminhtml/Mobile/Edit/Tab/Settings.php | 16 +- .../Mobile/Edit/Tab/Submission/History.php | 13 +- .../Block/Adminhtml/Mobile/Edit/Tabs.php | 17 +- .../Adminhtml/Mobile/Form/Element/Addrow.php | 37 +- .../Adminhtml/Mobile/Form/Element/Color.php | 12 +- .../Adminhtml/Mobile/Form/Element/Country.php | 21 +- .../Mobile/Form/Element/Datetime.php | 37 +- .../Adminhtml/Mobile/Form/Element/Font.php | 27 +- .../Adminhtml/Mobile/Form/Element/Image.php | 15 +- .../Adminhtml/Mobile/Form/Element/Page.php | 28 +- .../Adminhtml/Mobile/Form/Element/Tabs.php | 14 +- .../Adminhtml/Mobile/Form/Element/Theme.php | 13 +- .../Block/Adminhtml/Mobile/Grid.php | 8 + .../Adminhtml/Mobile/Grid/Renderer/Bool.php | 21 +- .../Adminhtml/Mobile/Grid/Renderer/Type.php | 9 +- .../Adminhtml/Mobile/Preview/Content.php | 8 + .../Adminhtml/Mobile/Preview/Tabitems.php | 9 +- .../Block/Adminhtml/Mobile/Submission.php | 22 +- .../Adminhtml/Mobile/Submission/Form.php | 11 +- .../Renderer/Country/Androidmarket.php | 2 +- .../Submission/Renderer/Country/Istore.php | 2 +- .../Mobile/Submission/Tab/Container.php | 13 +- .../Submission/Tab/Container/Submission.php | 3 +- .../Adminhtml/Mobile/Submission/Tabs.php | 11 +- .../Block/Adminhtml/Mobile/Widget/Form.php | 14 +- .../Mage/XmlConnect/Block/Adminhtml/Queue.php | 6 +- .../XmlConnect/Block/Adminhtml/Queue/Edit.php | 12 +- .../Block/Adminhtml/Queue/Edit/Form.php | 55 +- .../XmlConnect/Block/Adminhtml/Queue/Grid.php | 2 - .../Adminhtml/Queue/Grid/Renderer/Action.php | 9 +- .../Queue/Grid/Renderer/Application.php | 11 +- .../Adminhtml/Queue/Grid/Renderer/Id.php | 9 +- .../Queue/Grid/Renderer/Msgtitle.php | 11 +- .../Queue/Grid/Renderer/Pushtitle.php | 14 +- .../Adminhtml/Queue/Grid/Renderer/Status.php | 12 +- .../Queue/Grid/Renderer/Template.php | 14 +- .../XmlConnect/Block/Adminhtml/Template.php | 12 +- .../Block/Adminhtml/Template/Edit.php | 14 +- .../Block/Adminhtml/Template/Edit/Form.php | 30 +- .../Block/Adminhtml/Template/Grid.php | 9 +- .../Template/Grid/Renderer/Application.php | 2 +- .../Block/Adminhtml/Template/Preview.php | 6 +- .../Block/Adminhtml/Template/Preview/Form.php | 23 +- app/code/core/Mage/XmlConnect/Block/Cart.php | 321 +++++------ .../Mage/XmlConnect/Block/Cart/Crosssell.php | 8 +- .../core/Mage/XmlConnect/Block/Cart/Info.php | 20 +- .../XmlConnect/Block/Cart/Item/Renderer.php | 262 +++++++++ .../Block/Cart/Item/Renderer/Configurable.php | 88 +++ .../Block/Cart/Item/Renderer/Grouped.php | 52 ++ .../Block/Cart/Paypal/Mecl/Details.php | 87 +++ .../Block/Cart/Paypal/Mecl/Review.php | 94 ++++ .../Cart/Paypal/Mecl/Shippingmethods.php | 97 ++++ .../Block/Cart/Paypal/Mep/Totals.php | 35 +- .../Mage/XmlConnect/Block/Cart/Totals.php | 54 +- .../core/Mage/XmlConnect/Block/Catalog.php | 8 + .../XmlConnect/Block/Catalog/Category.php | 30 +- .../Block/Catalog/Category/Info.php | 4 +- .../Mage/XmlConnect/Block/Catalog/Filters.php | 2 +- .../Mage/XmlConnect/Block/Catalog/Product.php | 20 +- .../Block/Catalog/Product/Attributes.php | 6 +- .../Block/Catalog/Product/Gallery.php | 12 +- .../XmlConnect/Block/Catalog/Product/List.php | 18 +- .../Block/Catalog/Product/Options.php | 29 +- .../Block/Catalog/Product/Options/Bundle.php | 19 +- .../Catalog/Product/Options/Configurable.php | 17 +- .../Catalog/Product/Options/Giftcard.php | 175 +++--- .../Block/Catalog/Product/Options/Grouped.php | 9 +- .../Block/Catalog/Product/Options/Simple.php | 7 +- .../Block/Catalog/Product/Options/Virtual.php | 7 +- .../Block/Catalog/Product/Price.php | 2 +- .../Block/Catalog/Product/Price/Bundle.php | 198 +++++-- .../Block/Catalog/Product/Price/Default.php | 344 ++++++++---- .../Block/Catalog/Product/Price/Giftcard.php | 19 +- .../Block/Catalog/Product/Related.php | 60 +- .../Block/Catalog/Product/Review.php | 6 +- .../Block/Catalog/Product/Review/List.php | 9 +- .../Mage/XmlConnect/Block/Catalog/Search.php | 30 +- .../Block/Catalog/Search/Suggest.php | 11 +- .../Block/Checkout/Address/Billing.php | 4 +- .../Block/Checkout/Address/Form.php | 207 +++---- .../XmlConnect/Block/Checkout/Agreements.php | 2 +- .../Block/Checkout/Order/Review/Info.php | 48 +- .../Checkout/Payment/Method/Authorizenet.php | 48 +- .../Block/Checkout/Payment/Method/Checkmo.php | 6 +- .../Payment/Method/Info/Authorizenet.php | 28 +- .../Checkout/Payment/Method/Info/Ccsave.php | 15 +- .../Checkout/Payment/Method/Info/Checkmo.php | 23 +- .../Checkout/Payment/Method/Info/Free.php | 47 ++ .../Payment/Method/Info/Paypal/Abstract.php | 58 ++ .../Payment/Method/Info/Paypal/Express.php | 37 ++ .../Payment/Method/Info/Paypal/Mecl.php | 37 ++ .../Method/Info/Pbridge/Authorizenet.php | 37 ++ .../Method/Info/Pbridge/Paypal/Direct.php | 37 ++ .../Method/Info/Pbridge/Paypaluk/Direct.php | 37 ++ .../Payment/Method/Info/Pbridge/Verisign.php | 57 ++ .../Payment/Method/Info/Purchaseorder.php | 15 +- .../Block/Checkout/Payment/Method/List.php | 144 ++++- .../Checkout/Payment/Method/Paypal/Direct.php | 6 +- .../Payment/Method/Paypal/Payflow.php | 59 +- .../Payment/Method/Pbridge/Authorizenet.php | 6 +- .../Payment/Method/Pbridge/Paypal.php | 6 +- .../Payment/Method/Pbridge/Paypaluk.php | 6 +- .../Payment/Method/Pbridge/Verisign.php | 6 +- .../Checkout/Shipping/Method/Available.php | 29 +- .../core/Mage/XmlConnect/Block/Cms/Page.php | 5 +- .../Mage/XmlConnect/Block/Configuration.php | 3 +- .../Block/Customer/Address/Form.php | 467 ++++++++++++---- .../Block/Customer/Address/List.php | 11 +- .../Mage/XmlConnect/Block/Customer/Form.php | 9 +- .../Block/Customer/Form/Renderer/Boolean.php | 49 ++ .../Block/Customer/Form/Renderer/Date.php | 97 ++++ .../Block/Customer/Form/Renderer/File.php | 112 ++++ .../Block/Customer/Form/Renderer/Image.php | 83 +++ .../Customer/Form/Renderer/Multiline.php | 88 +++ .../Customer/Form/Renderer/Multiselect.php | 66 +++ .../Block/Customer/Form/Renderer/Select.php | 65 +++ .../Block/Customer/Form/Renderer/Text.php | 82 +++ .../Block/Customer/Form/Renderer/Textarea.php | 42 ++ .../Block/Customer/GiftcardCheck.php | 65 +++ .../Block/Customer/Order/Details.php | 156 +++--- .../Customer/Order/Item/Renderer/Bundle.php | 397 +++---------- .../Customer/Order/Item/Renderer/Default.php | 368 ++---------- .../Order/Item/Renderer/Downloadable.php | 409 ++------------ .../Customer/Order/Item/Renderer/Giftcard.php | 5 +- .../Customer/Order/Item/Renderer/Grouped.php | 7 +- .../XmlConnect/Block/Customer/Order/Items.php | 30 +- .../XmlConnect/Block/Customer/Order/List.php | 38 +- .../Block/Customer/Order/Totals.php | 20 +- .../Customer/Order/Totals/Customerbalance.php | 8 +- .../Order/Totals/Customerbalance/Refunded.php | 8 +- .../Block/Customer/Order/Totals/Giftcards.php | 12 +- .../Block/Customer/Order/Totals/Tax.php | 20 +- .../XmlConnect/Block/Customer/Storecredit.php | 91 +++ app/code/core/Mage/XmlConnect/Block/Home.php | 10 +- .../Mage/XmlConnect/Block/Review/Form.php | 79 +-- .../core/Mage/XmlConnect/Block/Wishlist.php | 13 +- .../Mage/XmlConnect/Controller/Action.php | 29 +- .../core/Mage/XmlConnect/Helper/Android.php | 197 +++---- .../Helper/Customer/Form/Renderer.php | 58 ++ .../Mage/XmlConnect/Helper/Customer/Order.php | 251 +++++++++ app/code/core/Mage/XmlConnect/Helper/Data.php | 136 +++-- .../core/Mage/XmlConnect/Helper/Image.php | 82 ++- app/code/core/Mage/XmlConnect/Helper/Ipad.php | 228 ++++---- .../core/Mage/XmlConnect/Helper/Iphone.php | 222 ++++---- .../core/Mage/XmlConnect/Helper/Payment.php | 2 +- .../core/Mage/XmlConnect/Helper/Theme.php | 50 +- .../System/Config/Backend/Baseurl.php | 12 +- .../Config/Backend/Currency/Default.php | 10 +- .../Mage/XmlConnect/Model/Application.php | 275 +++++---- .../Model/Catalog/Category/Image.php | 59 +- .../Model/Catalog/Category/Media/Config.php | 2 +- .../core/Mage/XmlConnect/Model/ConfigData.php | 12 +- .../core/Mage/XmlConnect/Model/History.php | 7 +- .../core/Mage/XmlConnect/Model/Observer.php | 33 +- .../Model/Payment/Method/Paypal/Config.php | 51 ++ .../Model/Payment/Method/Paypal/Mecl.php | 101 ++++ .../Model/Payment/Method/Paypal/Mep.php | 3 +- .../XmlConnect/Model/Paypal/Mecl/Checkout.php | 42 ++ .../XmlConnect/Model/Paypal/Mep/Checkout.php | 37 +- .../XmlConnect/Model/Preview/Abstract.php | 51 +- .../Mage/XmlConnect/Model/Preview/Iphone.php | 3 +- app/code/core/Mage/XmlConnect/Model/Queue.php | 35 +- .../XmlConnect/Model/Resource/Application.php | 21 +- .../Model/Resource/Application/Collection.php | 2 +- .../XmlConnect/Model/Resource/ConfigData.php | 11 +- .../Model/Resource/ConfigData/Collection.php | 12 +- .../XmlConnect/Model/Resource/History.php | 8 +- .../Model/Resource/History/Collection.php | 3 +- .../Mage/XmlConnect/Model/Resource/Queue.php | 2 +- .../Model/Resource/Queue/Collection.php | 26 +- .../XmlConnect/Model/Resource/Template.php | 2 +- .../Model/Resource/Template/Collection.php | 14 +- .../XmlConnect/Model/Simplexml/Element.php | 14 +- .../Mage/XmlConnect/Model/Simplexml/Form.php | 388 +++++++++++++ .../Model/Simplexml/Form/Abstract.php | 524 ++++++++++++++++++ .../Model/Simplexml/Form/Element/Abstract.php | 325 +++++++++++ .../Model/Simplexml/Form/Element/Checkbox.php | 59 ++ .../Simplexml/Form/Element/Collection.php | 202 +++++++ .../Form/Element/CountryListSelect.php | 240 ++++++++ .../Model/Simplexml/Form/Element/Date.php | 85 +++ .../Model/Simplexml/Form/Element/Email.php | 47 ++ .../Model/Simplexml/Form/Element/Fieldset.php | 219 ++++++++ .../Model/Simplexml/Form/Element/File.php | 47 ++ .../Model/Simplexml/Form/Element/Image.php | 47 ++ .../Simplexml/Form/Element/Multiline.php | 132 +++++ .../Simplexml/Form/Element/Multiselect.php | 81 +++ .../Form/Element/Renderer/Interface.php | 37 ++ .../Model/Simplexml/Form/Element/Select.php | 91 +++ .../Model/Simplexml/Form/Element/Text.php | 47 ++ .../Model/Simplexml/Form/Element/Textarea.php | 47 ++ .../Simplexml/Form/Element/Validator.php | 193 +++++++ .../Form/Element/Validator/Abstract.php | 184 ++++++ .../Simplexml/Form/Element/Validator/Rule.php | 46 ++ app/code/core/Mage/XmlConnect/Model/Tabs.php | 8 +- .../core/Mage/XmlConnect/Model/Template.php | 8 +- app/code/core/Mage/XmlConnect/Model/Theme.php | 34 +- .../Adminhtml/MobileController.php | 237 ++++---- .../XmlConnect/controllers/CartController.php | 200 +++++-- .../controllers/CatalogController.php | 112 +++- .../controllers/CheckoutController.php | 116 ++-- .../XmlConnect/controllers/CmsController.php | 8 +- .../controllers/ConfigurationController.php | 50 +- .../controllers/CustomerController.php | 299 +++++++--- .../controllers/IndexController.php | 17 +- .../controllers/Paypal/MeclController.php | 410 ++++++++++++++ .../controllers/Paypal/MepController.php | 84 ++- .../controllers/PbridgeController.php | 8 +- .../controllers/ReviewController.php | 80 +-- .../controllers/WishlistController.php | 78 ++- app/code/core/Mage/XmlConnect/etc/config.xml | 8 + .../system/config/payflowlink/info.phtml | 2 +- .../order/shipment/packaging/popup.phtml | 1 + .../default/template/widget/instance/js.phtml | 18 +- .../edit/tab/design/preview/home_iphone.phtml | 3 +- .../base/default/layout/catalog_msrp.xml | 3 + .../frontend/base/default/layout/paypal.xml | 3 + .../frontend/base/default/layout/paypaluk.xml | 3 + .../base/default/layout/xmlconnect.xml | 48 +- app/locale/en_US/Mage_Adminhtml.csv | 4 +- app/locale/en_US/Mage_Catalog.csv | 1 - app/locale/en_US/Mage_Paypal.csv | 1 + app/locale/en_US/Mage_Rss.csv | 2 - app/locale/en_US/Mage_Sales.csv | 1 + app/locale/en_US/Mage_Tax.csv | 1 + app/locale/en_US/Mage_Widget.csv | 3 +- app/locale/en_US/Mage_XmlConnect.csv | 105 +++- js/mage/adminhtml/sales.js | 5 + lib/Varien/Db/Adapter/Pdo/Mysql.php | 31 +- .../design_default/accordion_open.png | Bin 43389 -> 43069 bytes .../xmlconnect/design_default/banner_1_2.png | Bin 38683 -> 66439 bytes .../xmlconnect/mobile_preview/background.png | Bin 0 -> 43389 bytes ...terface_Adminhtml_Default-1.6.1.0-rc1.xml} | 10 +- ...ace_Frontend_Base_Default-1.6.1.0-rc1.xml} | 10 +- ...-beta1.xml => Lib_Js_Mage-1.6.1.0-rc1.xml} | 10 +- ...xml => Lib_Js_Prototype-1.7.0.0.2-rc1.xml} | 8 +- ...1.0-beta1.xml => Lib_Mage-1.6.1.0-rc1.xml} | 8 +- ...0-beta1.xml => Lib_Varien-1.6.1.0-rc1.xml} | 10 +- var/package/Mage_All_Latest-1.6.1.0-beta1.xml | 18 - var/package/Mage_All_Latest-1.6.1.0-rc1.xml | 18 + ...eta1.xml => Mage_Centinel-1.6.1.0-rc1.xml} | 8 +- ...ml => Mage_Core_Adminhtml-1.6.1.0-rc1.xml} | 10 +- ....xml => Mage_Core_Modules-1.6.1.0-rc1.xml} | 12 +- ...a1.xml => Mage_Downloader-1.6.1.0-rc1.xml} | 8 +- ....xml => Mage_Locale_en_US-1.6.1.0-rc1.xml} | 10 +- 307 files changed, 10948 insertions(+), 4127 deletions(-) create mode 100644 app/code/core/Mage/Tax/sql/tax_setup/upgrade-1.6.0.2-1.6.0.3.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Configurable.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Grouped.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Details.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Review.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Shippingmethods.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Free.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Abstract.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Express.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Mecl.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Authorizenet.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypal/Direct.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypaluk/Direct.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Verisign.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Boolean.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Date.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/File.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Image.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiline.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiselect.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Select.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Text.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Textarea.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/GiftcardCheck.php create mode 100644 app/code/core/Mage/XmlConnect/Block/Customer/Storecredit.php create mode 100644 app/code/core/Mage/XmlConnect/Helper/Customer/Form/Renderer.php create mode 100644 app/code/core/Mage/XmlConnect/Helper/Customer/Order.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Config.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mecl.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Paypal/Mecl/Checkout.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Abstract.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Abstract.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Checkbox.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Collection.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/CountryListSelect.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Date.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Email.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Fieldset.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/File.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Image.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Multiline.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Multiselect.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Renderer/Interface.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Select.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Text.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Textarea.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator/Abstract.php create mode 100644 app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator/Rule.php create mode 100644 app/code/core/Mage/XmlConnect/controllers/Paypal/MeclController.php create mode 100755 skin/adminhtml/default/default/images/xmlconnect/mobile_preview/background.png rename var/package/{Interface_Adminhtml_Default-1.6.1.0-beta1.xml => Interface_Adminhtml_Default-1.6.1.0-rc1.xml} (99%) rename var/package/{Interface_Frontend_Base_Default-1.6.1.0-beta1.xml => Interface_Frontend_Base_Default-1.6.1.0-rc1.xml} (98%) rename var/package/{Lib_Js_Mage-1.6.1.0-beta1.xml => Lib_Js_Mage-1.6.1.0-rc1.xml} (96%) rename var/package/{Lib_Js_Prototype-1.7.0.0.2-beta1.xml => Lib_Js_Prototype-1.7.0.0.2-rc1.xml} (98%) rename var/package/{Lib_Mage-1.6.1.0-beta1.xml => Lib_Mage-1.6.1.0-rc1.xml} (97%) rename var/package/{Lib_Varien-1.6.1.0-beta1.xml => Lib_Varien-1.6.1.0-rc1.xml} (98%) delete mode 100644 var/package/Mage_All_Latest-1.6.1.0-beta1.xml create mode 100644 var/package/Mage_All_Latest-1.6.1.0-rc1.xml rename var/package/{Mage_Centinel-1.6.1.0-beta1.xml => Mage_Centinel-1.6.1.0-rc1.xml} (97%) rename var/package/{Mage_Core_Adminhtml-1.6.1.0-beta1.xml => Mage_Core_Adminhtml-1.6.1.0-rc1.xml} (99%) rename var/package/{Mage_Core_Modules-1.6.1.0-beta1.xml => Mage_Core_Modules-1.6.1.0-rc1.xml} (93%) rename var/package/{Mage_Downloader-1.6.1.0-beta1.xml => Mage_Downloader-1.6.1.0-rc1.xml} (98%) rename var/package/{Mage_Locale_en_US-1.6.1.0-beta1.xml => Mage_Locale_en_US-1.6.1.0-rc1.xml} (89%) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index d9dfccc3c2..291d8b802a 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,3 +1,179 @@ +==== 1.6.1.0-rc1 ==== + +=== Major Highlights === +Added two-step password reset flow + +=== Improvements === +XmlConnect package release v22.0 +Added support for using Shift-Click to select a range of grid rows when clicking check boxes +Added ability to register during checkout when using PayPal Express +Updated PayflowLink HSS user interface in checkout +"Add to Wishlist", "Add to Compare" were added on the Product Details Page for configurable, bundled and downloadable products + +=== Changes === +TheFind integration was removed +Google Optimizer was removed (it will be supported as a core extension) +Improved how discounts are applied to sub products + +=== Fixes === +Fixed Incorrect behavior of changing quantity for composite products in Wishlist tab of customer's page in backend +Fixed Incorrect tax summary if product prices exclude tax +Fixed Redirect to blank page, when click Add Wishlist on the Bundle product page +Fixed Reviews not showing in category list page +Fixed QTY is wrong calculated for Bundle, Virtual, Simple, Configurable, Downloadable products after editing them in wishlist +Fixed Customer is redirected to shopping cart page instead to the "Ship to Multiple Addresses" page after login or register as a new customer +Fixed Configurable product with selected option is deleted from wishlist after updating another configurable product +Fixed After redirecting to product using tag 'click for price' doesn't work +Fixed "Notify for Quantity Below" doesn't work +Fixed Pending Reviews RSS doesn't show reviews, created for products, that are assigned not to Main Website +Fixed Authorize Direct Post: no successful notification about place order if do 'Edit' or 'Reorder' +Fixed Impossible to place Order with Payfowlink when Payment Action = Sale +Fixed Poll shows incorrect percentage +Fixed Message 'Cannot specify wishlist item.' is displayed by configuring products in wishlist in back-end +Fixed Billing Agreements: Order status is not updated if do actions from sandbox PayPal account +Fixed Additional authorization transaction is not displayed in Order's Transactions tab +Fixed Unable to update already created role by Admin +Fixed CDN Secure URL is used instead of non-secure +Fixed Attributes name disappeared during sorting +Fixed Typo in app/design/adminhtml/default/default/template/paypal/system/config/payflowlink/info.phtml +Fixed Report of Reviews shows all customer reviews when select certain user +Fixed Address Line Formats Incorrectly on PDF Invoices +Fixed Can't search transactions by order_id in manager.paypal.com +Fixed Wishlist Index Controller does unneeded logging of exception +Fixed Incorrect SQL generated in review product collection resource +Fixed Added shipping address rates collecting schedule for shipping method when shipping information step bypassed +Fixed Customer marked as guest in "Newsletter Subscribers" grid, after subscribing to newsletters in Google Checkout +Fixed Error is displayed by unchecking "Same As Billing Address" by creating order in admin +Fixed Tooltip doesn't appear if you put mouse pointer in to disabled package type field (in case with USPS Domestic) +Fixed Unable to select custom theme with underscores in name when creating a widget instance +Fixed When Redirect to Shopping Cart = No, choosing Remove item from shopping cart sidebar while editing an item leads to endless redirect loop +Fixed Saved CC form is not displayed, when there are no other available payment methods except Saved CC +Fixed It's impossible to create Catalog Price Rule +Fixed Fatal error on Multiple Addresses Checkout +Fixed Package Types that not available for current Shipping Method displayed in Create Packages pop-up +Fixed Stock item product getter not correspond to product setter +- added method getProduct() +Fixed Admin user interface: mistakes in labels names +Fixed Typo in Mage_Eav_Model_Resource_Entity_Attribute_Option model +Fixed Billing Agreement error +Fixed Payflow Link UI Changes +Fixed 'Website Payments Pro' impossible to place order during onepage checkout +Fixed Table rates works incorrect with asterisk +Fixed Typo in Category Resource Model +Fixed 3D secure with Saved CC works incorrectly +- removed unrelated message which told validation failed (even if it has actually succeeded) when trying to re-validate a card +Fixed Bug in Role Permission +Fixed Orders placed via Google Checkout were not created on the Magento side +Fixed When using direct Export, the _super_product_sku and _super_product_option on the configurable product does not match +Fixed Composite product price in grid is displayed incorrectly with some currencies due to JS regexp problem +Fixed No error message on Payflow link iframe +Fixed Flex uploader elements overlaps hovering menu items in backend +Fixed Unable to upload images in Magento installed on local server +Fixed Configurable Products - Use Default (attribute name) does not work correctly on IE9 +Fixed Capture failed when Verification Authorization Amount is set to Zero +Fixed Attribute is sorted like a string even when Input Validation for Store Owner is an Integer Number +Fixed Void and Cancel Order doesn't work (PayflowLink HSS) +Fixed Grand Total (Excl Tax) with negative value displays in the printed Credit Memo +Fixed Resource model of Media module is wrongly declared +Fixed Constraint violation with core_cache_tag table +Fixed Misprint in \downloader\lib\Mage\Connect\Validator.php +Fixed XMLRPC API attribute status changing +Fixed Typo in Mage_Rss_Block_Catalog_Category::_toHtml() method +Fixed Incorrect tax summary for partial credit memos/invoices +Fixed SSL is not used for links in email templates when admin area is configured to use HTTPS +Fixed Incorrect style on product page +Fixed Error is displayed by editing product or by creating product on back-end in IE8 +Fixed Catalog price rules for composite products changes +Fixed Moving modules to the correct place +Fixed Wishlist shows items per store scope, not website +Fixed Products in Wishlist disappears, when Store View is changed +Fixed Wrong Comments History in notification of order creation/cancellation +Fixed In AJAX popup fields "From" and "To" have behavior as mandatory fields +Fixed Filter by Allow Countries not working for Customer Address Form in the Backend +Fixed Product price lower than 0 (after catalog price rule applying) +Fixed Google Checkout throws error if Zip Range is used for Tax Rate +- changed part of XML request to Google responsible for postal codes +- made changes to correctly fetch tax rules for postal code ranges +Fixed Website config object is not being cached +Fixed Select groups in grid view doesn't work under IE7 +Fixed No products name in Popular tags report file .csv +Fixed Qty Increments should work when it was defined in the default scope configuration +Fixed Products in catalog displays as "out of stock" +Fixed "Get help for this page" in each tab under System->Configuration links to the same help page +Fixed Unable to translate submenu +Fixed Redirect to main page of front-end during deleting Product Tax Class which is used in Tax Rule +Fixed Redirect to base URL should consider full request URI string +Fixed Incorrect transparency of PNG image in indexed non-alpha mode +Fixed Problem of generation URL between different domains +Fixed There are no server side validation of first character of Attribute Code (it should be letter) +Fixed Edit Order without creating new one functionality saves invalid changes in non-default customer address attributes +Fixed Frontend: If second customer logs in and does not select the "Remember Me" then the previous long-term cookie does not removes +Fixed Admin can Reorder order with status On Hold +Fixed Frontend: After new customer registration with "Remember Me" and pressing "Logout" the long-term cookie session doesn't apply if in configuration on backend ""Remember Me" Default Value" - No +Fixed Tax not displaying on PayPal side for Express orders +Fixed Wishlist: Not configured grouped product has unneeded link "Show Details" +Fixed Removed the ability to work with customise admin url through the parameter base_url +Fixed Roles not displaying selected resources +Fixed Unable to use Import when compiler is enabled +Fixed Missing Translation Capability in Transactional Email Variable +Fixed productConfigure is undefined error is occurred during creation Order in Backend in IE8 browser +Fixed Zend Full Page Cache. Lifetime of the cookie is not equal to specified on "Cookie Lifetime" field +Fixed Incorrect price values for Bundle Product +Fixed Link does not pass validation if ends with .html +Fixed Incorrect Customs Value in Create Packages in case when price value contains decimals +Fixed Incorrect reports with updated_at filter +Fixed paypal_payment_transaction_clean job takes credentials form default config instead of website for Payflow Link +Fixed Wrong schedule time setup for paypal_payment_transaction_clean job for Payflow Link +Fixed Backend Error message "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'qwe' for key 2" appears after saving new Email Template with existing name +Fixed Rule Conditions logic +Fixed Error appears after Customer Group saving with name length more than 32 +Fixed Category product index run time +Fixed Sidebar cart is missing composite product options on category page +Fixed Missed validation for space character at the begin of unique fields +- improved validation of Attribute Set Name and validation of unique fields in Mage_Core_Model_Resource_Db_Abstract class +Fixed Ability to input uppercase, space, specials symbols in Order Status Code +Fixed Filter by Allow Countries not working for Customer Address Form in the Backend +Fixed No ability to create Shipping Label with "plus-four codes" Zip Code (in case with USPS Domestic) +Fixed Changing language twice -> Error 404 +Fixed The sort order in products page doesn't work +Fixed When a grouped product with configured price=0 is added to the wishlist and shared, adding the product to the cart leads to 404 error +Fixed Media Saves Incorrect Cached Config +- added options that disallow saving cache +Fixed Bundle Product items shows randomly instead of according to option +Fixed Ajax loader does not appears after click on Verify Card on Payflow Link +Fixed "Google Checkout - Carrier" in Magento backend as shipping method rather than the actual shipping method chosen +Fixed JavaScript error appears in checkout because of PSC after press 'Proceed to Checkout' +Fixed Admin user interface: mistakes in labels names +Fixed Problems with grid sorting on edit customer backend page +Fixed It is possible to change the price of the Bundle product from fixed to the dynamic at my store +Fixed Set special price via Catalog Product API is not working +Fixed Price is wrong calculated for bundle product with a zero price for its items on product details page +- subitem price calculation were fixed +Fixed Layout issue appears in IE9 on the grids (example Customers) +Fixed Impossible to press 'Continue' button to place in onepage +Fixed "Add to Wishlist", "Add to Compare" aren't presented for Configurable, bundle, downloadable, simple products on Product Details Page +Fixed Register during checkout with PayPal Express Checkout +Fixed Extension Packager does not read recursive directory if include expression use file mask +Fixed Newsletter Subscription Confirmation Message +Fixed Discount is wrong calculated for Shopping Cart Price Rules when some of them created with Coupon and another without Coupon +Fixed Subtotal (Incl.Tax) on invoices must not include tax applied to shipping amount +- shippingTax amount were excluded from subTotal value +Fixed "Maximum shipping amount allowed to refund" message shows amount excl. tax if Display Shipping Amount set to Including Tax +- adjusted function to include tax into allowed amount for shipping refund +Fixed Display Out of Stock Products must not be considered during admin order creation +Fixed Check box is not working correctly under "prices" of the Bundle products +Fixed CSS class missing +Fixed Frontend: JavaScript error appears if user registered on Checkout Page +Fixed Website config object is not being cached +- added functionality for memcache backend to split down data that is larger than slab size into chunks +Fixed Removed the ability to work with base_url +Fixed Custom design should be updated via import functionality +Fixed JS error during onepage checkout +Fixed Unable to translate "First name" and "Last name" fields on "Create an Account" page +Fixed After upgrading dashboard "Top 5 Search Terms" grid doesn't show search terms + + + ==== 1.6.1.0-beta1 ==== === Major Highlights === diff --git a/app/Mage.php b/app/Mage.php index aecdd9e4d8..240f870896 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -154,7 +154,7 @@ public static function getVersionInfo() 'minor' => '6', 'revision' => '1', 'patch' => '0', - 'stability' => 'beta', + 'stability' => 'rc', 'number' => '1', ); } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Tax.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Tax.php index e75da090c0..fc89023963 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Tax.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Tax.php @@ -49,6 +49,9 @@ public function getFullTaxInfo() if (empty($taxClassAmount)) { $rates = Mage::getModel('sales/order_tax')->getCollection()->loadByOrder($source)->toArray(); $taxClassAmount = Mage::getSingleton('tax/calculation')->reproduceProcess($rates['items']); + } else { + $shippingTax = Mage::helper('tax')->getShippingTax($source); + $taxClassAmount = array_merge($shippingTax, $taxClassAmount); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Options.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Options.php index 24c9952b57..1a1d984c0b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Options.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Options.php @@ -56,9 +56,10 @@ public function render(Varien_Object $row) } } return implode(', ', $res); - } - elseif (isset($options[$value])) { + } elseif (isset($options[$value])) { return $options[$value]; + } elseif (in_array($value, $options)) { + return $value; } return ''; } diff --git a/app/code/core/Mage/Bundle/Model/Observer.php b/app/code/core/Mage/Bundle/Model/Observer.php index 72c95bd163..61943827ca 100644 --- a/app/code/core/Mage/Bundle/Model/Observer.php +++ b/app/code/core/Mage/Bundle/Model/Observer.php @@ -62,7 +62,9 @@ public function prepareProductSave($observer) } } - $product->setCanSaveBundleSelections((bool)$request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly()); + $product->setCanSaveBundleSelections( + (bool)$request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly() + ); return $this; } @@ -100,7 +102,7 @@ public function appendUpsellProducts($observer) $resource = Mage::getResourceSingleton('bundle/selection'); $productIds = array_keys($collection->getItems()); - if ($limit <= count($productIds)) { + if (!is_null($limit) && $limit <= count($productIds)) { return $this; } @@ -124,12 +126,22 @@ public function appendUpsellProducts($observer) Mage::getSingleton('catalog/product_visibility') ->addVisibleInCatalogFilterToCollection($bundleCollection); - $bundleCollection->setPageSize($limit - count($productIds)) - ->addFieldToFilter('entity_id', array('in' => $bundleIds)) + if (!is_null($limit)) { + $bundleCollection->setPageSize($limit); + } + $bundleCollection->addFieldToFilter('entity_id', array('in' => $bundleIds)) ->setFlag('do_not_use_category_id', true); - foreach ($bundleCollection as $item) { - $collection->addItem($item); + if ($collection instanceof Varien_Data_Collection) { + foreach ($bundleCollection as $item) { + $collection->addItem($item); + } + } elseif ($collection instanceof Varien_Object) { + $items = $collection->getItems(); + foreach ($bundleCollection as $item) { + $items[$item->getEntityId()] = $item; + } + $collection->setItems($items); } return $this; diff --git a/app/code/core/Mage/Bundle/Model/Product/Type.php b/app/code/core/Mage/Bundle/Model/Product/Type.php index c33a1da6f9..a63111940d 100644 --- a/app/code/core/Mage/Bundle/Model/Product/Type.php +++ b/app/code/core/Mage/Bundle/Model/Product/Type.php @@ -552,7 +552,6 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process return Mage::helper('bundle')->__('Please select options for product.'); } - //$optionsCollection = $this->getOptionsByIds($optionIds, $product); $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product); $optionsCollection = $this->getOptionsCollection($product); if (!$this->getProduct($product)->getSkipCheckRequiredOption() && $isStrictProcessMode) { @@ -577,31 +576,33 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process } } } + // If product has not been configured yet then $selections array should be empty + if (!empty($selectionIds)) { + $selections = $this->getSelectionsByIds($selectionIds, $product); - $selections = $this->getSelectionsByIds($selectionIds, $product); - - /** - * checking if selections that where added are still on sale - */ - foreach ($selections->getItems() as $key => $selection) { - if (!$selection->isSalable()) { - $_option = $optionsCollection->getItemById($selection->getOptionId()); - if (is_array($options[$_option->getId()]) && count($options[$_option->getId()]) > 1){ - $moreSelections = true; - } else { - $moreSelections = false; - } - if ($_option->getRequired() && - (!$_option->isMultiSelection() || ($_option->isMultiSelection() && !$moreSelections)) - ) { - return Mage::helper('bundle')->__('Selected required options are not available.'); + // Check if added selections are still on sale + foreach ($selections->getItems() as $key => $selection) { + if (!$selection->isSalable()) { + $_option = $optionsCollection->getItemById($selection->getOptionId()); + if (is_array($options[$_option->getId()]) && count($options[$_option->getId()]) > 1) { + $moreSelections = true; + } else { + $moreSelections = false; + } + if ($_option->getRequired() + && (!$_option->isMultiSelection() || ($_option->isMultiSelection() && !$moreSelections)) + ) { + return Mage::helper('bundle')->__('Selected required options are not available.'); + } } } - } - $optionsCollection->appendSelections($selections, false, $_appendAllSelections); + $optionsCollection->appendSelections($selections, false, $_appendAllSelections); - $selections = $selections->getItems(); + $selections = $selections->getItems(); + } else { + $selections = array(); + } } else { $product->setOptionsValidationFail(true); $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product); @@ -632,9 +633,7 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process $uniqueKey = array($product->getId()); $selectionIds = array(); - /* - * shaking selection array :) by option position - */ + // Shuffle selection array by option position usort($selections, array($this, 'shakeSelections')); foreach ($selections as $selection) { @@ -649,14 +648,14 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process $selection->addCustomOption('selection_id', $selection->getSelectionId()); $beforeQty = 0; - if ($customOption = $product->getCustomOption('product_qty_' . $selection->getId())) { + $customOption = $product->getCustomOption('product_qty_' . $selection->getId()); + if ($customOption) { $beforeQty = (float)$customOption->getValue(); } $product->addCustomOption('product_qty_' . $selection->getId(), $qty + $beforeQty, $selection); /* - * creating extra attributes that will be converted - * to product options in order item + * Create extra attributes that will be converted to product options in order item * for selection (not for all bundle) */ $price = $product->getPriceModel()->getSelectionPrice($product, $selection, $qty); @@ -667,7 +666,6 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process 'option_id' => $selection->getOption()->getId() ); - //if (!$product->getPriceType()) { $_result = $selection->getTypeInstance(true)->prepareForCart($buyRequest, $selection); if (is_string($_result) && !is_array($_result)) { return $_result; @@ -680,7 +678,6 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process $result[] = $_result[0]->setParentProductId($product->getId()) ->addCustomOption('bundle_option_ids', serialize(array_map('intval', $optionIds))) ->addCustomOption('bundle_selection_attributes', serialize($attributes)); - //} if ($isStrictProcessMode) { $_result[0]->setCartQty($qty); @@ -690,14 +687,13 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process $uniqueKey[] = $_result[0]->getSelectionId(); $uniqueKey[] = $qty; } - /** - * "unique" key for bundle selection and add it to selections and bundle for selections - */ + + // "unique" key for bundle selection and add it to selections and bundle for selections $uniqueKey = implode('_', $uniqueKey); foreach ($result as $item) { $item->addCustomOption('bundle_identity', $uniqueKey); } - $product->addCustomOption('bundle_option_ids', serialize(array_map('intval',$optionIds))); + $product->addCustomOption('bundle_option_ids', serialize(array_map('intval', $optionIds))); $product->addCustomOption('bundle_selection_ids', serialize($selectionIds)); return $result; diff --git a/app/code/core/Mage/Catalog/Block/Product/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/Abstract.php index e0263c04dd..e573a5163e 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/Abstract.php @@ -280,13 +280,14 @@ public function addReviewSummaryTemplate($type, $template) protected function _initReviewsHelperBlock() { if (!$this->_reviewsHelperBlock) { - if (Mage::helper('catalog')->isModuleEnabled('Mage_Review')) { + if (!Mage::helper('catalog')->isModuleEnabled('Mage_Review')) { + return false; + } else { $this->_reviewsHelperBlock = $this->getLayout()->createBlock('review/helper'); - return true; } } - return false; + return true; } /** diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php b/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php index 26dfa56dc1..25839fba41 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php @@ -122,6 +122,11 @@ abstract class Mage_Catalog_Model_Product_Type_Abstract */ const PROCESS_MODE_LITE = 'lite'; + /** + * Item options prefix + */ + const OPTION_PREFIX = 'option_'; + /** * Specify type instance product * @@ -357,7 +362,7 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process $optionIds = array_keys($options); $product->addCustomOption('option_ids', implode(',', $optionIds)); foreach ($options as $optionId => $optionValue) { - $product->addCustomOption('option_'.$optionId, $optionValue); + $product->addCustomOption(self::OPTION_PREFIX . $optionId, $optionValue); } } @@ -569,7 +574,8 @@ public function checkProductBuyState($product = null) if (!$this->getProduct($product)->getSkipCheckRequiredOption()) { foreach ($this->getProduct($product)->getOptions() as $option) { if ($option->getIsRequire()) { - $customOption = $this->getProduct($product)->getCustomOption('option_' . $option->getId()); + $customOption = $this->getProduct($product) + ->getCustomOption(self::OPTION_PREFIX . $option->getId()); if (!$customOption || strlen($customOption->getValue()) == 0) { $this->getProduct($product)->setSkipCheckRequiredOption(true); Mage::throwException( @@ -601,7 +607,8 @@ public function getOrderOptions($product = null) foreach (explode(',', $optionIds->getValue()) as $optionId) { if ($option = $this->getProduct($product)->getOptionById($optionId)) { - $confItemOption = $this->getProduct($product)->getCustomOption('option_'.$option->getId()); + $confItemOption = $this->getProduct($product) + ->getCustomOption(self::OPTION_PREFIX . $option->getId()); $group = $option->groupFactory($option->getType()) ->setOption($option) @@ -740,7 +747,7 @@ public function getOptionSku($product = null, $sku='') foreach (explode(',', $optionIds->getValue()) as $optionId) { if ($option = $this->getProduct($product)->getOptionById($optionId)) { - $confItemOption = $this->getProduct($product)->getCustomOption('option_'.$optionId); + $confItemOption = $this->getProduct($product)->getCustomOption(self::OPTION_PREFIX . $optionId); $group = $option->groupFactory($option->getType()) ->setOption($option)->setListener(new Varien_Object()); diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 5d89aada2e..7ad0cca693 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -332,6 +332,11 @@ public function saveBilling($data, $customerAddressId) $this->getQuote()->collectTotals(); $this->getQuote()->save(); + if (!$this->getQuote()->isVirtual() && $this->getCheckout()->getStepData('shipping', 'complete') == true) { + //Recollect Shipping rates for shipping methods + $this->getQuote()->getShippingAddress()->setCollectShippingRates(true); + } + $this->getCheckout() ->setStepData('billing', 'allow', true) ->setStepData('billing', 'complete', true) diff --git a/app/code/core/Mage/Checkout/controllers/CartController.php b/app/code/core/Mage/Checkout/controllers/CartController.php index 33970d101e..35903de569 100644 --- a/app/code/core/Mage/Checkout/controllers/CartController.php +++ b/app/code/core/Mage/Checkout/controllers/CartController.php @@ -272,7 +272,7 @@ public function configureAction() if (!$quoteItem) { $this->_getSession()->addError($this->__('Quote item is not found.')); - $this->_goBack(); + $this->_redirect('checkout/cart'); return; } diff --git a/app/code/core/Mage/Checkout/controllers/MultishippingController.php b/app/code/core/Mage/Checkout/controllers/MultishippingController.php index 43163e8da5..8af1443a57 100644 --- a/app/code/core/Mage/Checkout/controllers/MultishippingController.php +++ b/app/code/core/Mage/Checkout/controllers/MultishippingController.php @@ -553,7 +553,7 @@ public function successAction() public function redirectLogin() { $this->setFlag('', 'no-dispatch', true); - Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->_getRefererUrl()); + Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*', array('_secure'=>true))); $this->getResponse()->setRedirect( Mage::helper('core/url')->addRequestParam( diff --git a/app/code/core/Mage/Checkout/controllers/OnepageController.php b/app/code/core/Mage/Checkout/controllers/OnepageController.php index 2c30e661c3..536530122f 100644 --- a/app/code/core/Mage/Checkout/controllers/OnepageController.php +++ b/app/code/core/Mage/Checkout/controllers/OnepageController.php @@ -463,12 +463,12 @@ protected function _getOrder() protected function _initInvoice() { $items = array(); - foreach ($this->getOnepage()->getQuote()->getAllItems() as $item) { - $items[$item->getId()] = $item->getQty(); + foreach ($this->_getOrder()->getAllItems() as $item) { + $items[$item->getId()] = $item->getQtyOrdered(); } /* @var $invoice Mage_Sales_Model_Service_Order */ $invoice = Mage::getModel('sales/service_order', $this->_getOrder())->prepareInvoice($items); - $invoice->setEmailSent(true); + $invoice->setEmailSent(true)->register(); Mage::register('current_invoice', $invoice); return $invoice; @@ -509,7 +509,10 @@ public function saveOrderAction() && $paymentHelper->getZeroSubTotalOrderStatus($storeId) == 'pending') { $invoice = $this->_initInvoice(); $invoice->getOrder()->setIsInProcess(true); - $invoice->save(); + $transactionSave = Mage::getModel('core/resource_transaction') + ->addObject($invoice) + ->addObject($invoice->getOrder()); + $transactionSave->save(); } $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl(); diff --git a/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php b/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php index e0a6ac4eb9..c3bcd1c6a4 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php +++ b/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php @@ -416,19 +416,28 @@ public function rewrite(array $p) return $p; } - protected function _checkShouldBeSecure($request, $path='') + /** + * Check if request URL should be secure + * + * Function redirects user to correct URL if needed + * + * @param Mage_Core_Controller_Request_Http $request + * @param string $path + * @return null + */ + protected function _checkShouldBeSecure($request, $path = '') { if (!Mage::isInstalled() || $request->getPost()) { return; } - if ($this->_shouldBeSecure($path) && !Mage::app()->getStore()->isCurrentlySecure()) { + if ($this->_shouldBeSecure($path) && !$request->isSecure()) { $url = $this->_getCurrentSecureUrl($request); Mage::app()->getFrontController()->getResponse() ->setRedirect($url) ->sendResponse(); - exit; + exit(); } } diff --git a/app/code/core/Mage/Core/Model/Session/Abstract.php b/app/code/core/Mage/Core/Model/Session/Abstract.php index a0797a9801..d705cb1aae 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract.php @@ -539,7 +539,7 @@ public function getSessionSaveMethod() } /** - * Get sesssion save path + * Get session save path * * @return string */ diff --git a/app/code/core/Mage/Core/Model/Store.php b/app/code/core/Mage/Core/Model/Store.php index 7c1868169b..4c1279123b 100644 --- a/app/code/core/Mage/Core/Model/Store.php +++ b/app/code/core/Mage/Core/Model/Store.php @@ -683,7 +683,7 @@ public function isFrontUrlSecure() } /** - * Check if store is currently secure + * Check if request was secure * * @return boolean */ @@ -711,15 +711,9 @@ public function isCurrentlySecure() $uri = Zend_Uri::factory($secureBaseUrl); $port = $uri->getPort(); - $isSecure = false; - if (!empty($port)) { - $isSecure = ($uri->getScheme() == 'https') - && isset($_SERVER['SERVER_PORT']) - && ($port == $_SERVER['SERVER_PORT']); - } else { - $isSecure = ($uri->getScheme() == 'https'); - } - + $isSecure = ($uri->getScheme() == 'https') + && isset($_SERVER['SERVER_PORT']) + && ($port == $_SERVER['SERVER_PORT']); return $isSecure; } else { $isSecure = isset($_SERVER['SERVER_PORT']) && (443 == $_SERVER['SERVER_PORT']); diff --git a/app/code/core/Mage/Core/Model/Url.php b/app/code/core/Mage/Core/Model/Url.php index 8139ec2e8b..63bd855343 100644 --- a/app/code/core/Mage/Core/Model/Url.php +++ b/app/code/core/Mage/Core/Model/Url.php @@ -325,7 +325,7 @@ public function getSecure() $pathSecure = Mage::getConfig()->shouldUrlBeSecure('/' . $this->getActionPath()); $this->setData('secure', $pathSecure); } else { - $this->setData('secure', $store->isCurrentlySecure()); + $this->setData('secure', true); } } return $this->getData('secure'); diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index 567418d855..603e424b96 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -463,7 +463,8 @@ T: {{var telephone}} {{depend street2}}{{var street2}}|{{/depend}} {{depend street3}}{{var street3}}|{{/depend}} {{depend street4}}{{var street4}}|{{/depend}} -{{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}| +{{if city}}{{var city}},|{{/if}} +{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}| {{var country}}| {{depend telephone}}T: {{var telephone}}{{/depend}}| {{depend fax}}<br/>F: {{var fax}}{{/depend}}| diff --git a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Callback.php b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Callback.php index 66d65568e0..a9418d6ca3 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Callback.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Callback.php @@ -440,7 +440,13 @@ protected function _responseNewOrderNotification() $quote->setIsActive(false)->save(); if ($emailAllowed) { - Mage::getModel('newsletter/subscriber')->subscribe($order->getCustomerEmail()); + $customer = $quote->getCustomer(); + if ($customer && $customer->getId()) { + $customer->setIsSubscribed(true); + Mage::getModel('newsletter/subscriber')->subscribeCustomer($customer); + } else { + Mage::getModel('newsletter/subscriber')->subscribe($order->getCustomerEmail()); + } } Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $quote)); diff --git a/app/code/core/Mage/GoogleCheckout/controllers/RedirectController.php b/app/code/core/Mage/GoogleCheckout/controllers/RedirectController.php index a1e570c34b..0f37aeff90 100644 --- a/app/code/core/Mage/GoogleCheckout/controllers/RedirectController.php +++ b/app/code/core/Mage/GoogleCheckout/controllers/RedirectController.php @@ -170,7 +170,7 @@ public function continueAction() public function redirectLogin() { $this->setFlag('', 'no-dispatch', true); - Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->_getRefererUrl()); + Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_secure'=>true))); $this->getResponse()->setRedirect( Mage::helper('core/url')->addRequestParam( Mage::helper('customer')->getLoginUrl(), diff --git a/app/code/core/Mage/Paypal/Model/Api/Nvp.php b/app/code/core/Mage/Paypal/Model/Api/Nvp.php index ba318ebaa3..54bbb7ec2e 100644 --- a/app/code/core/Mage/Paypal/Model/Api/Nvp.php +++ b/app/code/core/Mage/Paypal/Model/Api/Nvp.php @@ -488,7 +488,7 @@ class Mage_Paypal_Model_Api_Nvp extends Mage_Paypal_Model_Api_Abstract * @var array */ protected $_doReferenceTransactionRequest = array('REFERENCEID', 'PAYMENTACTION', 'AMT', 'ITEMAMT', 'SHIPPINGAMT', - 'TAXAMT' + 'TAXAMT', 'INVNUM', 'NOTIFYURL' ); protected $_doReferenceTransactionResponse = array('BILLINGAGREEMENTID', 'TRANSACTIONID'); diff --git a/app/code/core/Mage/Paypal/Model/Config.php b/app/code/core/Mage/Paypal/Model/Config.php index d813c0fe81..e0f4a267a2 100644 --- a/app/code/core/Mage/Paypal/Model/Config.php +++ b/app/code/core/Mage/Paypal/Model/Config.php @@ -304,8 +304,8 @@ public function setStoreId($storeId) public function isMethodActive($method) { if ($this->isMethodSupportedForCountry($method) - && Mage::getStoreConfigFlag("payment/{$method}/active", $this->_storeId)) - { + && Mage::getStoreConfigFlag("payment/{$method}/active", $this->_storeId) + ) { return true; } return false; @@ -476,6 +476,7 @@ public function getCountryMethods($countryCode = null) self::METHOD_WPS, self::METHOD_WPP_DIRECT, self::METHOD_WPP_EXPRESS, + self::METHOD_BILLING_AGREEMENT, self::METHOD_WPP_PE_DIRECT, self::METHOD_WPP_PE_EXPRESS, self::METHOD_PAYFLOWPRO, @@ -485,6 +486,7 @@ public function getCountryMethods($countryCode = null) self::METHOD_WPS, self::METHOD_WPP_DIRECT, self::METHOD_WPP_EXPRESS, + self::METHOD_BILLING_AGREEMENT, self::METHOD_PAYFLOWPRO, self::METHOD_PAYFLOWLINK, ), @@ -492,6 +494,7 @@ public function getCountryMethods($countryCode = null) self::METHOD_WPS, self::METHOD_WPP_DIRECT, self::METHOD_WPP_EXPRESS, + self::METHOD_BILLING_AGREEMENT, self::METHOD_WPP_PE_DIRECT, self::METHOD_WPP_PE_EXPRESS, self::METHOD_HOSTEDPRO, @@ -499,23 +502,27 @@ public function getCountryMethods($countryCode = null) 'AU' => array( self::METHOD_WPS, self::METHOD_WPP_EXPRESS, + self::METHOD_BILLING_AGREEMENT, self::METHOD_PAYFLOWPRO, self::METHOD_HOSTEDPRO, ), 'NZ' => array( self::METHOD_WPS, self::METHOD_WPP_EXPRESS, + self::METHOD_BILLING_AGREEMENT, self::METHOD_PAYFLOWPRO, self::METHOD_HOSTEDPRO, ), 'DE' => array( self::METHOD_WPS, self::METHOD_WPP_EXPRESS, + self::METHOD_BILLING_AGREEMENT, self::METHOD_HOSTEDPRO, ), 'other' => array( self::METHOD_WPS, self::METHOD_WPP_EXPRESS, + self::METHOD_BILLING_AGREEMENT, self::METHOD_HOSTEDPRO, ) ); diff --git a/app/code/core/Mage/Paypal/Model/Ipn.php b/app/code/core/Mage/Paypal/Model/Ipn.php index 44ecd92673..e9da8a45db 100644 --- a/app/code/core/Mage/Paypal/Model/Ipn.php +++ b/app/code/core/Mage/Paypal/Model/Ipn.php @@ -680,7 +680,7 @@ protected function _filterPaymentStatus($ipnPaymentStatus) */ protected function _debug() { - if ($this->_config->debug) { + if ($this->_config && $this->_config->debug) { $file = $this->_config->getMethodCode() ? "payment_{$this->_config->getMethodCode()}.log" : self::DEFAULT_LOG_FILE; Mage::getModel('core/log_adapter', $file)->log($this->_debugData); diff --git a/app/code/core/Mage/Paypal/Model/Method/Agreement.php b/app/code/core/Mage/Paypal/Model/Method/Agreement.php index d3d7d52ffb..497fd46355 100644 --- a/app/code/core/Mage/Paypal/Model/Method/Agreement.php +++ b/app/code/core/Mage/Paypal/Model/Method/Agreement.php @@ -307,6 +307,7 @@ protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount) ->setNotifyUrl(Mage::getUrl('paypal/ipn/')) ->setPaypalCart(Mage::getModel('paypal/cart', array($order))) ->setIsLineItemsEnabled($this->_pro->getConfig()->lineItemsEnabled) + ->setInvNum($order->getIncrementId()) ; // call api and import transaction and other payment information diff --git a/app/code/core/Mage/Paypal/Model/Payflowlink.php b/app/code/core/Mage/Paypal/Model/Payflowlink.php index 396796c981..2d833e86f5 100644 --- a/app/code/core/Mage/Paypal/Model/Payflowlink.php +++ b/app/code/core/Mage/Paypal/Model/Payflowlink.php @@ -253,8 +253,6 @@ public function capture(Varien_Object $payment, $amount) $transaction->loadByTxnId($txnId); if ($transaction->getId()) { $removePaypalTransaction = true; - $payment->setTransactionId($txnId); - $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH); $this->_authorize($payment, $amount, $transaction, $txnId); $this->_addTransaction($payment, $txnId); @@ -264,7 +262,7 @@ public function capture(Varien_Object $payment, $amount) $payment->setParentTransactionId($txnId); - $payment->setAmountOrdered(round($amount,2)); + $payment->setRequestAmount(round($amount,2)); parent::capture($payment, $amount); if ($removePaypalTransaction) { @@ -285,6 +283,7 @@ public function void(Varien_Object $payment) /** @var $payment Mage_Sales_Model_Quote_Payment */ if ($payment instanceof Mage_Sales_Model_Order_Payment) { parent::void($payment); + $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID); return $this; } elseif ($payment instanceof Mage_Sales_Model_Quote_Payment) { $this->setStore($payment->getQuote()->getStoreId()); @@ -564,8 +563,8 @@ protected function _buildBasicRequest(Varien_Object $payment) ->setPwd($this->getConfigData('pwd', $this->_getStoreId())) ->setVerbosity($this->getConfigData('verbosity', $this->_getStoreId())) ->setTender(self::TENDER_CC); - if ($payment->getAmountOrdered() > 0) { - $request->setAmt(round($payment->getAmountOrdered(),2)); + if ($payment->getRequestAmount() > 0) { + $request->setAmt(round($payment->getRequestAmount(),2)); } return $request; } diff --git a/app/code/core/Mage/Paypal/Model/Payflowpro.php b/app/code/core/Mage/Paypal/Model/Payflowpro.php index d101ea435d..45af5ebe71 100644 --- a/app/code/core/Mage/Paypal/Model/Payflowpro.php +++ b/app/code/core/Mage/Paypal/Model/Payflowpro.php @@ -404,7 +404,6 @@ protected function _buildPlaceRequest(Varien_Object $payment, $amount) { $request = $this->_buildBasicRequest($payment); $request->setAmt(round($amount,2)); - $request->setCurrency($payment->getOrder()->getBaseCurrencyCode()); $request->setAcct($payment->getCcNumber()); $request->setExpdate(sprintf('%02d',$payment->getCcExpMonth()) . substr($payment->getCcExpYear(),-2,2)); $request->setCvv2($payment->getCcCid()); @@ -417,6 +416,9 @@ protected function _buildPlaceRequest(Varien_Object $payment, $amount) $order = $payment->getOrder(); if(!empty($order)){ + $request->setCurrency($order->getBaseCurrencyCode()) + ->setCustref($order->getIncrementId()); + $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setFirstname($billing->getFirstname()) diff --git a/app/code/core/Mage/Paypal/etc/system.xml b/app/code/core/Mage/Paypal/etc/system.xml index 76121ec119..8da14aa53f 100644 --- a/app/code/core/Mage/Paypal/etc/system.xml +++ b/app/code/core/Mage/Paypal/etc/system.xml @@ -1626,7 +1626,7 @@ 1 - + payment/payflow_link/vendor text 45 diff --git a/app/code/core/Mage/Poll/Model/Resource/Poll.php b/app/code/core/Mage/Poll/Model/Resource/Poll.php index a8de3f194d..5d3f098cd4 100755 --- a/app/code/core/Mage/Poll/Model/Resource/Poll.php +++ b/app/code/core/Mage/Poll/Model/Resource/Poll.php @@ -169,16 +169,15 @@ public function getVotedPollIdsByIp($ipAddress, $pollId = false) */ public function resetVotesCount($object) { - $read = $this->_getReadAdapter(); - $select = $read->select(); - $select->from($this->getTable('poll_answer'), new Zend_Db_Expr("SUM(votes_count)")) - ->where('poll_id = :poll_id'); - - $count = $read->fetchOne($select, array(':poll_id' => $object->getPollId())); - - $write = $this->_getWriteAdapter(); - $condition = $write->quoteInto("{$this->getIdFieldName()} = ?", $object->getPollId()); - $write->update($this->getMainTable(), array('votes_count' => $count), $condition); + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from($this->getTable('poll_answer'), new Zend_Db_Expr("SUM(votes_count)")) + ->where('poll_id = ?', $object->getPollId()); + $adapter->update( + $this->getMainTable(), + array('votes_count' => new Zend_Db_Expr("($select)")), + array('poll_id = ' . $adapter->quote($object->getPollId())) + ); return $object; } diff --git a/app/code/core/Mage/Reports/Model/Resource/Review/Customer/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Review/Customer/Collection.php index 590424d09b..fd13f65050 100755 --- a/app/code/core/Mage/Reports/Model/Resource/Review/Customer/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Review/Customer/Collection.php @@ -91,6 +91,7 @@ public function joinCustomers() implode(' AND ', $lastnameCondition), array()) ->columns(array( + 'customer_id' => 'detail.customer_id', 'customer_name' => $customerFullname, 'review_cnt' => 'COUNT(main_table.review_id)')) ->group('detail.customer_id'); diff --git a/app/code/core/Mage/Review/Model/Resource/Review/Product/Collection.php b/app/code/core/Mage/Review/Model/Resource/Review/Product/Collection.php index da4753b03e..1101d18034 100755 --- a/app/code/core/Mage/Review/Model/Resource/Review/Product/Collection.php +++ b/app/code/core/Mage/Review/Model/Resource/Review/Product/Collection.php @@ -380,7 +380,7 @@ public function addAttributeToFilter($attribute, $condition = null, $joinType = case 'type': if ($condition == 1) { $conditionParts = array( - $this->_getConditionSql('rdt.customer_id', array('is' => 'NULL')), + $this->_getConditionSql('rdt.customer_id', array('is' => new Zend_Db_Expr('NULL'))), $this->_getConditionSql('rdt.store_id', array('eq' => Mage_Core_Model_App::ADMIN_STORE_ID)) ); $conditionSql = implode(' AND ', $conditionParts); @@ -388,7 +388,7 @@ public function addAttributeToFilter($attribute, $condition = null, $joinType = $conditionSql = $this->_getConditionSql('rdt.customer_id', array('gt' => 0)); } else { $conditionParts = array( - $this->_getConditionSql('rdt.customer_id', array('is' => 'NULL')), + $this->_getConditionSql('rdt.customer_id', array('is' => new Zend_Db_Expr('NULL'))), $this->_getConditionSql('rdt.store_id', array('neq' => Mage_Core_Model_App::ADMIN_STORE_ID)) ); $conditionSql = implode(' AND ', $conditionParts); diff --git a/app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php b/app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php index 382156bd4d..b2f824d6dc 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php +++ b/app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php @@ -41,6 +41,11 @@ class Mage_Rss_Block_Catalog_NotifyStock extends Mage_Rss_Block_Abstract */ const CACHE_TAG = 'block_html_rss_catalog_notifystock'; + /** + * Constructor + * + * @return null + */ protected function _construct() { $this->setCacheTags(array(self::CACHE_TAG)); @@ -51,45 +56,68 @@ protected function _construct() $this->setCacheLifetime(600); } + /** + * Render RSS + * + * @return string + */ protected function _toHtml() { - $newurl = Mage::getUrl('rss/catalog/notifystock'); - $title = Mage::helper('rss')->__('Low Stock Products'); + $newUrl = Mage::getUrl('rss/catalog/notifystock'); + /* @var $helper Mage_Rss_Helper_Data */ + $helper = Mage::helper('rss'); + $title = $helper->__('Low Stock Products'); $rssObj = Mage::getModel('rss/rss'); - $data = array('title' => $title, - 'description' => $title, - 'link' => $newurl, - 'charset' => 'UTF-8', + $data = array( + 'title' => $title, + 'description' => $title, + 'link' => $newUrl, + 'charset' => 'UTF-8', ); $rssObj->_addHeader($data); - $_configManageStock = (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); - $stockItemWhere = "({{table}}.low_stock_date is not null) " - . " AND ( ({{table}}.use_config_manage_stock=1 AND ".$_configManageStock."=1)" - . " OR ({{table}}.use_config_manage_stock=0 AND {{table}}.manage_stock=1) )"; - + $configManageStock = (int) Mage::getStoreConfigFlag( + Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); + $globalNotifyStockQty = (float) Mage::getStoreConfig( + Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY); + $helper->disableFlat(); + /* @var $product Mage_Catalog_Model_Product */ $product = Mage::getModel('catalog/product'); - $collection = $product->getCollection() - ->addAttributeToSelect('name', true) + /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */ + $collection = $product->getCollection(); + $stockItemTable = $collection->getTable('cataloginventory/stock_item'); + + $stockItemWhere = '({{table}}.low_stock_date is not null) ' + . " AND ( ({{table}}.use_config_manage_stock=1 AND {$configManageStock}=1)" + . " AND {{table}}.qty < " + . "IF({$stockItemTable}.`use_config_notify_stock_qty`, {$globalNotifyStockQty}, {{table}}.notify_stock_qty)" + . ' OR ({{table}}.use_config_manage_stock=0 AND {{table}}.manage_stock=1) )'; + + $collection ->addAttributeToSelect('name', true) ->joinTable('cataloginventory/stock_item', 'product_id=entity_id', - array('qty'=>'qty', 'notify_stock_qty'=>'notify_stock_qty', 'use_config' => 'use_config_notify_stock_qty','low_stock_date' => 'low_stock_date'), + array( + 'qty'=>'qty', + 'notify_stock_qty'=>'notify_stock_qty', + 'use_config' => 'use_config_notify_stock_qty', + 'low_stock_date' => 'low_stock_date'), $stockItemWhere, 'inner') - ->setOrder('low_stock_date') - ; - $collection->addAttributeToFilter('status', array('in' => Mage::getSingleton('catalog/product_status')->getVisibleStatusIds())); - - $_globalNotifyStockQty = (float) Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY); + ->setOrder('low_stock_date'); + $collection->addAttributeToFilter('status', + array('in' => Mage::getSingleton('catalog/product_status')->getVisibleStatusIds())); Mage::dispatchEvent('rss_catalog_notify_stock_collection_select', array('collection' => $collection)); /* using resource iterator to load the data one by one instead of loading all at the same time. loading all data at the same time can cause the big memory allocation. */ - Mage::getSingleton('core/resource_iterator') - ->walk($collection->getSelect(), array(array($this, 'addNotifyItemXmlCallback')), array('rssObj'=> $rssObj, 'product'=>$product, 'globalQty' => $_globalNotifyStockQty)); + Mage::getSingleton('core/resource_iterator')->walk( + $collection->getSelect(), + array(array($this, 'addNotifyItemXmlCallback')), + array('rssObj'=> $rssObj, 'product'=>$product, 'globalQty' => $globalNotifyStockQty) + ); return $rssObj->createRssXml(); } @@ -104,13 +132,15 @@ public function addNotifyItemXmlCallback($args) { $product = $args['product']; $product->setData($args['row']); - $url = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit/', array('id'=>$product->getId(),'_secure' => true,'_nosecret' => true)); - $description = Mage::helper('rss')->__('%s has reached a quantity of %s.', $product->getName(),(1*$product->getQty())); + $url = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit/', + array('id' => $product->getId(), '_secure' => true, '_nosecret' => true)); + $qty = 1 * $product->getQty(); + $description = Mage::helper('rss')->__('%s has reached a quantity of %s.', $product->getName(), $qty); $rssObj = $args['rssObj']; $data = array( - 'title' => $product->getName(), - 'link' => $url, - 'description' => $description, + 'title' => $product->getName(), + 'link' => $url, + 'description' => $description, ); $rssObj->_addEntry($data); } diff --git a/app/code/core/Mage/Rss/Block/Catalog/Review.php b/app/code/core/Mage/Rss/Block/Catalog/Review.php index 8086d87e58..456cd3cf09 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Review.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Review.php @@ -41,6 +41,11 @@ class Mage_Rss_Block_Catalog_Review extends Mage_Rss_Block_Abstract */ const CACHE_TAG = 'block_html_rss_catalog_review'; + /** + * Initialize cache + * + * @return null + */ protected function _construct() { $this->setCacheTags(array(self::CACHE_TAG)); @@ -51,17 +56,26 @@ protected function _construct() $this->setCacheLifetime(600); } + /** + * Render XML response + * + * @return string + */ protected function _toHtml() { - $newurl = Mage::getUrl('rss/catalog/review'); - $title = Mage::helper('rss')->__('Pending product review(s)'); + $newUrl = Mage::getUrl('rss/catalog/review'); + /* @var $helper Mage_Rss_Helper_Data */ + $helper = Mage::helper('rss'); + $title = $helper->__('Pending product review(s)'); + $helper->disableFlat(); $rssObj = Mage::getModel('rss/rss'); - $data = array('title' => $title, - 'description' => $title, - 'link' => $newurl, - 'charset' => 'UTF-8', - ); + $data = array( + 'title' => $title, + 'description' => $title, + 'link' => $newUrl, + 'charset' => 'UTF-8', + ); $rssObj->_addHeader($data); $reviewModel = Mage::getModel('review/review'); @@ -73,36 +87,44 @@ protected function _toHtml() Mage::dispatchEvent('rss_catalog_review_collection_select', array('collection' => $collection)); - Mage::getSingleton('core/resource_iterator') - ->walk($collection->getSelect(), array(array($this, 'addReviewItemXmlCallback')), array('rssObj'=> $rssObj, 'reviewModel'=> $reviewModel)); + Mage::getSingleton('core/resource_iterator')->walk( + $collection->getSelect(), + array(array($this, 'addReviewItemXmlCallback')), + array('rssObj'=> $rssObj, 'reviewModel'=> $reviewModel)); return $rssObj->createRssXml(); } + /** + * Format single RSS element + * + * @param array $args + * @return null + */ public function addReviewItemXmlCallback($args) { $rssObj = $args['rssObj']; - $reviewModel = $args['reviewModel']; $row = $args['row']; $store = Mage::app()->getStore($row['store_id']); $urlModel = Mage::getModel('core/url')->setStore($store); - $productUrl = $urlModel->getUrl('catalog/product/view', array('id'=>$row['entity_id'])); - $reviewUrl = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product_review/edit/', array('id'=>$row['review_id'], '_secure' => true, '_nosecret'=>true)); + $productUrl = $urlModel->getUrl('catalog/product/view', array('id' => $row['entity_id'])); + $reviewUrl = Mage::helper('adminhtml')->getUrl( + 'adminhtml/catalog_product_review/edit/', + array('id' => $row['review_id'], '_secure' => true, '_nosecret' => true)); $storeName = $store->getName(); - $description = '

'. - $this->__('Product: %s
',$productUrl,$row['name']). - $this->__('Summary of review: %s
',$row['title']). - $this->__('Review: %s
', $row['detail']). - $this->__('Store: %s
', $storeName ). - $this->__('click here to view the review',$reviewUrl). - '

' - ; + $description = '

' + . $this->__('Product: %s
', $productUrl, $row['name']) + . $this->__('Summary of review: %s
', $row['title']) + . $this->__('Review: %s
', $row['detail']) + . $this->__('Store: %s
', $storeName ) + . $this->__('click here to view the review', $reviewUrl) + . '

'; $data = array( - 'title' => $this->__('Product: "%s" review By: %s',$row['name'],$row['nickname']), - 'link' => 'test', - 'description' => $description, - ); + 'title' => $this->__('Product: "%s" review By: %s', $row['name'], $row['nickname']), + 'link' => 'test', + 'description' => $description, + ); $rssObj->_addEntry($data); } } diff --git a/app/code/core/Mage/Rss/Helper/Data.php b/app/code/core/Mage/Rss/Helper/Data.php index 98369c9aea..a5f64b117f 100644 --- a/app/code/core/Mage/Rss/Helper/Data.php +++ b/app/code/core/Mage/Rss/Helper/Data.php @@ -96,4 +96,23 @@ public function authFailed() { Mage::helper('core/http')->authFailed(); } + + /** + * Disable using of flat catalog and/or product model to prevent limiting results to single store. Probably won't + * work inside a controller. + * + * @return null + */ + public function disableFlat() + { + /* @var $flatHelper Mage_Catalog_Helper_Product_Flat */ + $flatHelper = Mage::helper('catalog/product_flat'); + if ($flatHelper->isEnabled()) { + /* @var $emulationModel Mage_Core_Model_App_Emulation */ + $emulationModel = Mage::getModel('core/app_emulation'); + // Emulate admin environment to disable using flat model - otherwise we won't get global stats + // for all stores + $emulationModel->startEnvironmentEmulation(0, Mage_Core_Model_App_Area::AREA_ADMINHTML); + } + } } diff --git a/app/code/core/Mage/Sales/Model/Order/Payment.php b/app/code/core/Mage/Sales/Model/Order/Payment.php index 0e96b68cd2..a3530f8a54 100644 --- a/app/code/core/Mage/Sales/Model/Order/Payment.php +++ b/app/code/core/Mage/Sales/Model/Order/Payment.php @@ -1382,7 +1382,8 @@ protected function _lookupTransaction($txnId, $txnType = false) ->setOrderFilter($this->getOrder()) ->addPaymentIdFilter($this->getId()) ->addTxnTypeFilter($txnType) - ->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC); + ->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC) + ->setOrder('transaction_id', Varien_Data_Collection::SORT_ORDER_DESC); foreach ($collection as $txn) { $txn->setOrderPaymentObject($this); $this->_transactionsLookup[$txn->getTxnId()] = $txn; diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php index c0b09b9111..cc41f5cd9a 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php @@ -70,6 +70,9 @@ public function getFullTaxInfo() $fontSize = $this->getFontSize() ? $this->getFontSize() : 7; if (!empty($taxClassAmount)) { + $shippingTax = Mage::helper('tax')->getShippingTax($this->getOrder()); + $taxClassAmount = array_merge($shippingTax, $taxClassAmount); + foreach ($taxClassAmount as &$tax) { $percent = $tax['percent'] ? ' (' . $tax['percent']. '%)' : ''; $tax['amount'] = $this->getAmountPrefix().$this->getOrder()->formatPriceTxt($tax['tax_amount']); diff --git a/app/code/core/Mage/Sales/controllers/DownloadController.php b/app/code/core/Mage/Sales/controllers/DownloadController.php index c242a4afd8..2fb7e71504 100644 --- a/app/code/core/Mage/Sales/controllers/DownloadController.php +++ b/app/code/core/Mage/Sales/controllers/DownloadController.php @@ -148,12 +148,33 @@ public function downloadProfileCustomOptionAction() public function downloadCustomOptionAction() { $quoteItemOptionId = $this->getRequest()->getParam('id'); + /** @var $option Mage_Sales_Model_Quote_Item_Option */ $option = Mage::getModel('sales/quote_item_option')->load($quoteItemOptionId); - if (!$option->getId() || $option->getCode() == 'info_buyRequest') { + if (!$option->getId()) { $this->_forward('noRoute'); return; } + + $optionId = null; + if (strpos($option->getCode(), Mage_Catalog_Model_Product_Type_Abstract::OPTION_PREFIX) === 0) { + $optionId = str_replace(Mage_Catalog_Model_Product_Type_Abstract::OPTION_PREFIX, '', $option->getCode()); + if ((int)$optionId != $optionId) { + $optionId = null; + } + } + $productOption = null; + if ($optionId) { + /** @var $productOption Mage_Catalog_Model_Product_Option */ + $productOption = Mage::getModel('catalog/product_option')->load($optionId); + } + if (!$productOption || !$productOption->getId() + || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file' + ) { + $this->_forward('noRoute'); + return; + } + try { $info = unserialize($option->getValue()); $this->_downloadFileAction($info); diff --git a/app/code/core/Mage/Tax/Helper/Data.php b/app/code/core/Mage/Tax/Helper/Data.php index 836b3e891d..b72ace3b10 100644 --- a/app/code/core/Mage/Tax/Helper/Data.php +++ b/app/code/core/Mage/Tax/Helper/Data.php @@ -783,15 +783,18 @@ public function getCalculationAgorithm($store=null) /** * Get calculated taxes for each tax class * - * @param Mage_Sales_Model_Order $source - * + * This method returns array with format: * array( * $index => array( * 'tax_amount' => $taxAmount, * 'base_tax_amount' => $baseTaxAmount, * 'hidden_tax_amount' => $hiddenTaxAmount + * 'title' => $title + * 'percent' => $percent * ) * ) + * + * @param Mage_Sales_Model_Order $source * @return array */ public function getCalculatedTaxes($source) @@ -806,11 +809,6 @@ public function getCalculatedTaxes($source) $taxClassAmount = array(); if ($current && $source) { - $shippingTaxAmount = $current->getShippingTaxAmount(); - $baseShippingTaxAmount = $current->getBaseShippingTaxAmount(); - $shippingHiddenTaxAmount = $current->getShippingHiddenTaxAmount(); - - $i = 0; foreach($current->getItemsCollection() as $item) { $taxCollection = Mage::getResourceModel('tax/sales_order_tax_item') ->getTaxItemsByItemId( @@ -819,25 +817,15 @@ public function getCalculatedTaxes($source) foreach ($taxCollection as $tax) { $taxClassId = $tax['tax_id']; - $percent = $tax['percent']; + $percent = $tax['tax_percent']; if (isset($taxClassAmount[$taxClassId])) { $taxClassAmount[$taxClassId]['tax_amount'] += $item->getRowTotal() * $percent / 100; $taxClassAmount[$taxClassId]['base_tax_amount'] += $item->getBaseRowTotal() * $percent / 100; $taxClassAmount[$taxClassId]['hidden_tax_amount'] += $item->getHiddenTaxAmount(); } else { - if ($i == 0) { - $i = 1; - $taxClassAmount[$taxClassId]['tax_amount'] = $shippingTaxAmount; - $taxClassAmount[$taxClassId]['base_tax_amount'] = $baseShippingTaxAmount; - $taxClassAmount[$taxClassId]['hidden_tax_amount'] = $shippingHiddenTaxAmount; - } else { - $taxClassAmount[$taxClassId]['tax_amount'] = 0; - $taxClassAmount[$taxClassId]['base_tax_amount'] = 0; - $taxClassAmount[$taxClassId]['hidden_tax_amount'] = 0; - } - $taxClassAmount[$taxClassId]['tax_amount'] += $item->getRowTotal() * $percent / 100; - $taxClassAmount[$taxClassId]['base_tax_amount'] += $item->getBaseRowTotal() * $percent / 100; - $taxClassAmount[$taxClassId]['hidden_tax_amount'] += $item->getHiddenTaxAmount(); + $taxClassAmount[$taxClassId]['tax_amount'] = $item->getRowTotal() * $percent / 100; + $taxClassAmount[$taxClassId]['base_tax_amount'] = $item->getBaseRowTotal() * $percent / 100; + $taxClassAmount[$taxClassId]['hidden_tax_amount'] = $item->getHiddenTaxAmount(); $taxClassAmount[$taxClassId]['title'] = $tax['title']; $taxClassAmount[$taxClassId]['percent'] = $tax['percent']; } @@ -845,7 +833,7 @@ public function getCalculatedTaxes($source) } foreach ($taxClassAmount as $key=>$tax) { - if ($tax['tax_amount'] == 0 && $tax['base_tax_amount'] == 0 && $tax['hidden_tax_amount'] == 0) { + if ($tax['tax_amount'] == 0 && $tax['base_tax_amount'] == 0) { unset($taxClassAmount[$key]); } } @@ -855,4 +843,47 @@ public function getCalculatedTaxes($source) return $taxClassAmount; } + + /** + * Get calculated Shipping & Handling Tax + * + * This method returns array with format: + * array( + * $index => array( + * 'tax_amount' => $taxAmount, + * 'base_tax_amount' => $baseTaxAmount, + * 'hidden_tax_amount' => $hiddenTaxAmount + * 'title' => $title + * 'percent' => $percent + * ) + * ) + * + * @param Mage_Sales_Model_Order $source + * @return array + */ + public function getShippingTax($source) + { + if (Mage::registry('current_invoice')) { + $current = Mage::registry('current_invoice'); + } elseif (Mage::registry('current_creditmemo')) { + $current = Mage::registry('current_creditmemo'); + } else { + $current = $source; + } + + $taxClassAmount = array(); + if ($current && $source) { + if ($current->getShippingTaxAmount() != 0 && $current->getBaseShippingTaxAmount() != 0) { + $taxClassAmount[0]['tax_amount'] = $current->getShippingTaxAmount(); + $taxClassAmount[0]['base_tax_amount'] = $current->getBaseShippingTaxAmount(); + if ($current->getShippingHiddenTaxAmount() > 0) { + $taxClassAmount[0]['hidden_tax_amount'] = $current->getShippingHiddenTaxAmount(); + } + $taxClassAmount[0]['title'] = $this->__('Shipping & Handling Tax'); + $taxClassAmount[0]['percent'] = NULL; + } + } + + return $taxClassAmount; + } } diff --git a/app/code/core/Mage/Tax/Model/Observer.php b/app/code/core/Mage/Tax/Model/Observer.php index 572149d2bf..d9dc2cc97a 100644 --- a/app/code/core/Mage/Tax/Model/Observer.php +++ b/app/code/core/Mage/Tax/Model/Observer.php @@ -70,10 +70,36 @@ public function salesEventOrderAfterSave(Varien_Event_Observer $observer) $ratesIdQuoteItemId = array(); foreach ($getTaxesForItems as $quoteItemId => $taxesArray) { foreach ($taxesArray as $rates) { - $ratesIdQuoteItemId[$rates['id']][] = $quoteItemId; + if (count($rates['rates']) == 1) { + $ratesIdQuoteItemId[$rates['id']][] = array( + 'id' => $quoteItemId, + 'percent' => $rates['percent'] + ); + } else { + $percentDelta = $rates['percent']; + $percentSum = 0; + foreach ($rates['rates'] as $rate) { + $ratesIdQuoteItemId[$rates['id']][] = array( + 'id' => $quoteItemId, + 'percent' => $rate['percent'] + ); + $percentSum += $rate['percent']; + } + + if ($percentDelta != $percentSum) { + $delta = $percentDelta - $percentSum; + foreach ($ratesIdQuoteItemId[$rates['id']] as &$rate) { + $rate = array( + 'id' => $rate['id'], + 'percent' => (($rate['percent'] / $percentSum) * $delta) + $rate['percent'] + ); + } + } + } } } + $a = array(); foreach ($taxes as $id => $row) { foreach ($row['rates'] as $tax) { if (is_null($row['percent'])) { @@ -100,22 +126,28 @@ public function salesEventOrderAfterSave(Varien_Event_Observer $observer) ); $result = Mage::getModel('tax/sales_order_tax')->setData($data)->save(); - if (isset($ratesIdQuoteItemId[$id])) { - foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) { - $item = $order->getItemByQuoteItemId($quoteItemId); - if ($item) { - $data = array( - 'item_id' => $item->getId(), - 'tax_id' => $result->getTaxId() - ); - Mage::getModel('tax/sales_order_tax_item')->setData($data)->save(); - } + + if (isset($a[$id])) { + $a[$id] = $a[$id]+1; + } else { + $a[$id] = 0; + } + + if (isset($ratesIdQuoteItemId[$id]) && isset($ratesIdQuoteItemId[$id][$a[$id]])) { + $quoteItemId = $ratesIdQuoteItemId[$id][$a[$id]]; + $item = $order->getItemByQuoteItemId($quoteItemId['id']); + if ($item) { + $data = array( + 'item_id' => $item->getId(), + 'tax_id' => $result->getTaxId(), + 'tax_percent' => $quoteItemId['percent'] + ); + Mage::getModel('tax/sales_order_tax_item')->setData($data)->save(); } } } } - $order->setAppliedTaxIsSaved(true); } diff --git a/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax/Item.php b/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax/Item.php index 37137c7b29..c986b31e6f 100755 --- a/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax/Item.php +++ b/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax/Item.php @@ -52,11 +52,11 @@ public function getTaxItemsByItemId($item_id) { $adapter = $this->_getReadAdapter(); $select = $adapter->select() - ->from(array('item' => $this->getTable('tax/sales_order_tax_item')), array('tax_id')) + ->from(array('item' => $this->getTable('tax/sales_order_tax_item')), array('tax_id', 'tax_percent')) ->join( array('tax' => $this->getTable('tax/sales_order_tax')), 'item.tax_id = tax.tax_id', - array('percent', 'title', 'percent') + array('title', 'percent', 'base_amount') ) ->where('item_id = ?', $item_id); diff --git a/app/code/core/Mage/Tax/etc/config.xml b/app/code/core/Mage/Tax/etc/config.xml index c519309d6f..e25aa95302 100644 --- a/app/code/core/Mage/Tax/etc/config.xml +++ b/app/code/core/Mage/Tax/etc/config.xml @@ -28,7 +28,7 @@ - 1.6.0.2 + 1.6.0.3 diff --git a/app/code/core/Mage/Tax/sql/tax_setup/upgrade-1.6.0.2-1.6.0.3.php b/app/code/core/Mage/Tax/sql/tax_setup/upgrade-1.6.0.2-1.6.0.3.php new file mode 100644 index 0000000000..8dcf938873 --- /dev/null +++ b/app/code/core/Mage/Tax/sql/tax_setup/upgrade-1.6.0.2-1.6.0.3.php @@ -0,0 +1,44 @@ +getConnection() + ->addColumn( + $installer->getTable('tax/sales_order_tax_item'), + 'tax_percent', + array( + 'TYPE' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'SCALE' => 4, + 'PRECISION' => 12, + 'NULLABLE' => false, + 'COMMENT' => 'Real Tax Percent For Item', + ) + ); diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php index e981b1cc3c..ce7da0159c 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php @@ -150,10 +150,10 @@ protected function _prepareForm() public function getContinueUrl() { return $this->getUrl('*/*/*', array( - '_current' => true, - 'type' => '{{type}}', - 'package' => '{{mpackage}}', - 'theme' => '{{mtheme}}' + '_current' => true, + 'type' => '{{type}}', + 'package' => '{{package}}', + 'theme' => '{{theme}}' )); } diff --git a/app/code/core/Mage/Widget/Model/Widget/Instance.php b/app/code/core/Mage/Widget/Model/Widget/Instance.php index 7140edb55b..c85b0c7799 100644 --- a/app/code/core/Mage/Widget/Model/Widget/Instance.php +++ b/app/code/core/Mage/Widget/Model/Widget/Instance.php @@ -236,7 +236,6 @@ protected function _prepareType() public function setPackageTheme($packageTheme) { $this->setData('package_theme', $packageTheme); - $this->_preparePackageTheme(); return $this; } @@ -248,20 +247,18 @@ public function setPackageTheme($packageTheme) */ public function getPackageTheme() { - $this->_preparePackageTheme(); return $this->_getData('package_theme'); } /** * Replace '_' to '/', if was set from request(GET request) * + * @deprecated after 1.6.1.0-alpha1 + * * @return Mage_Widget_Model_Widget_Instance */ protected function _preparePackageTheme() { - if (strpos($this->_getData('package_theme'), '_') >= 0) { - $this->setData('package_theme', str_replace('_', '/', $this->_getData('package_theme'))); - } return $this; } diff --git a/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php b/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php index 7392750f79..f77bd1873e 100644 --- a/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php +++ b/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php @@ -68,19 +68,22 @@ protected function _initWidgetInstance() { $this->_title($this->__('CMS'))->_title($this->__('Widgets')); + /** @var $widgetInstance Mage_Widget_Model_Widget_Instance */ $widgetInstance = Mage::getModel('widget/widget_instance'); + $instanceId = $this->getRequest()->getParam('instance_id', null); - $type = $this->getRequest()->getParam('type', null); - $packageTheme = $this->getRequest()->getParam('package', null) . '/' - . $this->getRequest()->getParam('theme', null); - $packageTheme = $packageTheme === '/' ? null : $packageTheme; + $type = $this->getRequest()->getParam('type', null); + $package = $this->getRequest()->getParam('package', null); + $theme = $this->getRequest()->getParam('theme', null); + if ($instanceId) { $widgetInstance->load($instanceId); if (!$widgetInstance->getId()) { - $this->_getSession()->addError(Mage::helper('widget')->__('Wrong wigdet instance specified.')); + $this->_getSession()->addError(Mage::helper('widget')->__('Wrong widget instance specified.')); return false; } } else { + $packageTheme = $package . '/' . $theme == '/' ? null : $package . '/' . $theme; $widgetInstance->setType($type) ->setPackageTheme($packageTheme); } diff --git a/app/code/core/Mage/Wishlist/Model/Wishlist.php b/app/code/core/Mage/Wishlist/Model/Wishlist.php index fa16549d7e..07cc2f361c 100644 --- a/app/code/core/Mage/Wishlist/Model/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Model/Wishlist.php @@ -199,9 +199,11 @@ protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty public function getItemCollection() { if (is_null($this->_itemCollection)) { + /** @var $currentWebsiteOnly boolean */ + $currentWebsiteOnly = !Mage::app()->getStore()->isAdmin(); $this->_itemCollection = Mage::getResourceModel('wishlist/item_collection') ->addWishlistFilter($this) - ->addStoreFilter($this->getSharedStoreIds()) + ->addStoreFilter($this->getSharedStoreIds($currentWebsiteOnly)) ->setVisibilityFilter(); } @@ -389,7 +391,8 @@ public function getSharedStoreIds($current = true) $this->_storeIds = $this->getStore()->getWebsite()->getStoreIds(); } else { $_storeIds = array(); - foreach (Mage::app()->getStores() as $store) { + $stores = Mage::app()->getStores(); + foreach ($stores as $store) { $_storeIds[] = $store->getId(); } $this->_storeIds = $_storeIds; @@ -512,7 +515,16 @@ public function updateItem($itemId, $buyRequest, $params = null) $buyRequest = Mage::helper('catalog/product')->addParamsToBuyRequest($buyRequest, $params); $product->setWishlistStoreId($item->getStoreId()); - $resultItem = $this->addNewItem($product, $buyRequest, true); + $items = $this->getItemCollection(); + $isForceSetQuantity = true; + foreach ($items as $_item) { + /* @var $_item Mage_Wishlist_Model_Item */ + if (($_item->getProductId() == $product->getId()) && $_item->representProduct($product)) { + // We do not add new wishlist item, but updating the existing one + $isForceSetQuantity = false; + } + } + $resultItem = $this->addNewItem($product, $buyRequest, $isForceSetQuantity); /** * Error message */ @@ -526,18 +538,9 @@ public function updateItem($itemId, $buyRequest, $params = null) } $item->isDeleted(true); $this->setDataChanges(true); - - $items = $this->getItemCollection(); - foreach ($items as $_item) { - if ($_item->getProductId() == $productId && $_item->getId() != $resultItem->getId()) { - if ($resultItem->compareOptions($resultItem->getOptions(), $_item->getOptions())) { - $resultItem->setQty($resultItem->getQty() + $_item->getQty()); - $_item->isDeleted(true); - } - } - } } else { - $resultItem->setQty($buyRequest->getQty()*1); + $resultItem->setQty($buyRequest->getQty() * 1); + $resultItem->setOrigData('qty', 0); } } else { Mage::throwException(Mage::helper('checkout')->__('The product does not exist.')); diff --git a/app/code/core/Mage/Wishlist/controllers/IndexController.php b/app/code/core/Mage/Wishlist/controllers/IndexController.php index a81bb01249..db76caa080 100644 --- a/app/code/core/Mage/Wishlist/controllers/IndexController.php +++ b/app/code/core/Mage/Wishlist/controllers/IndexController.php @@ -200,7 +200,6 @@ public function addAction() $session->addError($this->__('An error occurred while adding item to wishlist: %s', $e->getMessage())); } catch (Exception $e) { - mage::log($e->getMessage()); $session->addError($this->__('An error occurred while adding item to wishlist.')); } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php index 08a88462f3..eb4169af97 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php @@ -27,9 +27,9 @@ /** * XmlConnect application submission history grid * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Adminhtml_History extends Mage_Adminhtml_Block_Widget_Grid_Container { 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 4a159a7dc5..79fb163932 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php @@ -27,9 +27,9 @@ /** * XmlConnect application history grid * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Adminhtml_History_Grid extends Mage_Adminhtml_Block_Widget_Grid { diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php index 04ceb529da..310acf8d36 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php @@ -27,9 +27,9 @@ /** * XmlConnect application grid * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Adminhtml_Mobile extends Mage_Adminhtml_Block_Widget_Grid_Container { @@ -40,7 +40,12 @@ public function __construct() { $this->_controller = 'adminhtml_mobile'; $this->_blockGroup = 'xmlconnect'; - $this->_headerText = $this->__('Manage Apps'); + $xmlconnectVersion = Mage::getConfig()->getNode( + Mage_XmlConnect_Model_Application::XML_PATH_MODULE_VERSION + ); + $this->_headerText = $this->__('Manage Apps') + . ' ' + . $this->__('ver. %s', $xmlconnectVersion); $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 02bd7a268b..2144e9bab0 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,16 @@ * @copyright Copyright (c) 2011 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 + +/** + * Application edit block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit + extends Mage_Adminhtml_Block_Widget_Form_Container { /** * Setting app action buttons for application @@ -119,7 +128,7 @@ public function getHeaderText() } if (isset($app) && $app->getId()) { - return $this->__('Edit App "%s"', $this->htmlEscape($app->getName())); + return $this->__('Edit App "%s"', $this->escapeHtml($app->getName())); } else { 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 a9a93f2983..0117686836 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 @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Application Form block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Form extends Mage_Adminhtml_Block_Widget_Form { /** @@ -33,9 +41,10 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Form extends Mage_Adminhtml_Bl */ protected function _prepareForm() { - $form = new Varien_Data_Form(array('id' => 'edit_form', + $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'), + ? $this->getUrl('*/mobile/edit', array('_current' => true)) + : $this->getUrl('*/mobile/save'), 'method' => 'post', 'enctype' => 'multipart/form-data' )); 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 3ac44d0e0f..6c1af9ac6e 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 @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Submission extends Mage_Adminhtml_Block_Widget_Tabs + +/** + * Application Submission block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Submission + extends Mage_Adminhtml_Block_Widget_Tabs { /** * Constructor diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php index a351fd658b..fd5ed70bce 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php @@ -31,7 +31,8 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Cache extends Mage_Adminhtml_Block_Widget_Form +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Cache + extends Mage_Adminhtml_Block_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface { /** 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 031b42b80f..57e97bb4e6 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 @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Tab for Content Management + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Content extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface @@ -47,10 +55,10 @@ public function __construct() */ protected function _addPage($fieldset, $fieldPrefix) { - $el = $fieldset->addField($fieldPrefix, 'page', array( + $element = $fieldset->addField($fieldPrefix, 'page', array( 'name' => $fieldPrefix, )); - $el->initFields(array( + $element->initFields(array( 'name' => $fieldPrefix, 'values' => $this->_pages, )); 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 39e6cbbab7..5ef12f4e69 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 @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Tab_Design extends Mage_Adminhtml_Block_Template + +/** + * Tab for Design Management + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design + extends Mage_Adminhtml_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface { /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php index 80f3db6d00..5045b69c57 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Tab_Design_Accordion extends Mage_Adminhtml_Block_Widget_Accordion + +/** + * Tab design accordion xml renderer + * + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion + extends Mage_Adminhtml_Block_Widget_Accordion { /** * Add accordion item by specified block 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 7ac9589ea0..38f366cc6e 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 @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Tab design Accordion Images xml renderer + * + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Images extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_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 ca8cc9e8ca..d62626d6fb 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 @@ -25,7 +25,7 @@ */ /** - * Device tabs accourdion block + * Device tabs accordion block * * @category Mage * @package Mage_XmlConnect 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 876a80553a..527edf358a 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 @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Tab_Design_Preview extends Mage_Adminhtml_Block_Template + +/** + * Tab design preview xml renderer + * + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Preview + extends Mage_Adminhtml_Block_Template { /** * Set preview template @@ -36,7 +45,9 @@ public function __construct() 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.')); + Mage::throwException( + $this->__('Device doesn\'t recognized. Unable to load a template.') + ); } $this->setTemplate($template); @@ -58,7 +69,6 @@ public function getPreviewActionUrl($page = 'home') } else { $params = array('devtype' => $model->getType()); } - } 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 a10067cab2..4307b30df1 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 @@ -34,8 +34,7 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Themes extends Mage_Adminhtml_Block_Template { /** - * Set themes template - * Set color fieldsets + * Set themes template and color fieldsets */ public function __construct() { 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 index 2216fb75c9..2a4124638e 100755 --- 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 @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Tab for Flurry Analytics Management + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Flurryanalytics extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface @@ -30,7 +38,7 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Flurryanalytics protected $_pages; /** - * Construnctor + * Constructor * Setting view options */ public function __construct() @@ -74,7 +82,7 @@ protected function _prepareForm() Mage::getStoreConfig('xmlconnect/flurry_analytics/statistics_url') ); - $flurryLink = $fieldset->addField('flurry_analytics_link', 'link', array( + $fieldset->addField('flurry_analytics_link', 'link', array( 'title' => $this->__('Flurry Analytics Site'), 'label' => $this->__('Flurry Analytics Site'), 'value' => $flurryAnalyticsUrl, 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 8de396d899..0b325ccf95 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 @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Tab_General extends Mage_Adminhtml_Block_Widget_Form + +/** + * Tab for General Info Management + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_General + extends Mage_Adminhtml_Block_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface { /** @@ -57,7 +66,7 @@ protected function _prepareForm() )); if ($model->getId()) { - $field = $fieldset->addField('code', 'label', array( + $fieldset->addField('code', 'label', array( 'label' => $this->__('App Code'), 'title' => $this->__('App Code'), 'value' => $model->getCode(), 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 index 6c14ba4109..e339b4065b 100755 --- 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 @@ -23,12 +23,20 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Tab for Notifications Management + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Notification extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface { /** - * Construnctor + * Constructor * Setting view options */ public function __construct() @@ -179,7 +187,7 @@ public function getTabTitle() public function canShowTab() { return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication() - && Mage::helper('xmlconnect')->getDeviceType() == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE; + && Mage::helper('xmlconnect')->isNotificationsAllowed(); } /** 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 e61c124b6e..742d212785 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 @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Tab for Payments Management + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Payment extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface @@ -30,7 +38,7 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Payment protected $_pages; /** - * Construnctor + * Constructor * Setting view options */ public function __construct() @@ -77,32 +85,33 @@ protected function _prepareForm() /** * PayPal MEP management */ - $isExpressCheckoutAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep') + $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array( + 'legend' => $this->__('PayPal Mobile Embedded Payment (MEP)') + )); + + $paypalMepIsAvailable = 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]'] && $isExpressCheckoutAvailable); + $paypalActive = (int)($data['conf[native][paypal][isActive]'] && $paypalMepIsAvailable); } - $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array( - 'legend' => $this->__('PayPal Mobile Embedded Payment (MEP)') - )); - - $activateMepMethodNote = $this->__('To activate PayPal MEP payment method activate Express checkout first. '); $paypalConfigurationUrl = $this->escapeHtml( $this->getUrl('adminhtml/system_config/edit', array('section' => 'paypal')) ); + $activateMepMethodNote = $this->__('To activate PayPal MEP payment method activate Express checkout first. '); + $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' => $this->__('Activate PayPal Checkout'), 'name' => 'conf[native][paypal][isActive]', - 'note' => (!$isExpressCheckoutAvailable ? $activateMepMethodNote : $businessAccountNote), + 'note' => (!$paypalMepIsAvailable ? $activateMepMethodNote : $businessAccountNote), 'values' => $yesNoValues, 'value' => $paypalActive, - 'disabled' => !$isExpressCheckoutAvailable + 'disabled' => !$paypalMepIsAvailable )); if (isset($data['conf[special][merchantLabel]'])) { @@ -184,6 +193,41 @@ protected function _prepareForm() ); break; case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID: + /** + * PayPal MECL management + */ + if (Mage::app()->isSingleStoreMode() || Mage::helper('xmlconnect')->getApplication()->getId()) { + $paypalMeclIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mecl') + ->isAvailable(); + $activateMeclMethodNote = $this->__('You need to enable PayPal Express Checkout first from the Payment configuration before enabling PayPal MECL.'); + } else { + $paypalMeclIsAvailable = false; + $activateMeclMethodNote = $this->__('Please create and save an application first.'); + } + + $fieldsetMecl = $form->addFieldset('paypal_mecl_checkout', array( + 'legend' => $this->__('PayPal Mobile Express Checkout Library (MECL)') + )); + + $meclAccountNote = $this->__('PayPal MECL is the mobile version of PayPal\'s Express Checkout service. You can choose to use MECL alongside standard checkout, or use it as your only checkout method for Magento Mobile.'); + + $paypalMeclActive = 0; + if (isset($data['config_data[payment][paypalmecl_is_active]'])) { + $paypalMeclActive = (int) $data['config_data[payment][paypalmecl_is_active]']; + } + + $fieldsetMecl->addField('config_data/paypalmecl_is_active', 'select', array( + 'label' => $this->__('Activate PayPal MECL'), + 'name' => 'config_data[payment:paypalmecl_is_active]', + 'note' => (!$paypalMeclIsAvailable ? $activateMeclMethodNote : $meclAccountNote), + 'values' => $yesNoValues, + 'value' => $paypalMeclActive, + 'disabled' => !$paypalMeclIsAvailable + )); + + /** + * PayPal MEP management + */ $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array( 'legend' => $this->__('PayPal Mobile Embedded Payment (MEP)') )); 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 index 7b450ae565..faac69b2e4 100755 --- 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 @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form + +/** + * Tab for Settings Management + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Settings + extends Mage_Adminhtml_Block_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface { protected function _prepareLayout() @@ -34,8 +43,9 @@ protected function _prepareLayout() 'label' => Mage::helper('catalog')->__('Continue'), 'onclick' => "if (editForm.submit()) { return false }", 'class' => 'save' - )) - ); + ) + ) + ); return parent::_prepareLayout(); } 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 9119471835..c73fc34e76 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 @@ -27,11 +27,12 @@ /** * XmlConnect application history grid * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Submission_History extends Mage_Adminhtml_Block_Widget_Grid +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Submission_History + extends Mage_Adminhtml_Block_Widget_Grid implements Mage_Adminhtml_Block_Widget_Tab_Interface { /** @@ -92,8 +93,8 @@ public function isHidden() } /** - * Initialize history colelction - * Set aaplication filter + * Initialize history collection + * Set application filter * * @return Mage_Adminhtml_Block_Widget_Grid */ 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 3d9042b07f..7cfc88b7ba 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 @@ -23,13 +23,20 @@ * @copyright Copyright (c) 2011 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_Tabs extends Mage_Adminhtml_Block_Widget_Tabs + +/** + * Application Tabs block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tabs + extends Mage_Adminhtml_Block_Widget_Tabs { /** * Constructor - * * Setting grid_id, DOM destination element id, Title - * */ public function __construct() { @@ -49,7 +56,9 @@ protected function _prepareLayout() if (Mage::getSingleton('adminhtml/session')->getNewApplication()) { $this->addTab('set', array( 'label' => $this->__('Settings'), - 'content' => $this->getLayout()->createBlock('xmlconnect/adminhtml_mobile_edit_tab_settings')->toHtml(), + 'content' => $this->getLayout() + ->createBlock('xmlconnect/adminhtml_mobile_edit_tab_settings') + ->toHtml(), 'active' => true )); } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php index 02dae6f2a5..67cabb2c70 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php @@ -24,7 +24,15 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Addrow extends Varien_Data_Form_Element_Button +/** + * Xmlconnect Add row form element + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Addrow + extends Varien_Data_Form_Element_Button { /** * Render Element Html @@ -33,10 +41,17 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Addrow extends Varien_ */ public function getElementHtml() { - $html = $this->getBeforeElementHtml() . ''.$this->getAfterElementHtml(); + . ' >' + . $this->getEscapedValue() + . '' + . $this->getAfterElementHtml(); return $html; } @@ -52,25 +67,27 @@ public function getBeforeElementHtml() /** * Return label html code - * + * * @param string $idSuffix * @return string */ public function getLabelHtml($idSuffix = '') { - if (!is_null($this->getLabel())) { - $html = ''; + if ($this->getLabel() !== null) { + $html = ''; } else { $html = ''; } return $html; } - + /** * Overriding toHtml parent method * Adding addrow Block to element renderer - * + * * @return string */ public function toHtml() diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php index 060d0153b6..b4e7472c54 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php @@ -24,11 +24,19 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Color extends Varien_Data_Form_Element_Text +/** + * Xmlconnect color form element + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Color + extends Varien_Data_Form_Element_Text { /** * Return html code for current block - * + * * @return mixed|string */ public function getHtml() diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php index b0c8842e42..75143b51d8 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php @@ -27,11 +27,12 @@ /** * XmlConnect Country selector form element * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Country extends Varien_Data_Form_Element_Checkboxes +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Country + extends Varien_Data_Form_Element_Checkboxes { /** * Flag of using the border in the table's TD @@ -90,7 +91,7 @@ public function getElementHtml() $id = $this->getData('id'); $id = empty($id) ? '' : ' id="' . $id . '-table"'; $class = $this->getData('class'); - $html = "\n\n"; + $html = PHP_EOL . "
" . PHP_EOL; $zebrine = ''; $stripy = false; @@ -100,7 +101,7 @@ public function getElementHtml() $columns--; foreach ($options as $row) { - $html .= " \n "; + $html .= "" . PHP_EOL; if ($stripy) { $zebrine = empty($zebrine) ? ' class="odd"' : ''; @@ -123,11 +124,10 @@ public function getElementHtml() } } - $html .= "\n \n"; + $html .= PHP_EOL . '' . PHP_EOL; } - $html .= "
\n" - . $this->getAfterElementHtml(); + $html .= '' . PHP_EOL . $this->getAfterElementHtml(); return $html; } @@ -149,7 +149,8 @@ protected function _optionToHtml($option) $border = $this->_useBorderClass ? ' class="border"' : ''; $html = 'getHtmlAttributes() as $attribute) { - if ($value = $this->getDataUsingMethod($attribute, $option['value'])) { + $value = $this->getDataUsingMethod($attribute, $option['value']); + if ($value) { $html .= ' ' . $attribute . '="' . $value . '"'; } } 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 index d6d92577a8..cf421029ed 100755 --- 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 @@ -27,13 +27,16 @@ /** * XmlConnect data selector form element * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Datetime extends Varien_Data_Form_Element_Abstract +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Datetime + extends Varien_Data_Form_Element_Abstract { /** + * Date + * * @var Zend_Date */ protected $_value; @@ -63,7 +66,7 @@ protected function _toTimestamp($value) } return $value; } - + /** * Set date value * If Zend_Date instance is provided instead of value, other params will be ignored. @@ -156,19 +159,25 @@ public function getElementHtml() $html = sprintf( '' .' ', - $this->getName(), $this->getHtmlId(), $this->_escape($this->getValue()), $this->serialize($this->getHtmlAttributes()), - $this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '') + $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().'); + Mage::throwException( + $this->__('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() + $this->getHtmlId(), + $displayFormat . " " . $displayTimeFormat, + $this->getTime() ? 'true' : 'false', + $this->getHtmlId() ); $html .= $this->getAfterElementHtml(); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php index c3b7eb4856..ab86d400b1 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php @@ -24,10 +24,18 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Font extends Varien_Data_Form_Element_Abstract +/** + * XmlConnect font form element + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Font + extends Varien_Data_Form_Element_Abstract { /** - * Constructor... + * Init font element * * @param array $attributes */ @@ -68,13 +76,13 @@ public function initFields($conf) * Add form element * * @param Varien_Data_Form_Element_Abstract $element - * @param boolean|'^'|string $after + * @param bool|string $after also can be '^' * @return Varien_Data_Form */ - public function addElement(Varien_Data_Form_Element_Abstract $element, $after=false) + public function addElement(Varien_Data_Form_Element_Abstract $element, $after = false) { $element->setId($element->getData('name')); - $element->setNoSpan(TRUE); + $element->setNoSpan(true); parent::addElement($element, $after); } @@ -85,10 +93,13 @@ public function addElement(Varien_Data_Form_Element_Abstract $element, $after=fa */ public function getElementHtml() { - $el = array(); + $elementsArray = array(); foreach ($this->getElements() as $element) { - $el[] .= $element->toHtml(); + $elementsArray[] .= $element->toHtml(); } - return $el[0] . $el[1] . '' . $el[2]; + return $elementsArray[0] + . $elementsArray[1] + . '' + . $elementsArray[2]; } } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php index c00f893525..b355132b42 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php @@ -24,7 +24,15 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Image extends Varien_Data_Form_Element_Image +/** + * XmlConnect image form element + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Image + extends Varien_Data_Form_Element_Image { /** * Function fetches image Url actual or default @@ -33,9 +41,8 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Image extends Varien_D */ protected function _getUrl() { - $url = false; if ($this->getValue()) { - if (strpos($this->getValue(), '://') === FALSE ) { + if (strpos($this->getValue(), '://') === false) { $url = Mage::helper('xmlconnect/image')->getFileDefaultSizeSuffixAsUrl($this->getValue()); $url = Mage::helper('xmlconnect/image')->getMediaUrl($url); } else { @@ -82,7 +89,7 @@ public function getElementHtml() $this->setClass('input-file'); $html .= '' . "\n"; + $html .= '" value="' . $this->getEscapedValue() . '" ' . $attr . '/>' . PHP_EOL; $html .= $this->getAfterElementHtml(); $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 5ad9f49ce6..cca94ca4f5 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 @@ -24,10 +24,18 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Page extends Varien_Data_Form_Element_Abstract +/** + * XmlConnect page form element + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Page + extends Varien_Data_Form_Element_Abstract { /** - * Enter description here... + * Init page element * * @param array $attributes */ @@ -45,8 +53,8 @@ public function __construct($attributes=array()) public function initFields($conf) { $this->addElement(new Varien_Data_Form_Element_Text(array( - 'name' => $conf['name'] . '[label]', - 'class' => 'label onclick_text', + 'name' => $conf['name'] . '[label]', + 'class' => 'label onclick_text', ))); $this->addElement(new Varien_Data_Form_Element_Select(array( @@ -59,10 +67,10 @@ public function initFields($conf) * Add form element * * @param Varien_Data_Form_Element_Abstract $element - * @param boolean|'^'|string $after + * @param boolean|string $after also can be '^' * @return Varien_Data_Form */ - public function addElement(Varien_Data_Form_Element_Abstract $element, $after=false) + public function addElement(Varien_Data_Form_Element_Abstract $element, $after = false) { $element->setId($element->getData('name')); parent::addElement($element, $after); @@ -82,7 +90,7 @@ public function getLabelHtml($idSuffix = '') } /** - * Gettter for second part of rendered field ("selectbox" and "delete button") + * Getter for second part of rendered field ("selectbox" and "delete button") * fetching second element as * * @return string @@ -90,8 +98,10 @@ public function getLabelHtml($idSuffix = '') public function getElementHtml() { list($label, $element) = $this->getElements(); - return $element->toHtml() . '' + return $element->toHtml() + . '' . ''; + . Mage::helper('xmlconnect')->__('Delete') + . ''; } } 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 fd676eeefe..e9b55f0087 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 @@ -24,7 +24,15 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Tabs extends Varien_Data_Form_Element_Text +/** + * XmlConnect tabs form element + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Tabs + extends Varien_Data_Form_Element_Text { /** * Generate application tabs html @@ -43,7 +51,9 @@ public function getHtml() 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.')); + Mage::throwException( + $this->__('Device doesn\'t recognized. Unable to load a template.') + ); } $block->setTemplate($template); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php index 1a1ff95af0..387a0594c4 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php @@ -24,7 +24,15 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Theme extends Varien_Data_Form_Element_Text +/** + * XmlConnect theme form element + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Theme + extends Varien_Data_Form_Element_Text { /** * Generate themes (colors) html @@ -33,7 +41,8 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Theme extends Varien_D */ public function getHtml() { - $blockClassName = Mage::getConfig()->getBlockClassName('xmlconnect/adminhtml_mobile_edit_tab_design_themes'); + $blockClassName = Mage::getConfig() + ->getBlockClassName('xmlconnect/adminhtml_mobile_edit_tab_design_themes'); $block = new $blockClassName; $block->setThemes($this->getThemes()); $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 4adad9e7da..f8104e89b3 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Application grid block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_Xmlconnect_Block_Adminhtml_Mobile_Grid extends Mage_Adminhtml_Block_Widget_Grid { /** diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php index 7af683e6cb..b7ad0302cf 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php @@ -27,11 +27,12 @@ /** * XmlConnect status field grid renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Bool extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Bool + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Render application status image @@ -45,11 +46,15 @@ public function render(Varien_Object $row) $status = (int) $row->getData($this->getColumn()->getIndex()); $options = Mage::helper('xmlconnect')->getStatusOptions(); if ($status == Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS) { - $result = ' ' . (isset($options[$status]) ? $options[$status] : ''); + $result = ' ' + . (isset($options[$status]) ? $options[$status] : ''); } else if ($status == Mage_XmlConnect_Model_Application::APP_STATUS_INACTIVE) { - $result = ' ' . (isset($options[$status]) ? $options[$status] : ''); + $result = ' ' + . (isset($options[$status]) ? $options[$status] : ''); } return $result; } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php index f1255ce7c6..1e4ef26887 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php @@ -27,11 +27,12 @@ /** * Adminhtml catalog super product link grid checkbox renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Type extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Type + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Renders grid column 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 a79a5ba9fb..b404f60ce4 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 @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * XmlConnect preview content block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Content extends Mage_Adminhtml_Block_Template { /** 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 6b1100544b..686d041f95 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 @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * XmlConnect Tab items block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Tabitems extends Mage_Adminhtml_Block_Template { /** @@ -33,7 +41,6 @@ public function __construct() parent::__construct(); $deviceType = Mage::helper('xmlconnect')->getDeviceType(); - $this->setTemplate('xmlconnect/edit/tab/design/preview/tab_items_' . $deviceType . '.phtml'); } 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 851b51a359..4a40c9f1da 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php @@ -23,11 +23,18 @@ * @copyright Copyright (c) 2011 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 + +/** + * Application submission block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission + extends Mage_Adminhtml_Block_Widget_Form_Container { /** - * Class construct - * * Setting buttons for submit application page */ public function __construct() @@ -56,8 +63,11 @@ public function __construct() )); $this->_updateButton('back', 'label', $this->__('Back to App Edit')); - $this->_updateButton('back', 'onclick', 'setLocation(\''. $this->getUrl('*/*/edit', - array('application_id' => $app->getId())) . '\')'); + $this->_updateButton( + 'back', + 'onclick', + 'setLocation(\'' . $this->getUrl('*/*/edit', array('application_id' => $app->getId())) . '\')' + ); } /** @@ -104,7 +114,7 @@ public function getHeaderText() { $app = Mage::helper('xmlconnect')->getApplication(); if ($app && $app->getId()) { - return $this->__('Submit App "%s"', $this->htmlEscape($app->getName())); + return $this->__('Submit App "%s"', $this->escapeHtml($app->getName())); } return ''; } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php index 4bba1b6c06..c68925f62d 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Form extends Mage_Adminhtml_Block_Widget_Form + +/** + * Device submission form block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Form + extends Mage_Adminhtml_Block_Widget_Form { /** * Prepare form before rendering HTML diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php index 6d0aa59233..88727eb231 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php @@ -38,7 +38,7 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Android /** * Override setting the template * - * @return void + * @return null */ protected function _construct() { diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php index 55b4aa35c6..36aec5fa42 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php @@ -38,7 +38,7 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Istore /** * Override setting the template * - * @return void + * @return null */ protected function _construct() { 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 f34cb64436..0ef2f1e2c3 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 @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Tab_Container extends Mage_Adminhtml_Block_Template + +/** + * Device container block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tab_Container + extends Mage_Adminhtml_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface { /** @@ -58,7 +67,7 @@ public function getTabTitle() } /** - * Returns status flag about this tab can be showen or not + * Returns status flag about this tab can be shown or not * * @return true */ 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 814eaabb59..179bd6b834 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 @@ -76,6 +76,7 @@ public function addImage($fieldset, $fieldName, $title, $note = '', $default = ' 'name' => $fieldName, 'label' => $title, 'note' => !empty($note) ? $note : null, + 'default_value' => $default, 'required' => $required, )); } @@ -344,7 +345,7 @@ public function getTabTitle() } /** - * Returns status flag about this tab can be showen or not + * Returns status flag about this tab can be shown or not * * @return true */ 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 13d1d819bd..864ede2790 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 @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Tabs extends Mage_Adminhtml_Block_Widget_Tabs + +/** + * Device submission tabs block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tabs + extends Mage_Adminhtml_Block_Widget_Tabs { /** * Constructor 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 44ee685f87..79b93c2167 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 @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Xmlconnect widget form block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form extends Mage_Adminhtml_Block_Widget_Form { /** @@ -56,7 +64,7 @@ public function addImage($fieldset, $fieldName, $title, $note = null, $default = 'name' => $fieldName, 'label' => $title, 'note' => $note, - 'default_value' => $default, + 'default_value' => $default, 'required' => $required, )); } @@ -70,12 +78,12 @@ public function addImage($fieldset, $fieldName, $title, $note = null, $default = */ public function addFont($fieldset, $fieldPrefix, $title) { - $el = $fieldset->addField($fieldPrefix, 'font', array( + $element = $fieldset->addField($fieldPrefix, 'font', array( 'name' => $fieldPrefix, 'label' => $title, )); - $el->initFields(array( + $element->initFields(array( 'name' => $fieldPrefix, 'fontNames' => Mage::helper('xmlconnect')->getDeviceHelper()->getFontList(), 'fontSizes' => Mage::helper('xmlconnect')->getDeviceHelper()->getFontSizes(), diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php index e9c501591e..7c6dcc0b11 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php @@ -31,8 +31,8 @@ * @package Mage_XmlConnect * @author Magento Core Team */ - class Mage_XmlConnect_Block_Adminhtml_Queue extends Mage_Adminhtml_Block_Widget_Grid_Container - { +class Mage_XmlConnect_Block_Adminhtml_Queue extends Mage_Adminhtml_Block_Widget_Grid_Container +{ /** * Class constructor */ @@ -45,4 +45,4 @@ public function __construct() 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 index c03bf096ac..ef150e638a 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php @@ -24,7 +24,15 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Queue_Edit extends Mage_Adminhtml_Block_Widget_Form_Container +/** + * Xmlconnect queue edit block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Queue_Edit + extends Mage_Adminhtml_Block_Widget_Form_Container { /** * Constructor @@ -72,7 +80,7 @@ public function getHeaderText() { $message = Mage::registry('current_message'); if ($message && $message->getId()) { - return $this->__('Edit AirMail Message Queue #%s', $this->htmlEscape($message->getId())); + return $this->__('Edit AirMail Message Queue #%s', $this->escapeHtml($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 index 2657bd4fc3..875d4831b8 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php @@ -23,7 +23,16 @@ * @copyright Copyright (c) 2011 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_Queue_Edit_Form extends Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form + +/** + * Xmlconnect queue edit form block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Queue_Edit_Form + extends Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form { /** * Prepare form before rendering HTML @@ -34,7 +43,12 @@ class Mage_XmlConnect_Block_Adminhtml_Queue_Edit_Form extends Mage_XmlConnect_Bl protected function _prepareForm() { $model = Mage::registry('current_message'); - $this->_fieldsEnabled = $model->getStatus() == Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE ? true : false; + + if ($model->getStatus() == Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) { + $this->_fieldsEnabled = true; + } else { + $this->_fieldsEnabled = false; + } parent::_prepareForm(); @@ -44,7 +58,11 @@ protected function _prepareForm() $templateModel = Mage::getModel('xmlconnect/template')->load($model->getTemplateId()); } - $fieldset = $this->getForm()->addFieldset("message_settings", array('legend' => $this->__('Message Settings')), '^'); + $fieldset = $this->getForm()->addFieldset( + "message_settings", + array('legend' => $this->__('Message Settings')), + '^' + ); if ($model->getId()) { $fieldset->addField('message_id', 'hidden', array( @@ -55,7 +73,7 @@ protected function _prepareForm() // 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 */ + /** @var $sovereignField Varien_Data_Form_Element_Abstract */ $sovereignField = $fieldset->addField('type', 'select', array( 'name' => 'type', 'values' => Mage::helper('xmlconnect')->getMessageTypeOptions(), @@ -80,30 +98,40 @@ protected function _prepareForm() $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->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 (!empty($this->_dependentFields['message_title'])) { $dependenceBlock->addFieldDependence( $this->_dependentFields['message_title']->getName(), $sovereignField->getName(), - Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL); + 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']) { + if (!empty($this->_dependentFields['content'])) { $dependenceBlock->addFieldDependence( $this->_dependentFields['content']->getName(), $sovereignField->getName(), - Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL); + Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL + ); if (!$this->_fieldsEnabled) { $this->_dependentFields['content']->setReadonly(true, true); @@ -128,6 +156,7 @@ protected function _prepareForm() $model->setTemplateId($templateModel->getId()); } $model->setMessageId($model->getId()); + $model->setData('app_code', $templateModel->getData('app_code')); $this->getForm()->setAction($this->getUrl('*/*/saveMessage')); $this->getForm()->setValues($model->getData()); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php index c6e12eec8c..aa690dd73b 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php @@ -34,8 +34,6 @@ 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() 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 index 1cfa571d86..4c550dc62c 100755 --- 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 @@ -27,11 +27,12 @@ /** * Adminhtml airmail queue grid block action item renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Action + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action { /** * Render grid 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 index 7563ddf483..b094db007e 100755 --- 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 @@ -27,11 +27,12 @@ /** * Adminhtml airmail queue grid block action item renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Application extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Application + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Render grid row @@ -41,7 +42,7 @@ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Application extends Ma */ public function render(Varien_Object $row) { - $str = htmlspecialchars($row->getAppName()); + $str = $this->escapeHtml($row->getAppName()); if ($str == '') { $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 index 71c58e040a..d0e8ca4396 100755 --- 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 @@ -27,11 +27,12 @@ /** * Adminhtml airmail queue grid block action item renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Id extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Id + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Render grid row 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 index c086643110..29639ebcad 100755 --- 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 @@ -27,11 +27,12 @@ /** * Adminhtml airmail queue grid block action item renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Msgtitle extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Msgtitle + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Render grid row @@ -45,6 +46,6 @@ public function render(Varien_Object $row) if (strlen($msgTitle) > 50) { $msgTitle = substr($msgTitle, 0, 50) . '...'; } - return htmlspecialchars($msgTitle); + return $this->escapeHtml($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 index 045c83806c..7e28ee3e6a 100755 --- 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 @@ -27,12 +27,12 @@ /** * Adminhtml airmail queue grid block action item renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - -class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Pushtitle extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Pushtitle + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Render grid row @@ -42,6 +42,6 @@ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Pushtitle extends Mage */ public function render(Varien_Object $row) { - return htmlspecialchars($row->getPushTitle()); - } + return $this->escapeHtml($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 index dd4f22359a..c097e2881c 100755 --- 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 @@ -27,12 +27,12 @@ /** * Adminhtml airmail queue grid block action item renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - -class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Status extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Status + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Render grid row @@ -64,6 +64,6 @@ public function render(Varien_Object $row) $str = $this->__('Undefined'); } - return htmlspecialchars($str); + return $this->escapeHtml($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 index 27cb02e885..622603e809 100755 --- 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 @@ -27,12 +27,12 @@ /** * Adminhtml airmail queue grid block action item renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - -class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Template extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Template + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Render grid row @@ -42,10 +42,10 @@ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Template extends Mage_ */ public function render(Varien_Object $row) { - $str = htmlspecialchars($row->getTplName()); + $str = $this->escapeHtml($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 index 21ce0bf34c..7244adfd0f 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php @@ -31,8 +31,8 @@ * @package Mage_XmlConnect * @author Magento Core Team */ - class Mage_XmlConnect_Block_Adminhtml_Template extends Mage_Adminhtml_Block_Widget_Grid_Container - { +class Mage_XmlConnect_Block_Adminhtml_Template extends Mage_Adminhtml_Block_Widget_Grid_Container +{ /** * Class constructor */ @@ -45,11 +45,11 @@ public function __construct() parent::__construct(); $this->removeButton('add'); } - + /** * Prepare layout * Add new button - * + * * @return Mage_Adminhtml_Block_Widget_Grid_Container */ protected function _prepareLayout() @@ -59,7 +59,7 @@ protected function _prepareLayout() '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 index b3ee7f5d8f..ecf2dc965a 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php @@ -24,6 +24,13 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Xmlconnect template edit block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Adminhtml_Template_Edit extends Mage_Adminhtml_Block_Widget_Form_Container { /** @@ -37,8 +44,9 @@ public function __construct() 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->__('Warning: All related AirMail messages will be deleted!') . PHP_EOL + . $this->__('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') . '\')'); @@ -63,7 +71,7 @@ public function getHeaderText() { $template = Mage::registry('current_template'); if ($template && $template->getId()) { - return $this->__('Edit Template "%s"', $this->htmlEscape($template->getName())); + return $this->__('Edit Template "%s"', $this->escapeHtml($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 index 4b01f9cbe8..ffa43c1632 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php @@ -23,9 +23,29 @@ * @copyright Copyright (c) 2011 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_Template_Edit_Form extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form + +/** + * Xmlconnect template edit form block + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form + extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form { + /** + * Enabled fields flag + * + * @var bool + */ protected $_fieldsEnabled = true; + + /** + * Field dependencies + * + * @var array + */ protected $_dependentFields = array(); /** @@ -55,10 +75,10 @@ protected function _prepareForm() $action = $this->getUrl('*/*/saveTemplate'); $form = new Varien_Data_Form(array( - 'id' => 'edit_form', - 'action' => $action, - 'method' => 'post', - 'enctype' => 'multipart/form-data' + 'id' => 'edit_form', + 'action' => $action, + 'method' => 'post', + 'enctype' => 'multipart/form-data' )); $form->setHtmlIdPrefix('template_'); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php index eb8b356b66..1ab0ee9d8b 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php @@ -33,10 +33,7 @@ */ 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() @@ -130,15 +127,15 @@ protected function _prepareColumns() array( 'caption' => $this->__('Preview'), 'url' => array( - 'base' => '*/*/previewTemplate' + 'base' => '*/*/previewTemplate' ), - 'popup' => true, + 'popup' => true, 'field' => 'id' ), array( 'caption' => $this->__('Queue Message'), 'url' => array( - 'base' => '*/*/queueMessage', + 'base' => '*/*/queueMessage', ), 'field' => 'template_id' ), 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 index ea28360376..bb47be885b 100755 --- 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 @@ -47,5 +47,5 @@ public function render(Varien_Object $row) $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 index 4df9f7d6bf..bc44abd4c9 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php @@ -27,9 +27,9 @@ /** * XmlConnect Adminhtml AirMail template preview block * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Adminhtml_Template_Preview extends Mage_Adminhtml_Block_Widget { 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 index 30bfc62ed1..51b7d068e8 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php @@ -27,13 +27,13 @@ /** * Admin form widget * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form extends Mage_Adminhtml_Block_Widget_Form +class Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form + extends Mage_Adminhtml_Block_Widget_Form { - /** * Preparing from for revision page * @@ -42,17 +42,16 @@ class Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form extends Mage_Adminht 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()) { + 'id' => 'preview_form', + 'action' => $this->getUrl('*/*/drop', array('_current' => true)), + 'method' => 'post' + )); + if ($data = $this->getTemplateFormData()) { $mapper = array('preview_store_id' => 'store_id'); foreach ($data as $key => $value) { - if(array_key_exists($key, $mapper)) { + if (array_key_exists($key, $mapper)) { $name = $mapper[$key]; } else { $name = $key; diff --git a/app/code/core/Mage/XmlConnect/Block/Cart.php b/app/code/core/Mage/XmlConnect/Block/Cart.php index 06411a593d..a86f34f78b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart.php @@ -28,7 +28,7 @@ * Shopping cart xml renderer * * @category Mage - * @package Mage_Checkout + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Block_Cart extends Mage_Checkout_Block_Cart_Abstract @@ -40,179 +40,180 @@ class Mage_XmlConnect_Block_Cart extends Mage_Checkout_Block_Cart_Abstract */ protected function _toHtml() { - $cartMessages = $this->getMessages(); - $quote = $this->getQuote(); - $xmlObject = Mage::getModel('xmlconnect/simplexml_element', ''); - $xmlObject->addAttribute('is_virtual', (int)$this->helper('checkout/cart')->getIsVirtualQuote()); - $xmlObject->addAttribute('summary_qty', (int)$this->helper('checkout/cart')->getSummaryCount()); - if (strlen($quote->getCouponCode())) { - $xmlObject->addAttribute('has_coupon_code', 1); - } - $products = $xmlObject->addChild('products'); - + $cartMessages = $this->getMessages(); + $quote = $this->getQuote(); + /** @var $xmlObject Mage_XmlConnect_Model_Simplexml_Element */ + $xmlObject = Mage::getModel('xmlconnect/simplexml_element', ''); + $xmlObject->addAttribute('is_virtual', (int)$this->helper('checkout/cart')->getIsVirtualQuote()); + $xmlObject->addAttribute('summary_qty', (int)$this->helper('checkout/cart')->getSummaryCount()); + if (strlen($quote->getCouponCode())) { + $xmlObject->addAttribute('has_coupon_code', 1); + } + $products = $xmlObject->addChild('products'); /* @var $item Mage_Sales_Model_Quote_Item */ - foreach ($this->getItems() as $item) { - $type = $item->getProductType(); - $renderer = $this->getItemRenderer($type)->setItem($item); - - /** - * General information - */ - $itemXml = $products->addChild('item'); - $itemXml->addChild('entity_id', $item->getProduct()->getId()); - $itemXml->addChild('entity_type', $type); - $itemXml->addChild('item_id', $item->getId()); - $itemXml->addChild('name', $xmlObject->xmlentities(strip_tags($renderer->getProductName()))); - $itemXml->addChild('code', 'cart[' . $item->getId() . '][qty]'); - $itemXml->addChild('qty', $renderer->getQty()); - $icon = $renderer->getProductThumbnail()->resize( - Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small') - ); - - $iconXml = $itemXml->addChild('icon', $icon); - - $file = Mage::helper('xmlconnect')->urlToPath($icon); - - $iconXml->addAttribute('modification_time', filemtime($file)); - - /** - * Price - */ - $exclPrice = $inclPrice = 0.00; - if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { - if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') - && $item->getWeeeTaxAppliedAmount() - ) { - $exclPrice = $item->getCalculationPrice() - + $item->getWeeeTaxAppliedAmount() - + $item->getWeeeTaxDisposition(); - } else { - $exclPrice = $item->getCalculationPrice(); - } - } - - if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { - $_incl = $this->helper('checkout')->getPriceInclTax($item); - if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') - && $item->getWeeeTaxAppliedAmount() - ) { - $inclPrice = $_incl + $item->getWeeeTaxAppliedAmount(); - } else { + foreach ($this->getItems() as $item) { + $type = $item->getProductType(); + $renderer = $this->getItemRenderer($type)->setItem($item); + /** + * General information + */ + $itemXml = $products->addChild('item'); + $itemXml->addChild('entity_id', $item->getProduct()->getId()); + $itemXml->addChild('entity_type', $type); + $itemXml->addChild('item_id', $item->getId()); + $itemXml->addChild('name', $xmlObject->xmlentities($renderer->getProductName())); + $itemXml->addChild('code', 'cart[' . $item->getId() . '][qty]'); + $itemXml->addChild('qty', $renderer->getQty()); + $icon = $renderer->getProductThumbnail()->resize( + Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small') + ); + $iconXml = $itemXml->addChild('icon', $icon); + $file = Mage::helper('xmlconnect')->urlToPath($icon); + $iconXml->addAttribute('modification_time', filemtime($file)); + /** + * Price + */ + $exclPrice = $inclPrice = 0; + if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { + if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') + && $item->getWeeeTaxAppliedAmount() + ) { + $exclPrice = $item->getCalculationPrice() + $item->getWeeeTaxAppliedAmount() + + $item->getWeeeTaxDisposition(); + } else { + $exclPrice = $item->getCalculationPrice(); + } + } + if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { + $_incl = $this->helper('checkout')->getPriceInclTax($item); + if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') + && $item->getWeeeTaxAppliedAmount() + ) { + $inclPrice = $_incl + $item->getWeeeTaxAppliedAmount(); + } else { $inclPrice = $_incl - $item->getWeeeTaxDisposition(); - } - } - - $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); - $formatedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); - - $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); - $formatedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); + } + } + $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); + $paypalPrice = Mage::helper('xmlconnect')->formatPriceForXml($item->getCalculationPrice()); + $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); + $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); + $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); - $priceXmlObj = $itemXml->addChild('price'); - $formatedPriceXmlObj = $itemXml->addChild('formated_price'); + $priceXmlObj = $itemXml->addChild('price'); + $formattedPriceXmlObj = $itemXml->addChild('formated_price'); - if ($this->helper('tax')->displayCartBothPrices()) { + if ($this->helper('tax')->displayCartBothPrices()) { $priceXmlObj->addAttribute('excluding_tax', $exclPrice); $priceXmlObj->addAttribute('including_tax', $inclPrice); - $formatedPriceXmlObj->addAttribute('excluding_tax', $formatedExclPrice); - $formatedPriceXmlObj->addAttribute('including_tax', $formatedInclPrice); - } else { - if ($this->helper('tax')->displayCartPriceExclTax()) { - $priceXmlObj->addAttribute('regular', $exclPrice); - $formatedPriceXmlObj->addAttribute('regular', $formatedExclPrice); - } - if ($this->helper('tax')->displayCartPriceInclTax()) { - $priceXmlObj->addAttribute('regular', $inclPrice); - $formatedPriceXmlObj->addAttribute('regular', $formatedInclPrice); - } - } - - - /** + $formattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice); + $formattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice); + } else { + if ($this->helper('tax')->displayCartPriceExclTax()) { + $priceXmlObj->addAttribute('regular', $exclPrice); + $formattedPriceXmlObj->addAttribute('regular', $formattedExclPrice); + } + if ($this->helper('tax')->displayCartPriceInclTax()) { + $priceXmlObj->addAttribute('regular', $inclPrice); + $formattedPriceXmlObj->addAttribute('regular', $formattedInclPrice); + } + } + + /** + * Info for paypal MEP if it's enabled + */ + $appConfig = Mage::helper('xmlconnect')->getApplication()->loadConfiguration()->getRenderConf(); + + $isMepActive = $appConfig['paypal']['isActive']; + + $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null); + if ($paypalMepIsAvailable && $isMepActive) { + $paypalPriceXmlObj = $itemXml->addChild('paypal_price'); + $paypalPriceXmlObj->addAttribute('regular', $paypalPrice); + $paypalPriceXmlObj->addAttribute( + 'subtotal', Mage::helper('xmlconnect')->formatPriceForXml($item->getRowTotal()) + ); + } + + /** * Subtotal */ - $exclPrice = $inclPrice = 0.00; - if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { - if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') - && $item->getWeeeTaxAppliedAmount() - ) { - $exclPrice = $item->getRowTotal() - + $item->getWeeeTaxAppliedRowAmount() - + $item->getWeeeTaxRowDisposition(); - } else { + $exclPrice = $inclPrice = 0; + if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { + if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') + && $item->getWeeeTaxAppliedAmount() + ) { + $exclPrice = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount() + + $item->getWeeeTaxRowDisposition(); + } else { $exclPrice = $item->getRowTotal(); - } - } - if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { - $_incl = $this->helper('checkout')->getSubtotalInclTax($item); - if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') - && $item->getWeeeTaxAppliedAmount() - ) { - $inclPrice = $_incl + $item->getWeeeTaxAppliedRowAmount(); - } else { - $inclPrice = $_incl - $item->getWeeeTaxRowDisposition(); - } - } - - $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); - $formatedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); - - $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); - $formatedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); - - $subtotalPriceXmlObj = $itemXml->addChild('subtotal'); - $subtotalFormatedPriceXmlObj = $itemXml->addChild('formated_subtotal'); - - if ($this->helper('tax')->displayCartBothPrices()) { - $subtotalPriceXmlObj->addAttribute('excluding_tax', $exclPrice); - $subtotalPriceXmlObj->addAttribute('including_tax', $inclPrice); - - $subtotalFormatedPriceXmlObj->addAttribute('excluding_tax', $formatedExclPrice); - $subtotalFormatedPriceXmlObj->addAttribute('including_tax', $formatedInclPrice); - } else { - if ($this->helper('tax')->displayCartPriceExclTax()) { - $subtotalPriceXmlObj->addAttribute('regular', $exclPrice); - $subtotalFormatedPriceXmlObj->addAttribute('regular', $formatedExclPrice); - } - if ($this->helper('tax')->displayCartPriceInclTax()) { - $subtotalPriceXmlObj->addAttribute('regular', $inclPrice); - $subtotalFormatedPriceXmlObj->addAttribute('regular', $formatedInclPrice); - } - } - - /** + } + } + if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { + $_incl = $this->helper('checkout')->getSubtotalInclTax($item); + if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') + && $item->getWeeeTaxAppliedAmount() + ) { + $inclPrice = $_incl + $item->getWeeeTaxAppliedRowAmount(); + } else { + $inclPrice = $_incl - $item->getWeeeTaxRowDisposition(); + } + } + + $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); + $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); + + $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); + $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); + + $subtotalPriceXmlObj = $itemXml->addChild('subtotal'); + $subtotalFormattedPriceXmlObj = $itemXml->addChild('formated_subtotal'); + + if ($this->helper('tax')->displayCartBothPrices()) { + $subtotalPriceXmlObj->addAttribute('excluding_tax', $exclPrice); + $subtotalPriceXmlObj->addAttribute('including_tax', $inclPrice); + + $subtotalFormattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice); + $subtotalFormattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice); + } else { + if ($this->helper('tax')->displayCartPriceExclTax()) { + $subtotalPriceXmlObj->addAttribute('regular', $exclPrice); + $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedExclPrice); + } + if ($this->helper('tax')->displayCartPriceInclTax()) { + $subtotalPriceXmlObj->addAttribute('regular', $inclPrice); + $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedInclPrice); + } + } + + /** * Options list */ - if ($_options = $renderer->getOptionList()) { - $itemOptionsXml = $itemXml->addChild('options'); - foreach ($_options as $_option) { - $_formatedOptionValue = $renderer->getFormatedOptionValue($_option); - $optionXml = $itemOptionsXml->addChild('option'); - $optionXml->addAttribute('label', $xmlObject->xmlentities(strip_tags($_option['label']))); - $optionXml->addAttribute( - 'text', - $xmlObject->xmlentities(strip_tags($_formatedOptionValue['value'])) - ); -// if (isset($_formatedOptionValue['full_view'])) { -// $label = strip_tags($_option['label']); -// $value = strip_tags($_formatedOptionValue['full_view']); -// } - } - } - - /** + if ($_options = $renderer->getOptionList()) { + $itemOptionsXml = $itemXml->addChild('options'); + foreach ($_options as $_option) { + $_formattedOptionValue = $renderer->getFormatedOptionValue($_option); + $optionXml = $itemOptionsXml->addChild('option'); + $optionXml->addAttribute('label', $xmlObject->xmlAttribute($_option['label'])); + $optionXml->addAttribute( + 'text', $xmlObject->xmlAttribute(strip_tags($_formattedOptionValue['value'])) + ); + } + } + + /** * Item messages */ - if ($messages = $renderer->getMessages()) { - $itemMessagesXml = $itemXml->addChild('messages'); - foreach ($messages as $message) { - $messageXml = $itemMessagesXml->addChild('option'); - $messageXml->addChild('type', $message['type']); - $messageXml->addChild('text', $xmlObject->xmlentities(strip_tags($message['text']))); - } - } - } + if ($messages = $renderer->getMessages()) { + $itemMessagesXml = $itemXml->addChild('messages'); + foreach ($messages as $message) { + $messageXml = $itemMessagesXml->addChild('option'); + $messageXml->addChild('type', $message['type']); + $messageXml->addChild('text', $xmlObject->xmlentities($message['text'])); + } + } + } /** * Cart messages diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php b/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php index a16aeb9807..ed5f40b6aa 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php @@ -75,7 +75,7 @@ protected function _toHtml() } $itemXmlObj->addChild('has_options', (int)$product->getHasOptions()); - $itemXmlObj->addChild('in_stock', (int)$product->isInStock()); + $itemXmlObj->addChild('in_stock', (int)$product->getIsInStock()); if ($product->getTypeId() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) { $itemXmlObj->addChild('is_salable', 0); } else { @@ -83,14 +83,12 @@ protected function _toHtml() } if ($this->getChild('product_price')) { - $this->getChild('product_price')->setProduct($product) - ->setProductXmlObj($itemXmlObj) + $this->getChild('product_price')->setProduct($product)->setProductXmlObj($itemXmlObj) ->collectProductPrices(); } if (!$product->getRatingSummary()) { - Mage::getModel('review/review') - ->getEntitySummary($product, Mage::app()->getStore()->getId()); + Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId()); } $itemXmlObj->addChild('rating_summary', round((int)$product->getRatingSummary()->getRatingSummary() / 10)); diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Info.php b/app/code/core/Mage/XmlConnect/Block/Cart/Info.php index 53c74a69f9..ad7e66cd24 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Info.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Info.php @@ -28,7 +28,7 @@ * Shopping cart summary information xml renderer * * @category Mage - * @package Mage_Checkout + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Block_Cart_Info extends Mage_XmlConnect_Block_Cart @@ -45,18 +45,11 @@ protected function _toHtml() /** @var $xmlObject Mage_XmlConnect_Model_Simplexml_Element */ $xmlObject = Mage::getModel('xmlconnect/simplexml_element', ''); - $xmlObject->addChild( - 'is_virtual', - (int)$this->helper('checkout/cart')->getIsVirtualQuote() - ); - $xmlObject->addChild( - 'summary_qty', - (int)$this->helper('checkout/cart')->getSummaryCount() - ); - $xmlObject->addChild( - 'virtual_qty', - (int)$quote->getItemVirtualQty() - ); + $xmlObject->addChild('is_virtual', (int)$this->helper('checkout/cart')->getIsVirtualQuote()); + + $xmlObject->addChild('summary_qty', (int)$this->helper('checkout/cart')->getSummaryCount()); + + $xmlObject->addChild('virtual_qty', (int)$quote->getItemVirtualQty()); if (strlen($quote->getCouponCode())) { $xmlObject->addChild('has_coupon_code', 1); @@ -68,7 +61,6 @@ protected function _toHtml() $totalsXmlObj = Mage::getModel('xmlconnect/simplexml_element', $totalsXml); $xmlObject->appendChild($totalsXmlObj); } - return $xmlObject->asNiceXml(); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer.php b/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer.php new file mode 100644 index 0000000000..3a6f0f2c15 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer.php @@ -0,0 +1,262 @@ + + */ +class Mage_XmlConnect_Block_Cart_Item_Renderer extends Mage_Checkout_Block_Cart_Item_Renderer +{ + /** + * Add product details to XML object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function addProductToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj) + { + $_item = $this->getItem(); + $productXmlObj = $reviewXmlObj->addCustomChild('item'); + $productXmlObj->addCustomChild('name', $this->escapeHtml($this->getProductName())); + + if ($_options = $this->getOptionList()) { + $optionsXmlObj = $productXmlObj->addChild('options'); + foreach ($_options as $_option) { + $_formattedOptionValue = $this->getFormatedOptionValue($_option); + + if (isset($_formattedOptionValue['full_view'])) { + $value = $_formattedOptionValue['full_view']; + } else { + $value = null; + } + + $optionsXmlObj->addCustomChild('option', $value, array( + 'label' => $this->escapeHtml($_option['label']), + 'value' => $_formattedOptionValue['value'] + )); + } + } + + $this->_addPriceToXmlObj($productXmlObj); + $this->_addSubtotalToXmlObj($productXmlObj); + + $productXmlObj->addCustomChild('qty', $_item->getQty()); + + return $reviewXmlObj; + } + + /** + * Add product subtotal info to xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $productXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + protected function _addSubtotalToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $productXmlObj) + { + $_item = $this->getItem(); + $subtotalXmlObj = $productXmlObj->addCustomChild('subtotal'); + + if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { + if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') + && $_item->getWeeeTaxAppliedAmount() + ) { + $exclPrice = $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount() + + $_item->getWeeeTaxRowDisposition(); + } else { + $exclPrice = $_item->getRowTotal(); + } + $exclPrice = $this->_formatPrice($exclPrice); + $subtotalXmlObj->addAttribute('excluding_tax', $subtotalXmlObj->xmlentities($exclPrice)); + } + + if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { + $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); + + if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') + && $_item->getWeeeTaxAppliedAmount() + ) { + $inclPrice = $_incl + $_item->getWeeeTaxAppliedRowAmount(); + } else { + $inclPrice = $_incl - $_item->getWeeeTaxRowDisposition(); + } + $inclPrice = $this->_formatPrice($inclPrice); + + $subtotalXmlObj->addAttribute('including_tax', $subtotalXmlObj->xmlentities($inclPrice)); + } + + if (Mage::helper('weee')->getApplied($_item)) { + $this->_addWeeeToXmlObj($subtotalXmlObj, true); + } + + return $productXmlObj; + } + + /** + * Format product price + * + * @param int $price + * @return float + */ + protected function _formatPrice($price) + { + return $this->getQuote()->getStore()->formatPrice($price, false); + } + + /** + * Add product price info to xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $productXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + protected function _addPriceToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $productXmlObj) + { + $_item = $this->getItem(); + $priceXmlObj = $productXmlObj->addCustomChild('price'); + + if ($this->helper('tax')->displayCartPriceExclTax() + || $this->helper('tax')->displayCartBothPrices() + ) { + if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') + && $_item->getWeeeTaxAppliedAmount() + ) { + $exclPrice = $_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount() + + $_item->getWeeeTaxDisposition(); + } else { + $exclPrice = $_item->getCalculationPrice(); + } + $exclPrice = $this->_formatPrice($exclPrice); + + $priceXmlObj->addAttribute('excluding_tax', $priceXmlObj->xmlentities($exclPrice)); + } + + if ($this->helper('tax')->displayCartPriceInclTax() + || $this->helper('tax')->displayCartBothPrices() + ) { + $_incl = $this->helper('checkout')->getPriceInclTax($_item); + + if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') + && $_item->getWeeeTaxAppliedAmount() + ) { + $inclPrice = $_incl + $_item->getWeeeTaxAppliedAmount(); + } else { + $inclPrice = $_incl - $_item->getWeeeTaxDisposition(); + } + $inclPrice = $this->_formatPrice($inclPrice); + + $priceXmlObj->addAttribute('including_tax', $priceXmlObj->xmlentities($inclPrice)); + } + + if (Mage::helper('weee')->getApplied($_item)) { + $this->_addWeeeToXmlObj($priceXmlObj); + } + + return $productXmlObj; + } + + /** + * Add weee tax product info to xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj + * @param bool $subtotalFlag use true to get subtotal product info + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + protected function _addWeeeToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj, $subtotalFlag = false) + { + $_item = $this->getItem(); + $weeeXmlObj = $priceXmlObj->addCustomChild('weee'); + + if ($subtotalFlag) { + $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); + } else { + $_incl = $this->helper('checkout')->getPriceInclTax($_item); + } + + $typeOfDisplay2 = Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales'); + + if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()) { + foreach (Mage::helper('weee')->getApplied($_item) as $tax) { + + if ($subtotalFlag) { + $amount = $tax['row_amount']; + } else { + $amount = $tax['amount']; + } + + $weeeXmlObj->addCustomChild('item', null, array( + 'name' => $tax['title'], + 'amount' => $this->_formatPrice($amount) + )); + } + } elseif ($_item->getWeeeTaxAppliedAmount() + && ($typeOfDisplay2 || Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')) + ) { + foreach (Mage::helper('weee')->getApplied($_item) as $tax) { + if ($subtotalFlag) { + $amount = $tax['row_amount_incl_tax']; + } else { + $amount = $tax['amount_incl_tax']; + } + + $weeeXmlObj->addCustomChild('item', null, array( + 'name' => $tax['title'], + 'amount' => $this->_formatPrice($amount) + )); + } + } + + if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) { + if ($subtotalFlag) { + $totalExcl = $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount() + + $_item->getWeeeTaxRowDisposition(); + } else { + $totalExcl = $_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount() + + $_item->getWeeeTaxDisposition(); + } + + $totalExcl = $this->_formatPrice($totalExcl); + $priceXmlObj->addAttribute( + 'total_excluding_tax', + $priceXmlObj->xmlentities($totalExcl) + ); + } + + if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) { + if ($subtotalFlag) { + $totalIncl = $_incl + $_item->getWeeeTaxAppliedRowAmount(); + } else { + $totalIncl = $_incl + $_item->getWeeeTaxAppliedAmount(); + } + + $totalIncl = $this->_formatPrice($totalIncl); + $priceXmlObj->addAttribute('total_including_tax', $priceXmlObj->xmlentities($totalIncl)); + } + + return $priceXmlObj; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Configurable.php b/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Configurable.php new file mode 100644 index 0000000000..86e2b530c5 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Configurable.php @@ -0,0 +1,88 @@ + + */ +class Mage_XmlConnect_Block_Cart_Item_Renderer_Configurable extends Mage_XmlConnect_Block_Cart_Item_Renderer +{ + const CONFIGURABLE_PRODUCT_IMAGE = 'checkout/cart/configurable_product_image'; + const USE_PARENT_IMAGE = 'parent'; + + /** + * Get item configurable product + * + * @return Mage_Catalog_Model_Product + */ + public function getConfigurableProduct() + { + $option = $this->getItem()->getOptionByCode('product_type'); + if ($option) { + return $option->getProduct(); + } + return $this->getProduct(); + } + + /** + * Get item configurable child product + * + * @return Mage_Catalog_Model_Product + */ + public function getChildProduct() + { + $option = $this->getItem()->getOptionByCode('simple_product'); + if ($option) { + return $option->getProduct(); + } + return $this->getProduct(); + } + + /** + * Get item product name + * + * @return string + */ + public function getProductName() + { + return $this->getProduct()->getName(); + } + + /** + * Get list of all options for product + * + * @return array + */ + public function getOptionList() + { + /* @var $helper Mage_Catalog_Helper_Product_Configuration */ + $helper = Mage::helper('catalog/product_configuration'); + return $helper->getConfigurableOptions($this->getItem()); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Grouped.php b/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Grouped.php new file mode 100644 index 0000000000..49e539e4c6 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Item/Renderer/Grouped.php @@ -0,0 +1,52 @@ + + */ +class Mage_XmlConnect_Block_Cart_Item_Renderer_Grouped extends Mage_XmlConnect_Block_Cart_Item_Renderer +{ + const GROUPED_PRODUCT_IMAGE = 'checkout/cart/grouped_product_image'; + const USE_PARENT_IMAGE = 'parent'; + + /** + * Get item grouped product + * + * @return Mage_Catalog_Model_Product + */ + public function getGroupedProduct() + { + $option = $this->getItem()->getOptionByCode('product_type'); + if ($option) { + return $option->getProduct(); + } + return $this->getProduct(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Details.php b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Details.php new file mode 100644 index 0000000000..59561df5b8 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Details.php @@ -0,0 +1,87 @@ + + */ +class Mage_XmlConnect_Block_Cart_Paypal_Mecl_Details extends Mage_Paypal_Block_Express_Review_Details +{ + /** + * Add cart details to XML object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function addDetailsToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj) + { + $itemsXmlObj = $reviewXmlObj->addChild('ordered_items'); + foreach ($this->getItems() as $_item) { + $this->getItemXml($_item, $itemsXmlObj); + } + + $reviewXmlObj->appendChild($this->getChild('totals')->setReturnObjectFlag(true)->_toHtml()); + + return $reviewXmlObj; + } + + /** + * Get item row xml + * + * @param Mage_Sales_Model_Quote_Item $item + * @param Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function getItemXml( + Mage_Sales_Model_Quote_Item $item, + Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj + ) + { + $renderer = $this->getItemRenderer($item->getProductType())->setItem($item)->setQuote($this->getQuote()); + return $renderer->addProductToXmlObj($reviewXmlObj); + } + + /** + * Add renderer for item product type + * + * @param string $productType + * @param string $blockType + * @param string $template + * @return Mage_Checkout_Block_Cart_Abstract + */ + public function addItemRender($productType, $blockType, $template) + { + $this->_itemRenders[$productType] = array( + 'block' => $blockType, + 'template' => $template, + 'blockInstance' => null + ); + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Review.php b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Review.php new file mode 100644 index 0000000000..a2c8a07e87 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Review.php @@ -0,0 +1,94 @@ + + */ +class Mage_XmlConnect_Block_Cart_Paypal_Mecl_Review extends Mage_Paypal_Block_Express_Review +{ + /** + * Render PayPal MECL details xml + * + * @return string xml + */ + protected function _toHtml() + { + /** @var $reviewXmlObj Mage_XmlConnect_Model_Simplexml_Element */ + $reviewXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); + + if ($this->getPaypalMessages()) { + $reviewXmlObj->addChild('paypal_message', implode(PHP_EOL, $this->getPaypalMessages())); + } + + if ($this->getShippingAddress()) { + $reviewXmlObj->addCustomChild( + 'shipping_address', + Mage::helper('xmlconnect')->trimLineBreaks($this->getShippingAddress()->format('text')), + array('label' => $this->__('Shipping Address')) + ); + } + + if ($this->_quote->isVirtual()) { + $reviewXmlObj->addCustomChild('shipping_method', null, array( + 'label' => $this->__('No shipping method required.') + )); + } elseif ($this->getCanEditShippingMethod() || !$this->getCurrentShippingRate()) { + if ($groups = $this->getShippingRateGroups()) { + $currentRate = $this->getCurrentShippingRate(); + foreach ($groups as $code => $rates) { + foreach ($rates as $rate) { + if ($currentRate === $rate) { + $reviewXmlObj->addCustomChild('shipping_method', null, array( + 'rate' => strip_tags($this->renderShippingRateOption($rate)), + 'label' => $this->getCarrierName($code) + )); + break(2); + } + } + } + } + } + $reviewXmlObj->addCustomChild('payment_method', $this->escapeHtml($this->getPaymentMethodTitle()), array( + 'label' => $this->__('Payment Method') + )); + + $reviewXmlObj->addCustomChild( + 'billing_address', + Mage::helper('xmlconnect')->trimLineBreaks($this->getBillingAddress()->format('text')), + array( + 'label' => $this->__('Billing Address'), + 'payer_email' => $this->__('Payer Email: %s', $this->getBillingAddress()->getEmail()) + )); + + $this->getChild('details')->addDetailsToXmlObj($reviewXmlObj); + + return $reviewXmlObj->asNiceXml(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Shippingmethods.php b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Shippingmethods.php new file mode 100644 index 0000000000..d8d5f2dff9 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mecl/Shippingmethods.php @@ -0,0 +1,97 @@ + + */ +class Mage_XmlConnect_Block_Cart_Paypal_Mecl_Shippingmethods + extends Mage_Paypal_Block_Express_Review +{ + /** + * Render PayPal MECL shipping method list xml + * + * @return string xml + */ + protected function _toHtml() + { + /** @var $listXmlObj Mage_XmlConnect_Model_Simplexml_Element */ + $methodListXmlObj = Mage::getModel( + 'xmlconnect/simplexml_element', + '' + ); + + $methodListXmlObj->addAttribute('label', $this->__('Shipping Method')); + + if ($this->getCanEditShippingMethod() || !$this->getCurrentShippingRate()) { + $groups = $this->getShippingRateGroups(); + if ($groups) { + $currentRate = $this->getCurrentShippingRate(); + foreach ($groups as $code => $rates) { + $rateXmlObj = $this->_addRatesToXmlObj($methodListXmlObj, $code); + foreach ($rates as $rate) { + $rateAttributes = array( + 'label' => strip_tags($this->renderShippingRateOption($rate)), + 'code' => $this->renderShippingRateValue($rate) + ); + if ($currentRate === $rate) { + $rateAttributes += array('selected' => 1); + } + $rateXmlObj->addCustomChild('rate', null, $rateAttributes); + } + } + } else { + $message = $this->_quote->isVirtual() ? $this->__('No shipping method required.') + : $this->__('Sorry, no quotes are available for this order at this time.'); + $methodListXmlObj->addCustomChild('method', null, array('label' => $message)); + } + } else { + $rateXmlObj = $this->_addRatesToXmlObj($methodListXmlObj); + $rateXmlObj->addCustomChild('rate', null, array( + 'label' => $this->renderShippingRateOption($this->getCurrentShippingRate()), + 'selected' => 1 + )); + } + + return $methodListXmlObj->asNiceXml(); + } + + /** + * Add cart details to XML object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $methodListXmlObj + * @param string $code + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + protected function _addRatesToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $methodListXmlObj, $code = '') + { + $attributes = $code ? array('label' => $this->getCarrierName($code)) : array(); + return $methodListXmlObj->addCustomChild('method', null, $attributes)->addCustomChild('rates'); + } +} 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 65f8feb501..0903d6b3f1 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 @@ -28,7 +28,7 @@ * PayPal MEP Shopping cart totals xml renderer * * @category Mage - * @package Mage_Cart + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Block_Cart_Paypal_Mep_Totals extends Mage_Checkout_Block_Cart_Totals @@ -48,6 +48,39 @@ protected function _toHtml() $currencyAmount = $this->helper('core')->currency($amount, false, false); $totalsXmlObj->addChild($code, sprintf('%01.2F', $currencyAmount)); } + + $paypalTotals = $totalsXmlObj->addChild('paypal_totals'); + foreach ($this->getQuote()->getTotals() as $total) { + $code = $total->getCode(); + if ($code == 'giftcardaccount' || $code == 'giftwrapping') { + continue; + } + $renderer = $this->_getTotalRenderer($code)->setTotal($total); + switch ($code) { + case 'subtotal': + $subtotal = intval($total->getValueExclTax()) ? $total->getValueExclTax() : $total->getValue(); + $paypalTotals->addAttribute( + $code, + Mage::helper('xmlconnect')->formatPriceForXml($subtotal) + ); + break; + case 'tax': + $paypalTotals->addAttribute( + $code, + Mage::helper('xmlconnect')->formatPriceForXml($total->getValue()) + ); + break; + case 'shipping': + $paypalTotals->addAttribute( + $code, + Mage::helper('xmlconnect')->formatPriceForXml($renderer->getShippingExcludeTax()) + ); + break; + default: + break; + } + } + return $totalsXmlObj->asNiceXml(); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Totals.php b/app/code/core/Mage/XmlConnect/Block/Cart/Totals.php index 1a1a5c5c7d..19d4819eeb 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Totals.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Totals.php @@ -28,7 +28,7 @@ * Shopping cart totals xml renderer * * @category Mage - * @package Mage_Checkout + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Block_Cart_Totals extends Mage_Checkout_Block_Cart_Totals @@ -36,30 +36,30 @@ class Mage_XmlConnect_Block_Cart_Totals extends Mage_Checkout_Block_Cart_Totals /** * Render cart totals xml * - * @return string + * @return string|Mage_XmlConnect_Model_Simplexml_Element */ protected function _toHtml() { /** @var $totalsXmlObj Mage_XmlConnect_Model_Simplexml_Element */ $totalsXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); -// $taxConfig = Mage::getSingleton('tax/config'); foreach ($this->getQuote()->getTotals() as $total) { $code = $total->getCode(); - if ($code == 'giftcardaccount' || $code == 'giftwrapping') { + if ($code == 'giftwrapping') { continue; } + $title = ''; $value = null; $renderer = $this->_getTotalRenderer($code)->setTotal($total); + switch ($code) { case 'subtotal': if ($renderer->displayBoth()) { $title = $this->__('Subtotal (Excl. Tax)'); $this->_addTotalDataToXmlObj( $totalsXmlObj, - $code . - '_excl_tax', + $code . '_excl_tax', $title, $total->getValueExclTax() ); @@ -73,11 +73,7 @@ protected function _toHtml() if ($renderer->displayBoth()) { $title = $renderer->getExcludeTaxLabel(); $this->_addTotalDataToXmlObj( - $totalsXmlObj, - $code . - '_excl_tax', - $title, - $renderer->getShippingExcludeTax() + $totalsXmlObj, $code . '_excl_tax', $title, $renderer->getShippingExcludeTax() ); $code = $code . '_incl_tax'; @@ -95,28 +91,50 @@ protected function _toHtml() if ($displayBoth) { $title = $this->__('Grand Total (Excl. Tax)'); $this->_addTotalDataToXmlObj( - $totalsXmlObj, - $code . '_excl_tax', - $title, - $grandTotalExlTax + $totalsXmlObj, $code . '_excl_tax', $title, $grandTotalExlTax ); $code = $code . '_incl_tax'; $title = $this->__('Grand Total (Incl. Tax)'); } break; + case 'giftwrapping': + foreach ($renderer->getValues() as $title => $value) { + $this->_addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value); + } + continue 2; + case 'giftcardaccount': + $_cards = $renderer->getTotal()->getGiftCards(); + if (!$_cards) { + $_cards = $renderer->getQuoteGiftCards(); + } + if ($renderer->getTotal()->getValue()) { + foreach ($_cards as $cardCode) { + $title = $this->__('Gift Card (%s)', $cardCode['c']); + $value = $cardCode['c']; + $totalXmlObj = $totalsXmlObj->addChild($code); + $totalXmlObj->addChild('title', $totalsXmlObj->xmlentities($title)); + $totalXmlObj->addChild('value', $value); + $value = Mage::helper('xmlconnect')->formatPriceForXml($cardCode['a']); + $formattedValue = $this->getQuote()->getStore()->formatPrice($value, false); + $totalXmlObj->addChild('formated_value', '-' . $formattedValue); + } + } + continue 2; default: break; } if (empty($title)) { $title = $total->getTitle(); } - if (is_null($value)) { + if (null === $value) { $value = $total->getValue(); } - $this->_addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value); + if (null !== $value) { + $this->_addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value); + } } - return $totalsXmlObj->asNiceXml(); + return $this->getReturnObjectFlag() ? $totalsXmlObj : $totalsXmlObj->asNiceXml(); } /** diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog.php b/app/code/core/Mage/XmlConnect/Block/Catalog.php index c261b001b4..54e8b01832 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog.php @@ -23,6 +23,14 @@ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Catalog xml renderer + * + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team + */ class Mage_XmlConnect_Block_Catalog extends Mage_Core_Block_Template { /** diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php index 6cc1d87231..eb5aa2c9cf 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php @@ -55,31 +55,30 @@ protected function _toHtml() $productListBlock = $this->getChild('product_list'); if ($productListBlock && $categoryModel->getLevel() > 1) { $layer = Mage::getSingleton('catalog/layer'); - $productsXmlObj = $productListBlock->setCategory($categoryModel) - ->setLayer($layer) + $productsXmlObj = $productListBlock->setCategory($categoryModel)->setLayer($layer) ->getProductsXmlObject(); $hasMoreProductItems = (int)$productListBlock->getHasProductItems(); } $infoBlock = $this->getChild('category_info'); if ($infoBlock) { - $categoryInfoXmlObj = $infoBlock->setCategory($categoryModel) - ->getCategoryInfoXmlObject(); + $categoryInfoXmlObj = $infoBlock->setCategory($categoryModel)->getCategoryInfoXmlObject(); $categoryInfoXmlObj->addChild('has_more_items', $hasMoreProductItems); $categoryXmlObj->appendChild($categoryInfoXmlObj); } } - $categoryCollection = $categoryModel->getCategories($categoryId, 0, false, true); + $categoryCollection = $this->getCurrentChildCategories(); // subcategories are exists if (sizeof($categoryCollection)) { $itemsXmlObj = $categoryXmlObj->addChild('items'); foreach ($categoryCollection as $item) { - $itemXmlObj = $itemsXmlObj->addChild('item'); /** @var $item Mage_Catalog_Model_Category */ $item = Mage::getModel('catalog/category')->load($item->getId()); - $itemXmlObj->addChild('label', $categoryXmlObj->xmlentities(strip_tags($item->getName()))); + + $itemXmlObj = $itemsXmlObj->addChild('item'); + $itemXmlObj->addChild('label', $categoryXmlObj->xmlentities($item->getName())); $itemXmlObj->addChild('entity_id', $item->getId()); $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products'); if (!is_null($categoryId)) { @@ -100,4 +99,21 @@ protected function _toHtml() } return $categoryXmlObj->asNiceXml(); } + + /** + * Retrieve child categories of current category + * + * @return Varien_Data_Tree_Node_Collection + */ + public function getCurrentChildCategories() + { + $layer = Mage::getSingleton('catalog/layer'); + $category = $layer->getCurrentCategory(); + /* @var $category Mage_Catalog_Model_Category */ + $categories = $category->getChildrenCategories(); + $productCollection = Mage::getResourceModel('catalog/product_collection'); + $layer->prepareProductCollection($productCollection); + $productCollection->addCountToCategories($categories); + return $categories; + } } 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 6abd9945e2..ba74afce1e 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php @@ -42,7 +42,7 @@ public function getCategoryInfoXmlObject() { $infoXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); $category = $this->getCategory(); - if ($category && is_object($category) && $category->getId()) { + if (is_object($category) && $category->getId()) { /** * @var string $title * @@ -50,7 +50,7 @@ public function getCategoryInfoXmlObject() */ $title = $this->__('Shop'); if ($category->getParentCategory()->getLevel() > 1) { - $title = $infoXmlObj->xmlentities(strip_tags($category->getParentCategory()->getName())); + $title = $infoXmlObj->xmlentities($category->getParentCategory()->getName()); } $infoXmlObj->addChild('parent_title', $title); diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php index 1cf068c0d2..cb72d40270 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php @@ -50,7 +50,7 @@ protected function _toHtml() continue; } $itemXmlObj = $filtersXmlObj->addChild('item'); - $itemXmlObj->addChild('name', $categoryXmlObj->xmlentities(strip_tags($item->getName()))); + $itemXmlObj->addChild('name', $categoryXmlObj->xmlentities($item->getName())); $itemXmlObj->addChild('code', $categoryXmlObj->xmlentities($item->getCode())); $valuesXmlObj = $itemXmlObj->addChild('values'); diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php index b2f54fb82b..701afbdd90 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php @@ -46,9 +46,9 @@ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNod $item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '>'); if ($product && $product->getId()) { $item->addChild('entity_id', $product->getId()); - $item->addChild('name', $item->xmlentities(strip_tags($product->getName()))); + $item->addChild('name', $item->xmlentities($product->getName())); $item->addChild('entity_type', $product->getTypeId()); - $item->addChild('short_description', $item->xmlentities(strip_tags($product->getShortDescription()))); + $item->addChild('short_description', $item->xmlentities($product->getShortDescription())); $description = Mage::helper('xmlconnect')->htmlize($item->xmlentities($product->getDescription())); $item->addChild('description', $description); $item->addChild('link', $product->getProductUrl()); @@ -61,15 +61,14 @@ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNod $propertyToResizeName = 'image'; } - $icon = clone Mage::helper('catalog/image')->init($product, $propertyToResizeName) - ->resize($imageToResize); + $icon = clone Mage::helper('catalog/image')->init($product, $propertyToResizeName)->resize($imageToResize); $iconXml = $item->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); - $item->addChild('in_stock', (int)$product->isInStock()); + $item->addChild('in_stock', (int)$product->getIsInStock()); $item->addChild('is_salable', (int)$product->isSalable()); /** * By default all products has gallery (because of collection not load gallery attribute) @@ -92,17 +91,15 @@ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNod } if (!$product->getRatingSummary()) { - Mage::getModel('review/review') - ->getEntitySummary($product, Mage::app()->getStore()->getId()); + Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId()); } $item->addChild('rating_summary', round((int)$product->getRatingSummary()->getRatingSummary() / 10)); $item->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount()); if ($this->getChild('product_price')) { - $this->getChild('product_price')->setProduct($product) - ->setProductXmlObj($item) - ->collectProductPrices(); + $this->getChild('product_price')->setProduct($product)->setProductXmlObj($item) + ->collectProductPrices(); } if ($this->getChild('additional_info')) { @@ -138,8 +135,7 @@ protected function _getMinimalQty($product) protected function _toHtml() { /** @var $product Mage_Catalog_Model_Product */ - $product = Mage::getModel('catalog/product') - ->setStoreId(Mage::app()->getStore()->getId()) + $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId()) ->load($this->getRequest()->getParam('id', 0)); if (!$product) { 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 3116c53520..6daac159e8 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php @@ -40,10 +40,8 @@ class Mage_XmlConnect_Block_Catalog_Product_Attributes extends Mage_Catalog_Bloc * @param Mage_XmlConnect_Model_Simplexml_Element $productXmlObject */ public function addAdditionalData( - Mage_Catalog_Model_Product $product, - Mage_XmlConnect_Model_Simplexml_Element $productXmlObject - ) - { + Mage_Catalog_Model_Product $product, Mage_XmlConnect_Model_Simplexml_Element $productXmlObject + ) { if ($product && $productXmlObject && $product->getId()) { $this->_product = $product; $additionalData = $this->getAdditionalData(); 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 125070591b..44c78c096e 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php @@ -41,9 +41,7 @@ class Mage_XmlConnect_Block_Catalog_Product_Gallery extends Mage_XmlConnect_Bloc protected function _toHtml() { $productId = $this->getRequest()->getParam('id', null); - $product = Mage::getModel('catalog/product') - ->setStoreId(Mage::app()->getStore()->getId()) - ->load($productId); + $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId); $collection = $product->getMediaGalleryImages(); $imagesNode = Mage::getModel('xmlconnect/simplexml_element', ''); @@ -55,9 +53,7 @@ protected function _toHtml() /** * Big image */ - $bigImage = $helper->init($product, 'image', $item->getFile()) - ->constrainOnly(true) - ->keepFrame(false) + $bigImage = $helper->init($product, 'image', $item->getFile())->constrainOnly(true)->keepFrame(false) ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_gallery_big')); $fileNode = $imageNode->addChild('file'); @@ -72,9 +68,7 @@ protected function _toHtml() /** * Small image */ - $smallImage = $helper->init($product, 'thumbnail', $item->getFile()) - ->constrainOnly(true) - ->keepFrame(false) + $smallImage = $helper->init($product, 'thumbnail', $item->getFile())->constrainOnly(true)->keepFrame(false) ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_gallery_small')); $fileNode = $imageNode->addChild('file'); 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 985e49ce41..602028af47 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php @@ -99,7 +99,6 @@ protected function _getProductCollection() if ($category && is_object($category) && $category->getId()) { $layer->setCurrentCategory($category); } - if (!$this->getNeedBlockApplyingFilters()) { $attributes = $layer->getFilterableAttributes(); /** @@ -107,10 +106,9 @@ protected function _getProductCollection() */ foreach ($attributes as $attributeItem) { $attributeCode = $attributeItem->getAttributeCode(); - $filterModel = $this->helper('xmlconnect')->getFilterByKey($attributeCode); + list($filterModel, $filterBlock) = $this->helper('xmlconnect')->getFilterByKey($attributeCode); - $filterModel->setLayer($layer) - ->setAttributeModel($attributeItem); + $filterModel->setLayer($layer)->setAttributeModel($attributeItem); $filterParam = parent::REQUEST_FILTER_PARAM_REFIX . $attributeCode; /** @@ -119,18 +117,17 @@ protected function _getProductCollection() if (isset($requestParams[$filterParam])) { $filterModel->setRequestVar($filterParam); } - $filterModel->apply($request, null); + $filterModel->apply($request, $filterBlock); $filters[] = $filterModel; } /** * Separately apply and save category filter */ - $categoryFilter = $this->helper('xmlconnect')->getFilterByKey('category'); - $filterParam = parent::REQUEST_FILTER_PARAM_REFIX . $categoryFilter->getRequestVar(); - $categoryFilter->setLayer($layer) - ->setRequestVar($filterParam) - ->apply($this->getRequest(), null); + list($categoryFilter, $categoryFilterBlock) = $this->helper('xmlconnect')->getFilterByKey('category'); + $filterParam = parent::REQUEST_FILTER_PARAM_REFIX . $categoryFilter->getRequestVar(); + $categoryFilter->setLayer($layer)->setRequestVar($filterParam) + ->apply($this->getRequest(), $categoryFilterBlock); $filters[] = $categoryFilter; $this->_collectedFilters = $filters; @@ -157,7 +154,6 @@ protected function _getProductCollection() $this->setHasProductItems(1); } $collection->getSelect()->limit($count, $offset); - $collection->setFlag('require_stock_items', true); $this->_productCollection = $collection; 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 f6fd9d0a66..1d159608b7 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php @@ -87,7 +87,7 @@ public function getProductCustomOptionsXmlObject(Mage_Catalog_Model_Product $pro } $optionNode->addAttribute('code', $code); $optionNode->addAttribute('type', $type); - $optionNode->addAttribute('label', $xmlModel->xmlentities(strip_tags($option->getTitle()))); + $optionNode->addAttribute('label', $xmlModel->xmlentities($option->getTitle())); if ($option->getIsRequire()) { $optionNode->addAttribute('is_required', 1); } @@ -98,21 +98,20 @@ public function getProductCustomOptionsXmlObject(Mage_Catalog_Model_Product $pro $price = $option->getPrice(); if ($price) { $optionNode->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml($price)); - $formatedPrice = Mage::app()->getStore($product->getStoreId())->formatPrice($price, false); - $optionNode->addAttribute('formated_price', $formatedPrice); + $formattedPrice = Mage::app()->getStore($product->getStoreId())->formatPrice($price, false); + $optionNode->addAttribute('formated_price', $formattedPrice); } - if ($type == self::OPTION_TYPE_CHECKBOX || - $type == self::OPTION_TYPE_SELECT) { + if ($type == self::OPTION_TYPE_CHECKBOX || $type == self::OPTION_TYPE_SELECT) { foreach ($option->getValues() as $value) { $valueNode = $optionNode->addChild('value'); $valueNode->addAttribute('code', $value->getId()); - $valueNode->addAttribute('label', $xmlModel->xmlentities(strip_tags($value->getTitle()))); + $valueNode->addAttribute('label', $xmlModel->xmlentities($value->getTitle())); - $price = Mage::helper('xmlconnect')->formatPriceForXml($value->getPrice()); - if ((float)$price != 0.00) { + if ($value->getPrice() != 0) { + $price = Mage::helper('xmlconnect')->formatPriceForXml($value->getPrice()); $valueNode->addAttribute('price', $price); - $formatedPrice = $this->_formatPriceString($price, $product); - $valueNode->addAttribute('formated_price', $formatedPrice); + $formattedPrice = $this->_formatPriceString($price, $product); + $valueNode->addAttribute('formated_price', $formattedPrice); } } } @@ -133,12 +132,9 @@ protected function _formatPriceString($price, $product) $priceIncTax = Mage::helper('tax')->getPrice($product, $price, true); if (Mage::helper('tax')->displayBothPrices() && $priceTax != $priceIncTax) { - $formatted = Mage::helper('core')->currency($priceTax, true, false) - . ' (+' - . Mage::helper('core')->currency($priceIncTax, true, false) - . ' ' - . Mage::helper('tax')->__('Incl. Tax') - . ')'; + $formatted = Mage::helper('core')->currency($priceTax, true, false) . ' (+' + . Mage::helper('core')->currency($priceIncTax, true, false) . ' ' + . Mage::helper('tax')->__('Incl. Tax') . ')'; } else { $formatted = $this->helper('core')->currency($priceTax, true, false); } @@ -201,6 +197,7 @@ protected function _toHtml() { $productId = $this->getRequest()->getParam('id', null); $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId()); + if ($productId) { $product->load($productId); } 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 100023eccc..94ed27c17c 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 @@ -27,11 +27,10 @@ /** * Bundle product options xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - class Mage_XmlConnect_Block_Catalog_Product_Options_Bundle extends Mage_XmlConnect_Block_Catalog_Product_Options { /** @@ -43,7 +42,6 @@ class Mage_XmlConnect_Block_Catalog_Product_Options_Bundle extends Mage_XmlConne */ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false) { - $xmlModel = $this->getProductCustomOptionsXmlObject($product); $optionsXmlObj = $xmlModel->options; @@ -57,8 +55,7 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product); $optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product); $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection( - $product->getTypeInstance(true)->getOptionsIds($product), - $product + $product->getTypeInstance(true)->getOptionsIds($product), $product ); $bundleOptions = $optionCollection->appendSelections($selectionCollection, false, false); if (!sizeof($bundleOptions)) { @@ -83,13 +80,11 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj } $optionNode->addAttribute('code', $code); $optionNode->addAttribute('type', $type); - $optionNode->addAttribute('label', $optionsXmlObj->xmlentities(strip_tags($_option->getTitle()))); + $optionNode->addAttribute('label', $optionsXmlObj->xmlentities($_option->getTitle())); if ($_option->getRequired()) { $optionNode->addAttribute('is_required', 1); } -// $_default = $_option->getDefaultSelection(); - foreach ($selections as $_selection) { if (!$_selection->isSaleable()) { continue; @@ -98,7 +93,7 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj $valueNode = $optionNode->addChild('value'); $valueNode->addAttribute('code', $_selection->getSelectionId()); - $valueNode->addAttribute('label', $optionsXmlObj->xmlentities(strip_tags($_selection->getName()))); + $valueNode->addAttribute('label', $optionsXmlObj->xmlentities($_selection->getName())); if (!$_option->isMultiSelection()) { if ($_selection->getSelectionCanChangeQty()) { $valueNode->addAttribute('is_qty_editable', 1); @@ -114,8 +109,6 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj )); $valueNode->addAttribute('formated_price', $this->_formatPriceString($price, $product)); } - -// $_selection->getIsDefault(); } } 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 fc7c22f9ed..cbaaa866af 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 @@ -27,11 +27,10 @@ /** * Configurable product options xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - class Mage_XmlConnect_Block_Catalog_Product_Options_Configurable extends Mage_XmlConnect_Block_Catalog_Product_Options { /** @@ -132,13 +131,13 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj $optionNode = $optionsXmlObj->addChild('option'); $optionNode->addAttribute('code', 'super_attribute[' . $id . ']'); $optionNode->addAttribute('type', 'select'); - $optionNode->addAttribute('label', strip_tags($attribute['label'])); + $optionNode->addAttribute('label', $optionsXmlObj->xmlentities($attribute['label'])); $optionNode->addAttribute('is_required', 1); if ($isFirst) { foreach ($attribute['options'] as $option) { $valueNode = $optionNode->addChild('value'); $valueNode->addAttribute('code', $option['id']); - $valueNode->addAttribute('label', $optionsXmlObj->xmlentities(strip_tags($option['label']))); + $valueNode->addAttribute('label', $optionsXmlObj->xmlentities($option['label'])); if ((float)$option['price'] != 0.00) { $valueNode->addAttribute('price', $option['price']); $valueNode->addAttribute('formated_price', $option['formated_price']); @@ -157,7 +156,7 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj /** * Add recursively relations on each option * - * @param &Mage_XmlConnect_Model_Simplexml_Element &$valueNode value node object + * @param Mage_XmlConnect_Model_Simplexml_Element &$valueNode value node object * @param array $attributes all products attributes (options) * @param array $productIds prodcuts to search in next levels attributes * @param int $cycle @@ -188,7 +187,7 @@ protected function _prepareRecursivelyRelatedValues(&$valueNode, $attributes, $p $_valueNode = $relatedNode->addChild('value'); $_valueNode->addAttribute('code', $option['id']); - $_valueNode->addAttribute('label', $_valueNode->xmlentities(strip_tags($option['label']))); + $_valueNode->addAttribute('label', $_valueNode->xmlentities($option['label'])); if ((float)$option['price'] != 0.00) { $_valueNode->addAttribute('price', $option['price']); $_valueNode->addAttribute('formated_price', $option['formated_price']); @@ -210,7 +209,7 @@ protected function _prepareRecursivelyRelatedValues(&$valueNode, $attributes, $p * * @param Mage_Catalog_Model_Product $product * @param float|int|string $price - * @param unknown_type $isPercent + * @param bool $isPercent * @return float */ protected function _preparePrice($product, $price, $isPercent = false) diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php index 198a9f1dbf..5aee915c91 100755 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php @@ -27,9 +27,9 @@ /** * Gift Card product options xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Catalog_Product_Options_Giftcard extends Mage_XmlConnect_Block_Catalog_Product_Options { @@ -70,7 +70,7 @@ public function getSenderEmail() } /** - * Get preconfigured values from product + * Get pre-configured values from product * * @param $value param id * @return string @@ -145,144 +145,125 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj /** @var $optionsXmlObj Mage_XmlConnect_Model_Simplexml_Element */ $optionsXmlObj = $xmlModel->options; - if (!$product->isSaleable()) { + if (!$product->isSalable()) { return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } - /** @var $test Enterprise_GiftCard_Model_Catalog_Product_Type_Giftcard */ - $giftCard = $product->getTypeInstance(true); - /** @var $priceModel Enterprise_GiftCard_Block_Catalog_Product_Price */ $priceModel = $product->getPriceModel(); /** @var $coreHelper Mage_Core_Helper_Data */ $coreHelper = Mage::helper('core'); - if ($this->isAmountAvailable($product)) { + $configValue = $this->getDefaultValue('giftcard_amount'); - $configValue = $this->getDefaultValue('giftcard_amount'); + /** + * Render fixed amounts options + */ - /** - * Render fixed amounts options - */ - if (count($amounts = $priceModel->getSortedAmounts($product))) { - $amountNode = $optionsXmlObj->addChild('fixed_amounts'); + /** @var $fixedAmountsNode Mage_XmlConnect_Model_Simplexml_Element */ + $fixedAmountsNode = $optionsXmlObj->addChild('fixed_amounts'); + if ($this->isAmountAvailable($product)) { + $amounts = $priceModel->getSortedAmounts($product); + if (count($amounts)) { foreach ($amounts as $price) { - $amount = $amountNode->addChild('amount'); + $amountNode = $fixedAmountsNode->addChild('amount'); if ($configValue == $price) { - $amount->addAttribute('selected', 1); + $amountNode->addAttribute('selected', 1); } - $amount->addAttribute( - 'price', + $amountNode->addAttribute('formatted_price', $xmlModel->xmlAttribute( $coreHelper->currency($price, true, false) - ); + )); + $amountNode->addAttribute('price', $price); } } + } - /** - * Render open amount options - */ - $openAmountNode = $optionsXmlObj->addChild('open_amount'); - if ($product->getAllowOpenAmount()) { - $openAmountNode->addAttribute('enabled', 1); - if ($configValue == 'custom') { - $openAmountNode->addAttribute( - 'selected_amount', - $this->getDefaultValue('custom_giftcard_amount') - ); - } - if ($priceModel->getMinAmount($product)) { - $minAmount = $xmlModel->xmlentities( - $coreHelper->currency( - $product->getOpenAmountMin(), - true, - false - ) - ); - } else { - $minAmount = 0; - } - $openAmountNode->addAttribute('min_amount', $minAmount); + /** + * Render open amount options + */ + /** @var $openAmountNode Mage_XmlConnect_Model_Simplexml_Element */ + $openAmountNode = $optionsXmlObj->addChild('open_amount'); + if ($product->getAllowOpenAmount()) { + $openAmountNode->addAttribute('enabled', 1); - if ($priceModel->getMaxAmount($product)) { - $maxAmount = $xmlModel->xmlentities( - $coreHelper->currency( - $product->getOpenAmountMax(), - true, - false - ) - ); - } else { - $maxAmount = 0; - } - $openAmountNode->addAttribute('max_amount', $maxAmount); + if ($configValue == 'custom') { + $openAmountNode->addAttribute('selected_amount', $this->getDefaultValue('custom_giftcard_amount')); + } + if ($priceModel->getMinAmount($product)) { + $minPrice = $product->getOpenAmountMin(); + $minAmount = $coreHelper->currency($minPrice, true, false); + } else { + $minAmount = $minPrice = 0; + } + $openAmountNode->addAttribute('formatted_min_amount', $xmlModel->xmlAttribute($minAmount)); + $openAmountNode->addAttribute('min_amount', $minPrice); + + if ($priceModel->getMaxAmount($product)) { + $maxPrice = $product->getOpenAmountMax(); + $maxAmount = $coreHelper->currency($maxPrice, true, false); } else { - $openAmountNode->addAttribute('enabled', 0); + $maxAmount = $maxPrice = 0; } + $openAmountNode->addAttribute('formatted_max_amount', $xmlModel->xmlAttribute($maxAmount)); + $openAmountNode->addAttribute('max_amount', $maxPrice); + } else { + $openAmountNode->addAttribute('enabled', 0); } /** * Render Gift Card form options */ $form = $optionsXmlObj->addCustomChild('form', null, array( - 'name' => 'giftcard-send-form', - 'method' => 'post' - ) - ); + 'name' => 'giftcard-send-form', + 'method' => 'post' + )); $senderFieldset = $form->addCustomChild('fieldset', null, array( - 'legend' => $this->__('Sender Information') - ) - ); + 'legend' => $this->__('Sender Information') + )); $senderFieldset->addField('giftcard_sender_name', 'text', array( - 'label' => Mage::helper('enterprise_giftcard')->__('Sender Name'), - 'required' => 'true', - 'value' => $this->getSenderName() - ) - ); + 'label' => Mage::helper('enterprise_giftcard')->__('Sender Name'), + 'required' => 'true', + 'value' => $this->getSenderName() + )); $recipientFieldset = $form->addCustomChild('fieldset', null, array( - 'legend' => $this->__('Recipient Information') - ) - ); + 'legend' => $this->__('Recipient Information') + )); $recipientFieldset->addField('giftcard_recipient_name', 'text', array( - 'label' => Mage::helper('enterprise_giftcard')->__('Recipient Name'), - 'required' => 'true', - 'value' => $this->getDefaultValue('giftcard_recipient_name') - ) - ); + 'label' => Mage::helper('enterprise_giftcard')->__('Recipient Name'), + 'required' => 'true', + 'value' => $this->getDefaultValue('giftcard_recipient_name') + )); if ($this->isEmailAvailable($product)) { - $senderFieldset->addField('giftcard_sender_email', 'text', array( - 'label' => Mage::helper('enterprise_giftcard')->__('Sender Email'), - 'required' => 'true', - 'value' => $this->getSenderEmail() - ) - ); + $senderFieldset->addField('giftcard_sender_email', 'email', array( + 'label' => Mage::helper('enterprise_giftcard')->__('Sender Email'), + 'required' => 'true', + 'value' => $this->getSenderEmail() + )); - $recipientFieldset->addField('giftcard_recipient_email', 'text', array( - 'label' => Mage::helper('enterprise_giftcard')->__('Recipient Email'), - 'required' => 'true', - 'value' => $this->getDefaultValue('giftcard_recipient_email') - ) - ); + $recipientFieldset->addField('giftcard_recipient_email', 'email', array( + 'label' => Mage::helper('enterprise_giftcard')->__('Recipient Email'), + 'required' => 'true', + 'value' => $this->getDefaultValue('giftcard_recipient_email') + )); } if ($this->isMessageAvailable($product)) { $messageMaxLength = (int) Mage::getStoreConfig( Enterprise_GiftCard_Model_Giftcard::XML_PATH_MESSAGE_MAX_LENGTH ); - $recipientFieldset->addField('giftcard_message', 'text', array( - 'label' => Mage::helper('enterprise_giftcard')->__('Message'), - 'required' => 'false', - 'max_length'=> $messageMaxLength, - 'value' => $this->getDefaultValue('giftcard_message') - ) - ); + $recipientFieldset->addField('giftcard_message', 'textarea', array( + 'label' => Mage::helper('enterprise_giftcard')->__('Message'), + 'required' => 'false', + 'max_length'=> $messageMaxLength, + 'value' => $this->getDefaultValue('giftcard_message') + )); } - 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 02e095ab99..8c90bb5c32 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 @@ -59,6 +59,7 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj if (!sizeof($_associatedProducts)) { return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } + foreach ($_associatedProducts as $_item) { if (!$_item->isSaleable()) { continue; @@ -67,11 +68,10 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj $optionNode->addAttribute('code', 'super_group[' . $_item->getId() . ']'); $optionNode->addAttribute('type', 'product'); - $optionNode->addAttribute('label', $xmlModel->xmlentities(strip_tags($_item->getName()))); + $optionNode->addAttribute('label', $xmlModel->xmlentities($_item->getName())); $optionNode->addAttribute('is_qty_editable', 1); $optionNode->addAttribute('qty', $_item->getQty()*1); - /** * Process product price */ @@ -80,8 +80,9 @@ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObj } else { $productPrice = $_item->getPrice(); } - $productPrice = Mage::helper('xmlconnect')->formatPriceForXml($productPrice); - if ($productPrice != 0.00) { + + if ($productPrice != 0) { + $productPrice = Mage::helper('xmlconnect')->formatPriceForXml($productPrice); $optionNode->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml( Mage::helper('core')->currency($productPrice, false, false) )); 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 113b9b232c..a4e1d42e0e 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 @@ -27,11 +27,10 @@ /** * Simple product options xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - class Mage_XmlConnect_Block_Catalog_Product_Options_Simple extends Mage_XmlConnect_Block_Catalog_Product_Options { /** 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 d8cd010b93..8c6b189cd6 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 @@ -27,11 +27,10 @@ /** * Virtual product options xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - class Mage_XmlConnect_Block_Catalog_Product_Options_Virtual extends Mage_XmlConnect_Block_Catalog_Product_Options { /** diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php index caa49b80e1..7e8fca1128 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php @@ -25,7 +25,7 @@ */ /** - * Product Options xml renderer + * Product price xml renderer * * @category Mage * @package Mage_XmlConnect diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php index 5410ce54b1..d446da2754 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php @@ -27,11 +27,10 @@ /** * Bundle product price xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - class Mage_XmlConnect_Block_Catalog_Product_Price_Bundle extends Mage_Bundle_Block_Catalog_Product_Price { /** @@ -40,37 +39,34 @@ class Mage_XmlConnect_Block_Catalog_Product_Price_Bundle extends Mage_Bundle_Blo * @param Mage_Catalog_Model_Product $product * @param Mage_XmlConnect_Model_Simplexml_Element $item */ - public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_XmlConnect_Model_Simplexml_Element $item) - { - $this->setProduct($product) - ->setDisplayMinimalPrice(true) - ->setUseLinkForAsLowAs(false); + public function collectProductPrices( + Mage_Catalog_Model_Product $product, Mage_XmlConnect_Model_Simplexml_Element $item + ) { + $this->setProduct($product)->setDisplayMinimalPrice(true) ->setUseLinkForAsLowAs(false); $priceXmlObj = $item->addChild('price'); + /** @var $_coreHelper Mage_Core_Helper_Data */ $_coreHelper = $this->helper('core'); + /** @var $_weeeHelper Mage_Weee_Helper_Data */ $_weeeHelper = $this->helper('weee'); + /** @var $_taxHelper Mage_Tax_Helper_Data */ $_taxHelper = $this->helper('tax'); - /* @var $_coreHelper Mage_Core_Helper_Data */ - /* @var $_weeeHelper Mage_Weee_Helper_Data */ - /* @var $_taxHelper Mage_Tax_Helper_Data */ $_tierPrices = $this->_getTierPrices($product); if (count($_tierPrices) > 0) { $tierPricesTextArray = array(); foreach ($_tierPrices as $_price) { - $tierPricesTextArray[] = Mage::helper('catalog')->__('Buy %1$s with %2$s discount each', $_price['price_qty'], ' '.($_price['price']*1).'%'); + $discount = ' ' . ($_price['price'] * 1) . '%'; + $tierPricesTextArray[] = $this->__('Buy %1$s with %2$s discount each', $_price['price_qty'], $discount); } - $item->addChild('price_tier', implode("\n", $tierPricesTextArray)); + $item->addChild('price_tier', implode(PHP_EOL, $tierPricesTextArray)); } - list($_minimalPrice, $_maximalPrice) = $product->getPriceModel()->getPrices($product); - $_id = $product->getId(); $_weeeTaxAmount = 0; - $_minimalPriceTax = $_taxHelper->getPrice($product, $_minimalPrice); $_minimalPriceInclTax = $_taxHelper->getPrice($product, $_minimalPrice, true); @@ -84,15 +80,19 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $_minimalPriceInclTax += $_weeeTaxAmount; } - if ($_weeeHelper->typeOfDisplay($product, array(1,2,4))) { + if ($_weeeHelper->typeOfDisplay($product, array(1, 2, 4))) { $_weeeTaxAttributes = $_weeeHelper->getProductWeeeAttributesForDisplay($product); } } if ($product->getPriceView()) { if ($_taxHelper->displayBothPrices()) { - $priceXmlObj->addAttribute('as_low_as_excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false)); - if ($_weeeTaxAmount && $product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))) { + $priceXmlObj->addAttribute( + 'as_low_as_excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false) + ); + if ($_weeeTaxAmount && $product->getPriceType() == 1 + && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4)) + ) { $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); @@ -103,14 +103,24 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $amount = $_weeeTaxAttribute->getAmount(); } $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($amount, true, false) + ); } } - $priceXmlObj->addAttribute('as_low_as_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'as_low_as_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false) + ); } else { - $priceXmlObj->addAttribute('as_low_as', $_coreHelper->currency($_minimalPriceTax, true, false)); - if ($_weeeTaxAmount && $product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))) { + $priceXmlObj->addAttribute( + 'as_low_as', $_coreHelper->currency($_minimalPriceTax, true, false) + ); + if ($_weeeTaxAmount && $product->getPriceType() == 1 + && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4)) + ) { $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); @@ -121,12 +131,18 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $amount = $_weeeTaxAttribute->getAmount(); } $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($amount, true, false) + ); } } if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) { - $priceXmlObj->addAttribute('as_low_as_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'as_low_as_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false) + ); } } /** @@ -135,8 +151,12 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X } else { if ($_minimalPrice <> $_maximalPrice) { if ($_taxHelper->displayBothPrices()) { - $priceXmlObj->addAttribute('from_excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false)); - if ($_weeeTaxAmount && $product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))) { + $priceXmlObj->addAttribute( + 'from_excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false) + ); + if ($_weeeTaxAmount && $product->getPriceType() == 1 + && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4)) + ) { $weeeXmlObj = $priceXmlObj->addChild('from_weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); @@ -147,14 +167,22 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $amount = $_weeeTaxAttribute->getAmount(); } $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($amount, true, false) + ); } } - $priceXmlObj->addAttribute('from_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'from_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false) + ); } else { $priceXmlObj->addAttribute('from', $_coreHelper->currency($_minimalPriceTax, true, false)); - if ($_weeeTaxAmount && $product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))) { + if ($_weeeTaxAmount && $product->getPriceType() == 1 + && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4)) + ) { $weeeXmlObj = $priceXmlObj->addChild('from_weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); @@ -165,12 +193,16 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $amount = $_weeeTaxAttribute->getAmount(); } $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false)); } } if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) { - $priceXmlObj->addAttribute('from_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'from_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false) + ); } } @@ -188,8 +220,12 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X } if ($_taxHelper->displayBothPrices()) { - $priceXmlObj->addAttribute('to_excluding_tax', $_coreHelper->currency($_maximalPriceTax, true, false)); - if ($_weeeTaxAmount && $product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))) { + $priceXmlObj->addAttribute( + 'to_excluding_tax', $_coreHelper->currency($_maximalPriceTax, true, false) + ); + if ($_weeeTaxAmount && $product->getPriceType() == 1 + && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4)) + ) { $weeeXmlObj = $priceXmlObj->addChild('to_weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); @@ -200,14 +236,24 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $amount = $_weeeTaxAttribute->getAmount(); } $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($amount, true, false) + ); } } - $priceXmlObj->addAttribute('to_including_tax', $_coreHelper->currency($_maximalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'to_including_tax', $_coreHelper->currency($_maximalPriceInclTax, true, false) + ); } else { - $priceXmlObj->addAttribute('to', $_coreHelper->currency($_maximalPriceTax, true, false)); - if ($_weeeTaxAmount && $product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))) { + $priceXmlObj->addAttribute( + 'to', $_coreHelper->currency($_maximalPriceTax, true, false) + ); + if ($_weeeTaxAmount && $product->getPriceType() == 1 + && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4)) + ) { $weeeXmlObj = $priceXmlObj->addChild('to_weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); @@ -218,12 +264,18 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $amount = $_weeeTaxAttribute->getAmount(); } $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($amount, true, false) + ); } } if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) { - $priceXmlObj->addAttribute('to_including_tax', $_coreHelper->currency($_maximalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'to_including_tax', $_coreHelper->currency($_maximalPriceInclTax, true, false) + ); } } /** @@ -231,8 +283,12 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X */ } else { if ($_taxHelper->displayBothPrices()) { - $priceXmlObj->addAttribute('excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false)); - if ($_weeeTaxAmount && $product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))) { + $priceXmlObj->addAttribute( + 'excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false) + ); + if ($_weeeTaxAmount && $product->getPriceType() == 1 + && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4)) + ) { $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); @@ -243,14 +299,24 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $amount = $_weeeTaxAttribute->getAmount(); } $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($amount, true, false) + ); } } - $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false) + ); } else { - $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_minimalPriceTax, true, false)); - if ($_weeeTaxAmount && $product->getPriceType() == 1 && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))) { + $priceXmlObj->addAttribute( + 'regular', $_coreHelper->currency($_minimalPriceTax, true, false) + ); + if ($_weeeTaxAmount && $product->getPriceType() == 1 + && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4)) + ) { $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); @@ -261,12 +327,18 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $amount = $_weeeTaxAttribute->getAmount(); } $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($amount, true, false) + ); } } if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) { - $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false) + ); } } } @@ -290,15 +362,19 @@ protected function _getTierPrices($product) if (is_array($prices)) { foreach ($prices as $price) { $price['price_qty'] = $price['price_qty']*1; - $price['savePercent'] = ceil(100 - $price['price'] ); + $price['savePercent'] = ceil(100 - $price['price']); $price['formated_price'] = Mage::app()->getStore()->formatPrice( Mage::app()->getStore()->convertPrice( - Mage::helper('tax')->getPrice($product, $price['website_price'])), - false); + Mage::helper('tax')->getPrice($product, $price['website_price']) + ), + false + ); $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice( Mage::app()->getStore()->convertPrice( - Mage::helper('tax')->getPrice($product, $price['website_price'], true)), - false); + Mage::helper('tax')->getPrice($product, $price['website_price'], true) + ), + false + ); $res[] = $price; } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php index 63a44cffb8..33de63ad5d 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php @@ -27,11 +27,10 @@ /** * Default product price xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - class Mage_XmlConnect_Block_Catalog_Product_Price_Default extends Mage_Catalog_Block_Product_Price { /** @@ -40,37 +39,32 @@ class Mage_XmlConnect_Block_Catalog_Product_Price_Default extends Mage_Catalog_B * @param Mage_Catalog_Model_Product $product * @param Mage_XmlConnect_Model_Simplexml_Element $item */ - public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_XmlConnect_Model_Simplexml_Element $item) - { - $this->setProduct($product) - ->setDisplayMinimalPrice(true) - ->setUseLinkForAsLowAs(false); + public function collectProductPrices( + Mage_Catalog_Model_Product $product, Mage_XmlConnect_Model_Simplexml_Element $item + ) { + $this->setProduct($product)->setDisplayMinimalPrice(true)->setUseLinkForAsLowAs(false); $priceXmlObj = $item->addChild('price'); $_tierPrices = $this->_getTierPrices($product); if (count($_tierPrices) > 0) { - $tierPricesTextArray = array(); $tierPricesTextArray = $this->_getTierPricesTextArray($_tierPrices, $product); - $item->addChild('price_tier', implode("\n", $tierPricesTextArray)); + $item->addChild('price_tier', implode(PHP_EOL, $tierPricesTextArray)); } + /** @var $_coreHelper Mage_Core_Helper_Data */ $_coreHelper = $this->helper('core'); + /** @var $_weeeHelper Mage_Weee_Helper_Data */ $_weeeHelper = $this->helper('weee'); + /** @var $_taxHelper Mage_Tax_Helper_Data */ $_taxHelper = $this->helper('tax'); - /* @var $_coreHelper Mage_Core_Helper_Data */ - /* @var $_weeeHelper Mage_Weee_Helper_Data */ - /* @var $_taxHelper Mage_Tax_Helper_Data */ - - $_id = $product->getId(); - $_weeeSeparator = ''; $_simplePricesTax = ($_taxHelper->displayPriceIncludingTax() || $_taxHelper->displayBothPrices()); $_minimalPriceValue = $product->getMinimalPrice(); $_minimalPrice = $_taxHelper->getPrice($product, $_minimalPriceValue, $_simplePricesTax); if (!$product->isGrouped()) { $_weeeTaxAmount = $_weeeHelper->getAmountForDisplay($product); - if ($_weeeHelper->typeOfDisplay($product, array(1,2,4))) { + if ($_weeeHelper->typeOfDisplay($product, array(1, 2, 4))) { $_weeeTaxAmount = $_weeeHelper->getAmount($product); $_weeeTaxAttributes = $_weeeHelper->getProductWeeeAttributesForDisplay($product); } @@ -79,42 +73,62 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $_regularPrice = $_taxHelper->getPrice($product, $product->getPrice(), $_simplePricesTax); $_finalPrice = $_taxHelper->getPrice($product, $product->getFinalPrice()); $_finalPriceInclTax = $_taxHelper->getPrice($product, $product->getFinalPrice(), true); - $_weeeDisplayType = $_weeeHelper->getPriceDisplayType(); + $_weeeHelper->getPriceDisplayType(); if ($_finalPrice == $_price) { if ($_taxHelper->displayBothPrices()) { /** * Including */ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 0)) { - $priceXmlObj->addAttribute('excluding_tax', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)); - $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute( + 'excluding_tax', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false) + ); + $priceXmlObj->addAttribute( + 'including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false) + ); } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 1)) { /** * Including + Weee */ - $priceXmlObj->addAttribute('excluding_tax', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)); - $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute( + 'excluding_tax', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false) + ); + $priceXmlObj->addAttribute( + 'including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false) + ); $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false) + ); } } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 4)) { /** * Including + Weee */ - $priceXmlObj->addAttribute('excluding_tax', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)); - $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute( + 'excluding_tax', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false) + ); + $priceXmlObj->addAttribute( + 'including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false) + ); $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency( + $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(), true, false + )); } } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) { /** @@ -124,13 +138,21 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X $weeeXmlObj = $priceXmlObj->addChild('weee'); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false) + ); } - $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency( + $_finalPriceInclTax + $_weeeTaxAmount, true, false + )); } else { - $priceXmlObj->addAttribute('excluding_tax', $_coreHelper->currency($_price, true, false)); - $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency($_finalPriceInclTax, true, false)); + $priceXmlObj->addAttribute('excluding_tax', $_coreHelper->currency($_price, true, false)); + $priceXmlObj->addAttribute( + 'including_tax', $_coreHelper->currency($_finalPriceInclTax, true, false) + ); } /** * if ($_taxHelper->displayBothPrices()) { @@ -140,46 +162,67 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X * Including */ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 0)) { - $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('regular', $_coreHelper->currency( + $_price + $_weeeTaxAmount, true, false + )); } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 1)) { /** * Including + Weee */ - - $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('regular', $_coreHelper->currency( + $_price + $_weeeTaxAmount, true, false + )); $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false) + ); } } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 4)) { /** * Including + Weee */ - $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('regular', $_coreHelper->currency( + $_price + $_weeeTaxAmount, true, false + )); $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency( + $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(), true, false + )); } } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) { /** * Excluding + Weee + Final */ - $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_price, true, false)); + $priceXmlObj->addAttribute( + 'regular', $_coreHelper->currency($_price, true, false) + ); $weeeXmlObj = $priceXmlObj->addChild('weee'); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute( + 'amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false) + ); } - $priceXmlObj->addAttribute('including_tax', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute( + 'including_tax', $_coreHelper->currency($_price + $_weeeTaxAmount, true, false) + ); } else { $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_price, true, false)); } @@ -193,91 +236,143 @@ public function collectProductPrices(Mage_Catalog_Model_Product $product, Mage_X * Including */ if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 0)) { - $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_regularPrice + $_originalWeeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('regular', $_coreHelper->currency( + $_regularPrice + $_originalWeeeTaxAmount, true, false + )); if ($_taxHelper->displayBothPrices()) { - $priceXmlObj->addAttribute('special_excluding_tax', $_coreHelper->currency($_finalPrice + $_weeeTaxAmount, true, false)); - $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('special_excluding_tax', $_coreHelper->currency( + $_finalPrice + $_weeeTaxAmount, true, false + )); + $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency( + $_finalPriceInclTax + $_weeeTaxAmount, true, false + )); } else { - $priceXmlObj->addAttribute('special', $_coreHelper->currency($_finalPrice + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('special', $_coreHelper->currency( + $_finalPrice + $_weeeTaxAmount, true, false + )); } } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 1)) { /** * Including + Weee */ - $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_regularPrice + $_originalWeeeTaxAmount, true, false)); - $priceXmlObj->addAttribute('special_excluding_tax', $_coreHelper->currency($_finalPrice + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('regular', $_coreHelper->currency( + $_regularPrice + $_originalWeeeTaxAmount, true, false + )); + $priceXmlObj->addAttribute('special_excluding_tax', $_coreHelper->currency( + $_finalPrice + $_weeeTaxAmount, true, false + )); $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency( + $_weeeTaxAttribute->getAmount(), true, false + )); } - $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency( + $_finalPriceInclTax + $_weeeTaxAmount, true, false + )); } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 4)) { /** * Including + Weee */ - $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_regularPrice + $_originalWeeeTaxAmount, true, false)); - $priceXmlObj->addAttribute('special_excluding_tax', $_coreHelper->currency($_finalPrice + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('regular', $_coreHelper->currency( + $_regularPrice + $_originalWeeeTaxAmount, true, false + )); + $priceXmlObj->addAttribute('special_excluding_tax', $_coreHelper->currency( + $_finalPrice + $_weeeTaxAmount, true, false + )); $weeeXmlObj = $priceXmlObj->addChild('weee'); $_weeeSeparator = ' + '; $weeeXmlObj->addAttribute('separator', $_weeeSeparator); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency( + $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(), true, false + )); } - $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency( + $_finalPriceInclTax + $_weeeTaxAmount, true, false + )); } elseif ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) { /** * Excluding + Weee + Final */ $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_regularPrice, true, false)); - $priceXmlObj->addAttribute('special_excluding_tax', $_coreHelper->currency($_finalPrice, true, false)); + $priceXmlObj->addAttribute( + 'special_excluding_tax', $_coreHelper->currency($_finalPrice, true, false) + ); $weeeXmlObj = $priceXmlObj->addChild('weee'); foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) { $weeeItemXmlObj = $weeeXmlObj->addChild('item'); - $weeeItemXmlObj->addAttribute('name', $weeeItemXmlObj->xmlentities(strip_tags($_weeeTaxAttribute->getName()))); - $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($_weeeTaxAttribute->getAmount(), true, false)); + $weeeItemXmlObj->addAttribute( + 'name', $weeeItemXmlObj->xmlentities($_weeeTaxAttribute->getName()) + ); + $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency( + $_weeeTaxAttribute->getAmount(), true, false + )); } - $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency($_finalPriceInclTax + $_weeeTaxAmount, true, false)); + $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency( + $_finalPriceInclTax + $_weeeTaxAmount, true, false + )); } else { /** * Excluding */ $priceXmlObj->addAttribute('regular', $_coreHelper->currency($_regularPrice, true, false)); if ($_taxHelper->displayBothPrices()) { - $priceXmlObj->addAttribute('special_excluding_tax', $_coreHelper->currency($_finalPrice, true, false)); - $priceXmlObj->addAttribute('special_including_tax', $_coreHelper->currency($_finalPriceInclTax, true, false)); + $priceXmlObj->addAttribute( + 'special_excluding_tax', $_coreHelper->currency($_finalPrice, true, false) + ); + $priceXmlObj->addAttribute( + 'special_including_tax', $_coreHelper->currency($_finalPriceInclTax, true, false) + ); } else { - $priceXmlObj->addAttribute('special', $_coreHelper->currency($_finalPrice, true, false)); + $priceXmlObj->addAttribute( + 'special', $_coreHelper->currency($_finalPrice, true, false) + ); } } } - if ($this->getDisplayMinimalPrice() && $_minimalPriceValue && $_minimalPriceValue < $product->getFinalPrice()) { + if ($this->getDisplayMinimalPrice() + && $_minimalPriceValue + && $_minimalPriceValue < $product->getFinalPrice() + ) { $_minimalPriceDisplayValue = $_minimalPrice; + if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, array(0, 1, 4))) { $_minimalPriceDisplayValue = $_minimalPrice + $_weeeTaxAmount; } if (!$this->getUseLinkForAsLowAs()) { - $priceXmlObj->addAttribute('as_low_as', $_coreHelper->currency($_minimalPriceDisplayValue, true, false)); + $priceXmlObj->addAttribute('as_low_as', $_coreHelper->currency( + $_minimalPriceDisplayValue, true, false + )); } } /** * if (!$product->isGrouped()) { */ } else { - $_exclTax = $_taxHelper->getPrice($product, $_minimalPriceValue, $includingTax = null); - $_inclTax = $_taxHelper->getPrice($product, $_minimalPriceValue, $includingTax = true); + $_exclTax = $_taxHelper->getPrice($product, $_minimalPriceValue, null); + $_inclTax = $_taxHelper->getPrice($product, $_minimalPriceValue, true); if ($this->getDisplayMinimalPrice() && $_minimalPriceValue) { if ($_taxHelper->displayBothPrices()) { - $priceXmlObj->addAttribute('starting_at_excluding_tax', $_coreHelper->currency($_exclTax, true, false)); - $priceXmlObj->addAttribute('starting_at_including_tax', $_coreHelper->currency($_inclTax, true, false)); + $priceXmlObj->addAttribute('starting_at_excluding_tax', $_coreHelper->currency( + $_exclTax, true, false + )); + $priceXmlObj->addAttribute('starting_at_including_tax', $_coreHelper->currency( + $_inclTax, true, false + )); } else { $_showPrice = $_inclTax; if (!$_taxHelper->displayPriceIncludingTax()) { @@ -307,23 +402,42 @@ protected function _getTierPrices(Mage_Catalog_Model_Product $product) foreach ($prices as $price) { $price['price_qty'] = $price['price_qty']*1; if ($product->getPrice() != $product->getFinalPrice()) { - if ($price['price']<$product->getFinalPrice()) { - $price['savePercent'] = ceil(100 - (( 100/$product->getFinalPrice() ) * $price['price'] )); - $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'])), false); - $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true)), false); + if ($price['price'] < $product->getFinalPrice()) { + $price['savePercent'] = ceil(100 - ((100 / $product->getFinalPrice()) * $price['price'])); + $price['formated_price'] = Mage::app()->getStore()->formatPrice( + Mage::app()->getStore()->convertPrice( + Mage::helper('tax')->getPrice($product, $price['website_price']) + ), + false + ); + $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice( + Mage::app()->getStore()->convertPrice( + Mage::helper('tax')->getPrice($product, $price['website_price'], true) + ), + false + ); $res[] = $price; } } else { - if ($price['price']<$product->getPrice()) { - $price['savePercent'] = ceil(100 - (( 100/$product->getPrice() ) * $price['price'] )); - $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'])), false); - $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true)), false); + if ($price['price'] < $product->getPrice()) { + $price['savePercent'] = ceil(100 - ((100 / $product->getPrice()) * $price['price'])); + $price['formated_price'] = Mage::app()->getStore()->formatPrice( + Mage::app()->getStore()->convertPrice( + Mage::helper('tax')->getPrice($product, $price['website_price']) + ), + false + ); + $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice( + Mage::app()->getStore()->convertPrice( + Mage::helper('tax')->getPrice($product, $price['website_price'], true) + ), + false + ); $res[] = $price; } } } } - return $res; } @@ -332,12 +446,11 @@ protected function _getTierPrices(Mage_Catalog_Model_Product $product) * * @param array $_tierPrices * @param Mage_Catalog_Model_Product $_product - * + * * @return array */ protected function _getTierPricesTextArray($_tierPrices, $_product) { - $pricesArray = array(); if (Mage::helper('weee')->typeOfDisplay($_product, array(1, 2, 4))) { $_weeeTaxAttributes = Mage::helper('weee')->getProductWeeeAttributesForDisplay($_product); @@ -356,12 +469,11 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) } else if (Mage::helper('weee')->typeOfDisplay($_product, 1)) { $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']); if ($_weeeTaxAttributes) { - $s .= '('; - $s .= $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']); + $s .= '(' . $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']); $separator = ' + '; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $separator; - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount()); + $s .= $separator . $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency($_attribute->getAmount()); } $s .= ')'; } @@ -369,12 +481,13 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) } else if (Mage::helper('weee')->typeOfDisplay($_product, 4)) { $s .= $this->__('Buy %1$s for %2$s', $_price['price_qty'], $_price['formated_price_incl_weee_only']); if ($_weeeTaxAttributes) { - $s .= '('; - $s .= $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']); + $s .= '(' . $this->__('%1$s incl tax.', $_price['formated_price_incl_weee']); $separator = ' + '; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $separator; - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount() + $_attribute->getTaxAmount()); + $s .= $separator . $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency( + $_attribute->getAmount() + $_attribute->getTaxAmount() + ); } $s .= ')'; } @@ -384,10 +497,10 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) if ($_weeeTaxAttributes) { $s .= '('; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount()); + $s .= $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency($_attribute->getAmount()); } - $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']); - $s .= ')'; + $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']) . ')'; } $s .= $this->__('each'); } else { @@ -403,8 +516,8 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) $s .= '('; $separator = ''; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $separator; - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount()); + $s .= $separator . $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency($_attribute->getAmount()); $separator = ' + '; } $s .= ')'; @@ -416,8 +529,10 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) $s .= '('; $separator = ''; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $separator; - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount() + $_attribute->getTaxAmount()); + $s .= $separator . $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency( + $_attribute->getAmount() + $_attribute->getTaxAmount() + ); $separator = ' + '; } $s .= ')'; @@ -428,10 +543,10 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) if ($_weeeTaxAttributes) { $s .= '('; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount()); + $s .= $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency($_attribute->getAmount()); } - $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']); - $s .= ')'; + $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee']) . ')'; } $s .= $this->__('each'); } else { @@ -446,8 +561,8 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) $s .= '('; $separator = ''; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $separator; - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount()); + $s .= $separator . $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency($_attribute->getAmount()); $separator = ' + '; } $s .= ')'; @@ -459,8 +574,10 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) $s .= '('; $separator = ''; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $separator; - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount() + $_attribute->getTaxAmount()); + $s .= $separator . $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency( + $_attribute->getAmount() + $_attribute->getTaxAmount() + ); $separator = ' + '; } $s .= ')'; @@ -471,10 +588,10 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) if ($_weeeTaxAttributes) { $s .= '('; foreach ($_weeeTaxAttributes as $_attribute) { - $s .= $_attribute->getName() . ': ' . Mage::helper('core')->currency($_attribute->getAmount()); + $s .= $_attribute->getName() . ': '; + $s .= Mage::helper('core')->currency($_attribute->getAmount()); } - $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee_only']); - $s .= ')'; + $s .= $this->__('Total incl. Tax: %1$s', $_price['formated_price_incl_weee_only']) . ')'; } $s .= $this->__('each'); } else { @@ -483,8 +600,13 @@ protected function _getTierPricesTextArray($_tierPrices, $_product) } } if (!$_product->isGrouped()) { - if (($_product->getPrice() == $_product->getFinalPrice() && $_product->getPrice() > $_price['price']) - || ($_product->getPrice() != $_product->getFinalPrice() && $_product->getFinalPrice() > $_price['price'])) { + $condition1 = ($_product->getPrice() == $_product->getFinalPrice() + && $_product->getPrice() > $_price['price']); + + $condition2 = ($_product->getPrice() != $_product->getFinalPrice() + && $_product->getFinalPrice() > $_price['price']); + + if ($condition1 || $condition2) { $s .= ' ' . $this->__('and') . ' ' . $this->__('save') . ' ' . $_price['savePercent'] . '%'; } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php index 3219bf68ef..5924e86c9d 100755 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php @@ -27,9 +27,9 @@ /** * Giftcard product price xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Catalog_Product_Price_Giftcard extends Mage_Bundle_Block_Catalog_Product_Price { @@ -70,24 +70,19 @@ public function getMaxAmount($product = null) public function collectProductPrices( Mage_Catalog_Model_Product $product, Mage_XmlConnect_Model_Simplexml_Element $item - ) - { + ) { $this->setProduct($product); if ($product->getCanShowPrice() !== false) { $priceXmlObj = $item->addChild('price'); if (($_min = $this->getMinAmount()) && ($_max = $this->getMaxAmount()) && ($_min == $_max)) { - $priceXmlObj->addAttribute( - 'regular', - Mage::helper('core')->currency($_min, true, false) - ); + $priceXmlObj->addAttribute('regular', Mage::helper('core')->currency($_min, true, false)); } elseif (($_min = $this->getMinAmount()) && $_min != 0) { $priceXmlObj->addAttribute( 'regular', - Mage::helper('enterprise_giftcard')->__('From') - . ': ' - . Mage::helper('core')->currency($_min, true, false) + Mage::helper('enterprise_giftcard')->__('From') . ': ' + . Mage::helper('core')->currency($_min, true, false) ); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php index c57fb3adef..5a15f6d6a0 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php @@ -41,25 +41,56 @@ class Mage_XmlConnect_Block_Catalog_Product_Related extends Mage_XmlConnect_Bloc */ public function getRelatedProductsXmlObj() { + /** @var $relatedXmlObj Mage_XmlConnect_Model_Simplexml_Element */ $relatedXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); - if ($this->getParentBlock()->getProduct()->getId() > 0) { - $collection = $this->_getProductCollection(); - if (!$collection) { - return $relatedXmlObj; - } - foreach ($collection->getItems() as $product) { - $productXmlObj = $this->productToXmlObject($product); - if ($productXmlObj) { - if ($this->getParentBlock()->getChild('product_price')) { - $this->getParentBlock()->getChild('product_price')->setProduct($product) - ->setProductXmlObj($productXmlObj) - ->collectProductPrices(); - } - $relatedXmlObj->appendChild($productXmlObj); + + $productObj = $this->getParentBlock()->getProduct(); + + if (is_object(Mage::getConfig()->getNode('modules/Enterprise_TargetRule'))) { + Mage::register('product', $productObj); + + $productBlock = $this->getLayout()->addBlock( + 'enterprise_targetrule/catalog_product_list_related', 'relatedProducts' + ); + + $collection = $productBlock->getItemCollection(); + } else { + if ($productObj->getId() > 0) { + $collection = $this->_getProductCollection(); + if (!$collection) { + return $relatedXmlObj; } + $collection = $collection->getItems(); } } + $this->_addProductXmlObj($relatedXmlObj, $collection); + + return $relatedXmlObj; + } + + /** + * Add related products info to xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $relatedXmlObj + * @param array $collection + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + protected function _addProductXmlObj(Mage_XmlConnect_Model_Simplexml_Element $relatedXmlObj, $collection) + { + foreach ($collection as $product) { + $productXmlObj = $this->productToXmlObject($product); + + if (!$productXmlObj) { + continue; + } + + if ($this->getParentBlock()->getChild('product_price')) { + $this->getParentBlock()->getChild('product_price')->setProduct($product) + ->setProductXmlObj($productXmlObj)->collectProductPrices(); + } + $relatedXmlObj->appendChild($productXmlObj); + } return $relatedXmlObj; } @@ -87,7 +118,6 @@ protected function _getProductCollection() * Add rating and review summary, image attribute, apply sort params */ $this->_prepareCollection($collection); - $this->_productCollection = $collection; } return $this->_productCollection; 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 58f067be56..8b196ccbfb 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php @@ -52,8 +52,8 @@ public function reviewToXmlObject(Mage_Review_Model_Review $review, $itemNodeNam if ($review->getId()) { $item->addChild('review_id', $review->getId()); $item->addChild('created_at', $this->formatDate($review->getCreatedAt())); - $item->addChild('title', $item->xmlentities(strip_tags($review->getTitle()))); - $item->addChild('nickname', $item->xmlentities(strip_tags($review->getNickname()))); + $item->addChild('title', $item->xmlentities($review->getTitle())); + $item->addChild('nickname', $item->xmlentities($review->getNickname())); $detail = $item->xmlentities($review->getDetail()); if ($itemNodeName == 'item') { $remainder = ''; @@ -72,7 +72,6 @@ public function reviewToXmlObject(Mage_Review_Model_Review $review, $itemNodeNam if ($rating) { $item->addChild('rating_votes', $rating); } - } return $item; } @@ -87,5 +86,4 @@ protected function _toHtml() $review = Mage::getModel('review/review')->load((int)$this->getRequest()->getParam('id', 0)); return $this->reviewToXmlObject($review, 'review')->asNiceXml(); } - } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php index 03fe02756a..9ed4353766 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php @@ -48,7 +48,7 @@ class Mage_XmlConnect_Block_Catalog_Product_Review_List extends Mage_XmlConnect_ public function getReviewsXmlObject() { $reviewsXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); - $collection = $this->_getReviewCollection(); + $collection = $this->_getReviewCollection(); if (!$collection) { return $reviewsXmlObj; @@ -78,10 +78,8 @@ protected function _getReviewCollection() } /** @var $collection Mage_Review_Model_Mysql4_Review_Collection */ $collection = Mage::getResourceModel('review/review_collection') - ->addEntityFilter('product', $product->getId()) - ->addStoreFilter(Mage::app()->getStore()->getId()) - ->addStatusFilter('approved') - ->setDateOrder(); + ->addEntityFilter('product', $product->getId())->addStoreFilter(Mage::app()->getStore()->getId()) + ->addStatusFilter('approved')->setDateOrder(); /** * Apply offset and count @@ -110,5 +108,4 @@ protected function _toHtml() return $this->getReviewsXmlObject()->asNiceXml(); } - } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php index 10442d6177..a782092bbd 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php @@ -35,8 +35,8 @@ class Mage_XmlConnect_Block_Catalog_Search extends Mage_XmlConnect_Block_Catalog { /** * Search results xml renderer - * XML also contains filters that can be apply (accorfingly already applyed filters and search query) - * and sort fields + * XML also contains filters that can be apply (accorfingly already applyed filters + * and search query) and sort fields * * @return string */ @@ -48,15 +48,15 @@ protected function _toHtml() $helper = Mage::helper('catalogsearch'); if (method_exists($helper, 'getEngine')) { $engine = Mage::helper('catalogsearch')->getEngine(); - $isLayeredNavigationAllowed = ($engine instanceof Varien_Object) - ? $engine->isLeyeredNavigationAllowed() - : true; + if ($engine instanceof Varien_Object) { + $isLayeredNavigationAllowed = $engine->isLeyeredNavigationAllowed(); + } else { + $isLayeredNavigationAllowed = true; + } } else { $isLayeredNavigationAllowed = true; } - $request = $this->getRequest(); - $requestParams = $request->getParams(); $hasMoreProductItems = 0; /** @@ -66,8 +66,7 @@ protected function _toHtml() if ($productListBlock) { $layer = Mage::getSingleton('catalogsearch/layer'); $productsXmlObj = $productListBlock->setLayer($layer) - ->setNeedBlockApplyingFilters(!$isLayeredNavigationAllowed) - ->getProductsXmlObject(); + ->setNeedBlockApplyingFilters(!$isLayeredNavigationAllowed)->getProductsXmlObject(); $searchXmlObject->appendChild($productsXmlObj); $hasMoreProductItems = (int)$productListBlock->getHasProductItems(); } @@ -78,10 +77,11 @@ protected function _toHtml() * Filters */ $showFiltersAndOrders = (bool) count($productsXmlObj); - $reguest = $this->getRequest(); - foreach ($reguest->getParams() as $key => $value) { - if (0 === strpos($key, parent::REQUEST_SORT_ORDER_PARAM_REFIX) || - 0 === strpos($key, parent::REQUEST_FILTER_PARAM_REFIX)) { + $requestParams = $this->getRequest()->getParams(); + foreach ($requestParams as $key => $value) { + if (0 === strpos($key, parent::REQUEST_SORT_ORDER_PARAM_REFIX) + || 0 === strpos($key, parent::REQUEST_FILTER_PARAM_REFIX) + ) { $showFiltersAndOrders = false; break; } @@ -107,7 +107,9 @@ protected function _toHtml() } $value = $values->addChild('value'); $value->addChild('id', $valueItem->getValueString()); - $value->addChild('label', $searchXmlObject->xmlentities(strip_tags($valueItem->getLabel()))); + $value->addChild( + 'label', $searchXmlObject->xmlentities(strip_tags($valueItem->getLabel())) + ); $value->addChild('count', $count); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php index b57cd4bc20..d35c133214 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php @@ -33,6 +33,9 @@ */ class Mage_XmlConnect_Block_Catalog_Search_Suggest extends Mage_CatalogSearch_Block_Autocomplete { + /** + * Suggest item separator + */ const SUGGEST_ITEM_SEPARATOR = '::sep::'; /** @@ -49,16 +52,14 @@ protected function _toHtml() } $suggestData = $this->getSuggestData(); - if (!($count = count($suggestData))) { + if (!count($suggestData)) { return $suggestXmlObj->asNiceXml(); } $items = ''; foreach ($suggestData as $item) { - $items .= $suggestXmlObj->xmlentities(strip_tags($item['title'])) - . self::SUGGEST_ITEM_SEPARATOR - . (int)$item['num_of_results'] - . self::SUGGEST_ITEM_SEPARATOR; + $items .= $suggestXmlObj->xmlentities(strip_tags($item['title'])) . self::SUGGEST_ITEM_SEPARATOR + . (int)$item['num_of_results'] . self::SUGGEST_ITEM_SEPARATOR; } $suggestXmlObj = Mage::getModel('xmlconnect/simplexml_element', '' . $items . ''); diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php index 81b4c065bd..8d5b5c7b7e 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php @@ -54,7 +54,9 @@ protected function _toHtml() $item->addAttribute('selected', 1); } $this->getChild('address_list')->prepareAddressData($address, $item); - $item->addChild('address_line', $billingXmlObj->xmlentities($address->format('oneline'))); + $item->addChild( + 'address_line', $billingXmlObj->xmlentities($address->format('oneline')) + ); } return $billingXmlObj->asNiceXml(); 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 3ced72cc06..8e1cc2d555 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php @@ -27,9 +27,9 @@ /** * Customer address form xml renderer for onepage checkout * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Checkout_Address_Form extends Mage_Core_Block_Template { @@ -45,81 +45,68 @@ protected function _toHtml() $xmlModel->addAttribute('name', 'address_form'); $xmlModel->addAttribute('method', 'post'); - if ($this->getType() == 'shipping' || $this->getType() == 'billing') { - $addressType = $this->getType(); - } else { + $addressType = $this->getType(); + if (!$addressType) { $addressType = 'billing'; } - $isAllowedGuestCheckout = Mage::getSingleton('checkout/session') - ->getQuote() - ->isAllowedGuestCheckout(); + $isAllowedGuestCheckout = Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout(); $countries = $this->_getCountryOptions(); - $xmlModel->addField($addressType.'[firstname]', 'text', array( - 'label' => $this->__('First Name'), - 'required' => 'true', - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[lastname]', 'text', array( - 'label' => $this->__('Last Name'), - 'required' => 'true', - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[company]', 'text', array( - 'label' => $this->__('Company'), - 'required' => 'true', - 'value' => '' - ) - ); - - if ($isAllowedGuestCheckout - && !Mage::getSingleton('customer/session')->isLoggedIn() + $xmlModel->addField($addressType . '[firstname]', 'text', array( + 'label' => $this->__('First Name'), + 'required' => 'true', + 'value' => '' + )); + + $xmlModel->addField($addressType . '[lastname]', 'text', array( + 'label' => $this->__('Last Name'), + 'required' => 'true', + 'value' => '' + )); + + $xmlModel->addField($addressType . '[company]', 'text', array( + 'label' => $this->__('Company'), + 'required' => 'true', + 'value' => '' + )); + + if ($isAllowedGuestCheckout && !Mage::getSingleton('customer/session')->isLoggedIn() && $addressType == 'billing' ) { - $emailField = $xmlModel->addField($addressType.'[email]', 'text', array( - 'label' => $this->__('Email Address'), - 'required' => 'true', - 'value' => '' - ) - ); + $emailField = $xmlModel->addField($addressType . '[email]', 'text', array( + 'label' => $this->__('Email Address'), + 'required' => 'true', + 'value' => '' + )); $emailValidator = $emailField->addChild('validators')->addChild('validator'); $emailValidator->addAttribute('type', 'email'); $emailValidator->addAttribute('message', $this->__('Wrong email format')); } - $xmlModel->addField($addressType.'[street][]', 'text', array( - 'label' => $this->__('Address'), - 'required' => 'true', - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[street][]', 'text', array( - 'label' => $this->__('Address 2'), - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[city]', 'text', array( - 'label' => $this->__('City'), - 'required' => 'true', - 'value' => '' - ) - ); - - $countryOptionsXml = $xmlModel->addField($addressType.'[country_id]', 'select', array( - 'label' => $this->__('Country'), - 'required' => 'true', - 'value' => '' - ) - ) - ->addChild('values'); + $xmlModel->addField($addressType . '[street][]', 'text', array( + 'label' => $this->__('Address'), + 'required' => 'true', + 'value' => '' + )); + + $xmlModel->addField($addressType . '[street][]', 'text', array( + 'label' => $this->__('Address 2'), + 'value' => '' + )); + + $xmlModel->addField($addressType . '[city]', 'text', array( + 'label' => $this->__('City'), + 'required' => 'true', + 'value' => '' + )); + + $countryOptionsXml = $xmlModel->addField($addressType . '[country_id]', 'select', array( + 'label' => $this->__('Country'), + 'required' => 'true', + 'value' => '' + ))->addChild('values'); foreach ($countries as $data) { $regions = array(); @@ -130,15 +117,11 @@ protected function _toHtml() $regionStr = (!empty($regions) ? 'region_id' : 'region'); - $countryXml = $countryOptionsXml->addCustomChild('item', null, array( - 'relation' => $regionStr - ) - ); + $countryXml = $countryOptionsXml->addCustomChild('item', null, array('relation' => $regionStr)); $countryXml->addCustomChild('label', (string)$data['label']); $countryXml->addCustomChild('value', (string)$data['value']); if (!empty($regions)) { $regionXml = $countryXml->addChild('regions'); - foreach ($regions as $_data) { $regionItemXml = $regionXml->addChild('region_item'); $regionItemXml->addCustomChild('label', (string)$_data['label']); @@ -147,43 +130,37 @@ protected function _toHtml() } } - $xmlModel->addField($addressType.'[region]', 'text', array( - 'label' => $this->__('State/Province'), - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[region_id]', 'select', array( - 'label' => $this->__('State/Province'), - 'required' => 'true', - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[postcode]', 'text', array( - 'label' => $this->__('Zip/Postal Code'), - 'required' => 'true', - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[telephone]', 'text', array( - 'label' => $this->__('Telephone'), - 'required' => 'true', - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[fax]', 'text', array( - 'label' => $this->__('Fax'), - 'value' => '' - ) - ); - - $xmlModel->addField($addressType.'[save_in_address_book]', 'checkbox', array( - 'label' => $this->__('Save in address book'), - ) - ); + $xmlModel->addField($addressType . '[region]', 'text', array( + 'label' => $this->__('State/Province'), + 'value' => '' + )); + + $xmlModel->addField($addressType . '[region_id]', 'select', array( + 'label' => $this->__('State/Province'), + 'required' => 'true', + 'value' => '' + )); + + $xmlModel->addField($addressType . '[postcode]', 'text', array( + 'label' => $this->__('Zip/Postal Code'), + 'required' => 'true', + 'value' => '' + )); + + $xmlModel->addField($addressType . '[telephone]', 'text', array( + 'label' => $this->__('Telephone'), + 'required' => 'true', + 'value' => '' + )); + + $xmlModel->addField($addressType . '[fax]', 'text', array( + 'label' => $this->__('Fax'), + 'value' => '' + )); + + $xmlModel->addField($addressType . '[save_in_address_book]', 'checkbox', array( + 'label' => $this->__('Save in address book'), + )); return $xmlModel->asNiceXml(); } @@ -196,12 +173,12 @@ protected function _toHtml() */ protected function _getRegionOptions($countryId) { - $cacheKey = 'DIRECTORY_REGION_SELECT_STORE'.Mage::app()->getStore()->getId().$countryId; - if (Mage::app()->useCache('config') && $cache = Mage::app()->loadCache($cacheKey)) { + $cacheKey = 'DIRECTORY_REGION_SELECT_STORE' . Mage::app()->getStore()->getId() . $countryId; + $cache = Mage::app()->loadCache($cacheKey); + if (Mage::app()->useCache('config') && $cache) { $options = unserialize($cache); } else { - $collection = Mage::getModel('directory/region')->getResourceCollection() - ->addCountryFilter($countryId) + $collection = Mage::getModel('directory/region')->getResourceCollection()->addCountryFilter($countryId) ->load(); $options = $collection->toOptionArray(); if (Mage::app()->useCache('config')) { @@ -218,13 +195,13 @@ protected function _getRegionOptions($countryId) */ protected function _getCountryOptions() { - $cacheKey = 'DIRECTORY_COUNTRY_SELECT_STORE_'.Mage::app()->getStore()->getCode(); - if (Mage::app()->useCache('config') && $cache = Mage::app()->loadCache($cacheKey)) { + $cacheKey = 'DIRECTORY_COUNTRY_SELECT_STORE_' . Mage::app()->getStore()->getCode(); + $cache = Mage::app()->loadCache($cacheKey); + if (Mage::app()->useCache('config') && $cache) { $options = unserialize($cache); } else { /** @var $collection Mage_Directory_Model_Mysql4_Country_Collection */ - $collection = Mage::getModel('directory/country')->getResourceCollection() - ->loadByStore(); + $collection = Mage::getModel('directory/country')->getResourceCollection()->loadByStore(); $options = $collection->toOptionArray(false); if (Mage::app()->useCache('config')) { Mage::app()->saveCache(serialize($options), $cacheKey, array('config')); diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php index ae42a039b9..c5f667e6d9 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php @@ -48,7 +48,7 @@ protected function _toHtml() if (!$agreement->getIsHtml()) { $content = nl2br(strip_tags($content)); } - $agreementText = $agreementsXmlObj->xmlentities(strip_tags($agreement->getCheckboxText())); + $agreementText = $agreementsXmlObj->xmlentities($agreement->getCheckboxText()); $itemXmlObj->addChild('label', $agreementText); $itemXmlObj->addChild('content', $content); $itemXmlObj->addChild('code', 'agreement[' . $agreement->getId() . ']'); 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 543718ecd6..cab02fc13b 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 @@ -55,7 +55,7 @@ protected function _toHtml() $itemXml->addChild('entity_id', $item->getProduct()->getId()); $itemXml->addChild('entity_type', $type); $itemXml->addChild('item_id', $item->getId()); - $itemXml->addChild('name', $itemsXmlObj->xmlentities(strip_tags($renderer->getProductName()))); + $itemXml->addChild('name', $itemsXmlObj->xmlentities($renderer->getProductName())); $itemXml->addChild('qty', $renderer->getQty()); $icon = $renderer->getProductThumbnail()->resize( Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small') @@ -73,8 +73,7 @@ protected function _toHtml() if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { $typeOfDisplay = Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales'); if ($typeOfDisplay && $item->getWeeeTaxAppliedAmount()) { - $exclPrice = $item->getCalculationPrice() - + $item->getWeeeTaxAppliedAmount() + $exclPrice = $item->getCalculationPrice() + $item->getWeeeTaxAppliedAmount() + $item->getWeeeTaxDisposition(); } else { $exclPrice = $item->getCalculationPrice(); @@ -92,28 +91,28 @@ protected function _toHtml() } $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); - $formatedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); + $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); - $formatedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); + $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); $priceXmlObj = $itemXml->addChild('price'); - $formatedPriceXmlObj = $itemXml->addChild('formated_price'); + $formattedPriceXmlObj = $itemXml->addChild('formated_price'); if ($this->helper('tax')->displayCartBothPrices()) { $priceXmlObj->addAttribute('excluding_tax', $exclPrice); $priceXmlObj->addAttribute('including_tax', $inclPrice); - $formatedPriceXmlObj->addAttribute('excluding_tax', $formatedExclPrice); - $formatedPriceXmlObj->addAttribute('including_tax', $formatedInclPrice); + $formattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice); + $formattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice); } else { if ($this->helper('tax')->displayCartPriceExclTax()) { $priceXmlObj->addAttribute('regular', $exclPrice); - $formatedPriceXmlObj->addAttribute('regular', $formatedExclPrice); + $formattedPriceXmlObj->addAttribute('regular', $formattedExclPrice); } if ($this->helper('tax')->displayCartPriceInclTax()) { $priceXmlObj->addAttribute('regular', $inclPrice); - $formatedPriceXmlObj->addAttribute('regular', $formatedInclPrice); + $formattedPriceXmlObj->addAttribute('regular', $formattedInclPrice); } } @@ -124,8 +123,7 @@ protected function _toHtml() if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { $typeOfDisplay = Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales'); if ($typeOfDisplay && $item->getWeeeTaxAppliedAmount()) { - $exclPrice = $item->getRowTotal() - + $item->getWeeeTaxAppliedRowAmount() + $exclPrice = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount() + $item->getWeeeTaxRowDisposition(); } else { $exclPrice = $item->getRowTotal(); @@ -143,28 +141,28 @@ protected function _toHtml() } $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); - $formatedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); + $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); - $formatedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); + $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); $subtotalPriceXmlObj = $itemXml->addChild('subtotal'); - $subtotalFormatedPriceXmlObj = $itemXml->addChild('formated_subtotal'); + $subtotalFormattedPriceXmlObj = $itemXml->addChild('formated_subtotal'); if ($this->helper('tax')->displayCartBothPrices()) { $subtotalPriceXmlObj->addAttribute('excluding_tax', $exclPrice); $subtotalPriceXmlObj->addAttribute('including_tax', $inclPrice); - $subtotalFormatedPriceXmlObj->addAttribute('excluding_tax', $formatedExclPrice); - $subtotalFormatedPriceXmlObj->addAttribute('including_tax', $formatedInclPrice); + $subtotalFormattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice); + $subtotalFormattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice); } else { if ($this->helper('tax')->displayCartPriceExclTax()) { $subtotalPriceXmlObj->addAttribute('regular', $exclPrice); - $subtotalFormatedPriceXmlObj->addAttribute('regular', $formatedExclPrice); + $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedExclPrice); } if ($this->helper('tax')->displayCartPriceInclTax()) { $subtotalPriceXmlObj->addAttribute('regular', $inclPrice); - $subtotalFormatedPriceXmlObj->addAttribute('regular', $formatedInclPrice); + $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedInclPrice); } } @@ -174,16 +172,14 @@ protected function _toHtml() if ($_options = $renderer->getOptionList()) { $itemOptionsXml = $itemXml->addChild('options'); foreach ($_options as $_option) { - $_formatedOptionValue = $renderer->getFormatedOptionValue($_option); + $_formattedOptionValue = $renderer->getFormatedOptionValue($_option); $optionXml = $itemOptionsXml->addChild('option'); - $labelValue = $itemsXmlObj->xmlentities(strip_tags($_option['label'])); + $labelValue = $itemsXmlObj->xmlentities($_option['label']); $optionXml->addAttribute('label', $labelValue); - $textValue = $itemsXmlObj->xmlentities(strip_tags($_formatedOptionValue['value'])); + $textValue = $itemsXmlObj->xmlentities( + strip_tags($_formattedOptionValue['value']) + ); $optionXml->addAttribute('text', $textValue); -// if (isset($_formatedOptionValue['full_view'])) { -// $label = strip_tags($_option['label']); -// $value = strip_tags($_formatedOptionValue['full_view']); -// } } } } diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php index 01684092f3..11a06acec3 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php @@ -87,7 +87,7 @@ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $ $cvnText = $this->__('Card Verification Number'); $cvnValidationText = $this->__('Card verification number is wrong'); $verification = - ' + ' @@ -98,29 +98,29 @@ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $ $expMonthText = $this->__('Expiration Date - Month'); $expYearText = $this->__('Expiration Date - Year'); $xml = << - - - {$ccTypes} - - - - - - - - - - {$ccMonths} - - - - - {$ccYears} - - - {$verification} - +
+ + + {$ccTypes} + + + + + + + + + + {$ccMonths} + + + + + {$ccYears} + + + {$verification} +
EOT; $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml); $formXmlObj->appendChild($fieldsetXmlObj); diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php index c5c6032fbd..937646312f 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php @@ -27,9 +27,9 @@ /** * Check / Money order Payment method xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Checkout_Payment_Method_Checkmo extends Mage_Payment_Block_Form_Checkmo { diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Authorizenet.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Authorizenet.php index 993d574675..5cc6f656f6 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Authorizenet.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Authorizenet.php @@ -31,8 +31,7 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet - extends Mage_Paygate_Block_Authorizenet_Info_Cc +class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet extends Mage_Paygate_Block_Authorizenet_Info_Cc { /** * Add Authorizenet info to order XML object @@ -44,31 +43,20 @@ public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $ { $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode()); if (!$this->getHideTitle()) { - $orderItemXmlObj->addAttribute( - 'title', - $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle()) - ); + $orderItemXmlObj->addAttribute('title', $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())); } $cards = $this->getCards(); $showCount = count($cards) > 1; foreach ($cards as $key => $card) { - $creditCard = $orderItemXmlObj->addCustomChild( - 'item', - null, - array( - 'label' => $showCount ? $this->__('Credit Card %s', $key + 1) : $this->__('Credit Card') - ) - ); + $creditCard = $orderItemXmlObj->addCustomChild('item', null, array( + 'label' => $showCount ? $this->__('Credit Card %s', $key + 1) : $this->__('Credit Card') + )); foreach ($card as $label => $value) { - $creditCard->addCustomChild( - 'item', - implode($this->getValueAsArray($value, true), PHP_EOL), - array( - 'label' => $label - ) - ); + $creditCard->addCustomChild('item', implode($this->getValueAsArray($value, true), '\n'), array( + 'label' => $label + )); } } } diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Ccsave.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Ccsave.php index e8264a56a6..5b49907254 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Ccsave.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Ccsave.php @@ -42,20 +42,13 @@ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Ccsave extends Mage_Pay public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) { $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode()); - $orderItemXmlObj->addAttribute( - 'title', - $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle()) - ); + $orderItemXmlObj->addAttribute('title', $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())); if ($_specificInfo = $this->getSpecificInformation()) { foreach ($_specificInfo as $label => $value) { - $orderItemXmlObj->addCustomChild( - 'item', - implode($this->getValueAsArray($value, true), PHP_EOL), - array( - 'label' => $label - ) - ); + $orderItemXmlObj->addCustomChild('item', implode($this->getValueAsArray($value, true), '\n'), array( + 'label' => $label + )); } } } diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Checkmo.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Checkmo.php index c7984ea6df..71527a7105 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Checkmo.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Checkmo.php @@ -43,28 +43,19 @@ public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $ { $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode()); $orderItemXmlObj->addAttribute( - 'title', - $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle()) + 'title', $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle()) ); if ($this->getInfo()->getAdditionalData()) { if ($this->getPayableTo()) { - $orderItemXmlObj->addCustomChild( - 'item', - $this->getPayableTo(), - array( - 'label' => Mage::helper('sales')->__('Make Check payable to:') - ) - ); + $orderItemXmlObj->addCustomChild('item', $this->getPayableTo(), array( + 'label' => Mage::helper('sales')->__('Make Check payable to:') + )); } if ($this->getMailingAddress()) { - $orderItemXmlObj->addCustomChild( - 'item', - $this->getMailingAddress(), - array( - 'label' => Mage::helper('payment')->__('Send Check to:') - ) - ); + $orderItemXmlObj->addCustomChild('item', $this->getMailingAddress(), array( + 'label' => Mage::helper('payment')->__('Send Check to:') + )); } } } diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Free.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Free.php new file mode 100644 index 0000000000..82a9ec85eb --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Free.php @@ -0,0 +1,47 @@ + + */ +class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Free extends Mage_Payment_Block_Info +{ + /** + * Add Check / Money order info to order XML object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) + { + $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode()); + $orderItemXmlObj->addAttribute('title', $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Abstract.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Abstract.php new file mode 100644 index 0000000000..807ef7d069 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Abstract.php @@ -0,0 +1,58 @@ + + */ +abstract class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract + extends Mage_Paypal_Block_Payment_Info +{ + /** + * Add CC Save Payment info to order XML object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) + { + $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode()); + $orderItemXmlObj->addAttribute( + 'title', $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle()) + ); + + if ($_specificInfo = $this->getSpecificInformation()) { + foreach ($_specificInfo as $label => $value) { + $orderItemXmlObj->addCustomChild('item', implode($this->getValueAsArray($value, true), '\n'), array( + 'label' => $label + )); + } + } + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Express.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Express.php new file mode 100644 index 0000000000..1979debbd7 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Express.php @@ -0,0 +1,37 @@ + + */ +class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Express + extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract +{ +} diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Mecl.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Mecl.php new file mode 100644 index 0000000000..ea2eec0dbb --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Paypal/Mecl.php @@ -0,0 +1,37 @@ + + */ +class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Mecl + extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract +{ +} diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Authorizenet.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Authorizenet.php new file mode 100644 index 0000000000..d0f6362706 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Authorizenet.php @@ -0,0 +1,37 @@ + + */ +class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Authorizenet + extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet +{ +} diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypal/Direct.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypal/Direct.php new file mode 100644 index 0000000000..dd5080b97f --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypal/Direct.php @@ -0,0 +1,37 @@ + + */ +class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Paypal_Direct + extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract +{ +} diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypaluk/Direct.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypaluk/Direct.php new file mode 100644 index 0000000000..3b885046dc --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Paypaluk/Direct.php @@ -0,0 +1,37 @@ + + */ +class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Paypaluk_Direct + extends Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract +{ +} diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Verisign.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Verisign.php new file mode 100644 index 0000000000..d614df0d69 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Pbridge/Verisign.php @@ -0,0 +1,57 @@ + + */ +class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Verisign extends Mage_Payment_Block_Info_Cc +{ + /** + * Add CC Save Payment info to order XML object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) + { + $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode()); + $orderItemXmlObj->addAttribute( + 'title', $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle()) + ); + + if ($_specificInfo = $this->getSpecificInformation()) { + foreach ($_specificInfo as $label => $value) { + $orderItemXmlObj->addCustomChild('item', implode($this->getValueAsArray($value, true), '\n'), array( + 'label' => $label + )); + } + } + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Purchaseorder.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Purchaseorder.php index f2b9c038cb..b238223924 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Purchaseorder.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Info/Purchaseorder.php @@ -42,17 +42,10 @@ class Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Purchaseorder extends M public function addPaymentInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) { $orderItemXmlObj->addAttribute('type', $this->getMethod()->getCode()); - $orderItemXmlObj->addAttribute( - 'title', - $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle()) - ); + $orderItemXmlObj->addAttribute('title', $orderItemXmlObj->xmlAttribute($this->getMethod()->getTitle())); - $orderItemXmlObj->addCustomChild( - 'item', - $this->getInfo()->getPoNumber(), - array( - 'label' => Mage::helper('sales')->__('Purchase Order Number:') - ) - ); + $orderItemXmlObj->addCustomChild('item', $this->getInfo()->getPoNumber(), array( + 'label' => Mage::helper('sales')->__('Purchase Order Number:') + )); } } 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 ffda4976be..36c201aa5d 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 @@ -33,6 +33,32 @@ */ class Mage_XmlConnect_Block_Checkout_Payment_Method_List extends Mage_Payment_Block_Form_Container { + /** + * Pre-defined array of methods that we are going to render + * + * @var array + */ + protected $_methodArray = array( + 'payment_ccsave' => 'Mage_Payment_Model_Method_Cc', + 'payment_checkmo' => 'Mage_Payment_Model_Method_Checkmo', + 'payment_purchaseorder' => 'Mage_Payment_Model_Method_Purchaseorder', + ); + + /** + * Payment bridge methods array + * + * Core block renderer by method code + * - 'pbridge_authorizenet' => 'Enterprise_Pbridge_Model_Payment_Method_Authorizenet', + * - 'pbridge_paypal' => 'Enterprise_Pbridge_Model_Payment_Method_Paypal', + * - 'pbridge_verisign' => 'Enterprise_Pbridge_Model_Payment_Method_Payflow_Pro', + * - 'pbridge_paypaluk' => 'Enterprise_Pbridge_Model_Payment_Method_Paypaluk', + * + * @var array + */ + protected $_pbridgeMethodArray = array( + 'pbridge_authorizenet', 'pbridge_paypal', 'pbridge_verisign', 'pbridge_paypaluk' + ); + /** * Prevent parent set children * @@ -54,54 +80,128 @@ public function getQuote() } /** - * Render payment methods xml + * Add customer balance details to XML object * - * @return string - * @throw Mage_Core_Exception + * @param Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj */ - protected function _toHtml() + public function addCustomerBalanceToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj) { - /** @var $methodsXmlObj Mage_XmlConnect_Model_Simplexml_Element */ - $methodsXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); + /** @var $customerBalanceBlock Enterprise_CustomerBalance_Block_Checkout_Onepage_Payment_Additional */ + $customerBalanceBlock = $this->getLayout() + ->addBlock('enterprise_customerbalance/checkout_onepage_payment_additional', 'customer_balance'); + $storeCreditFlag = (int) Mage::getStoreConfig(Enterprise_CustomerBalance_Helper_Data::XML_PATH_ENABLED); + if ($storeCreditFlag && $customerBalanceBlock->isDisplayContainer()) { + $balance = $this->getQuote()->getStore()->formatPrice($customerBalanceBlock->getBalance(), false); + $methodsXmlObj->addCustomChild('customer_balance', null, array( + 'post_name' => 'payment[use_customer_balance]', + 'code' => 1, + 'label' => $this->__('Use Store Credit (%s available)', $balance), + 'is_cover_a_quote' => intval($customerBalanceBlock->isFullyPaidAfterApplication()), + 'selected' => intval($customerBalanceBlock->isCustomerBalanceUsed()) + )); + } + } - /** - * Pre-defined array of methods that we are going to render - */ - $methodArray = array( - 'payment_ccsave' => 'Mage_Payment_Model_Method_Cc', - 'payment_checkmo' => 'Mage_Payment_Model_Method_Checkmo', - 'payment_purchaseorder' => 'Mage_Payment_Model_Method_Purchaseorder', + /** + * Add gift card details to XML object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj + */ + public function addGiftcardToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $methodsXmlObj) + { + $giftcardInfoBlock = $this->getLayout()->addBlock( + 'enterprise_giftcardaccount/checkout_onepage_payment_additional', 'giftcard_info' ); + if (intval($giftcardInfoBlock->getAppliedGiftCardAmount())) { + $amount = $this->getQuote()->getStore()->formatPrice($giftcardInfoBlock->getAppliedGiftCardAmount(), false); + $amount = $this->__('Gift Card amount applied to order: %s', $amount); + + $methodsXmlObj->addCustomChild('information', null, array('label' => $amount, 'disabled' => '1')); + + if ($this->_isPaymentRequired()) { + $methodsXmlObj->addCustomChild('method', null, array( + 'post_name' => 'payment[method]', + 'code' => 'free', + 'label' => $this->__('No Payment Information Required'), + 'selected' => '1', + 'disabled' => '1' + )); + } + $this->setIsUsedGiftCard(true); + } + } + + /** + * Check is payment required for a quote + * + * @return bool + */ + protected function _isPaymentRequired() + { + $this->getQuote()->collectTotals(); + return !intval($this->getQuote()->getGrandTotal()) && !$this->getQuote()->hasNominalItems(); + } + + /** + * Get payment methods array as code => renderer and set payment blocks to layout + * + * @return array + */ + protected function _getPaymentMethodArray() + { + $methodArray = $this->_methodArray; + /** * Check is available Payment Bridge and add methods for rendering */ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_Pbridge'))) { - $pbridgeMethodArray = array( - 'pbridge_authorizenet' => 'Enterprise_Pbridge_Model_Payment_Method_Authorizenet', - 'pbridge_paypal' => 'Enterprise_Pbridge_Model_Payment_Method_Paypal', - 'pbridge_verisign' => 'Enterprise_Pbridge_Model_Payment_Method_Payflow_Pro', - 'pbridge_paypaluk' => 'Enterprise_Pbridge_Model_Payment_Method_Paypaluk', - ); $pbBlockRenderer = 'xmlconnect/checkout_payment_method_'; $pbBlockName = 'xmlconnect.checkout.payment.method.'; - foreach ($pbridgeMethodArray as $block => $class) { + foreach ($this->_pbridgeMethodArray as $block) { $currentBlockRenderer = $pbBlockRenderer . $block; $currentBlockName = $pbBlockName . $block; $this->getLayout()->addBlock($currentBlockRenderer, $currentBlockName); $this->setChild($block, $currentBlockName); } - $methodArray = $methodArray + $pbridgeMethodArray; + $methodArray = $methodArray + $this->_pbridgeMethodArray; + } + return $methodArray; + } + + /** + * Render payment methods xml + * + * @return string + * @throw Mage_Core_Exception + */ + protected function _toHtml() + { + /** @var $methodsXmlObj Mage_XmlConnect_Model_Simplexml_Element */ + $methodsXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); + + if (is_object(Mage::getConfig()->getNode('modules/Enterprise_GiftCardAccount'))) { + $this->addGiftcardToXmlObj($methodsXmlObj); + if ($this->getIsUsedGiftCard() && $this->_isPaymentRequired()) { + return $methodsXmlObj->asNiceXml(); + } } + if (is_object(Mage::getConfig()->getNode('modules/Enterprise_CustomerBalance'))) { + $this->addCustomerBalanceToXmlObj($methodsXmlObj); + } + + $methodArray = $this->_getPaymentMethodArray(); $usedMethods = $sortedAvailableMethodCodes = $usedCodes = array(); /** * Receive available methods for checkout */ - $allAvailableMethods = Mage::helper('payment')->getStoreMethods(Mage::app()->getStore(), $this->getQuote()); + $allAvailableMethods = Mage::helper('payment')->getStoreMethods( + Mage::app()->getStore(), $this->getQuote() + ); /** * Get sorted codes of available methods diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php index ceb8f11ced..ace6306a33 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php @@ -27,9 +27,9 @@ /** * PayPal Direct Payment method xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Direct extends Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Payflow diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php index 4a53a76491..97b9bb7cc2 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php @@ -119,38 +119,39 @@ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $ $verification = ''; if ($this->hasVerification()) { - $verification = - ' - - - - '; + $verification = << + + + +
+EOT; } $xml = << - - - $ccTypes - - - - - - - - - - $ccMonthes - - - - - $ccYears - - - $verification - +
+ + + $ccTypes + + + + + + + + + + $ccMonthes + + + + + $ccYears + + + $verification +
EOT; $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml); $formXmlObj->appendChild($fieldsetXmlObj); diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php index 5fbb893ab6..0315456e42 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php @@ -27,9 +27,9 @@ /** * Authorize.Net through Pbridge Payment method xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Authorizenet extends Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php index a06e6a4600..1b7fd0b102 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php @@ -27,9 +27,9 @@ /** * PayPal Direct through Pbridge Payment method xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Paypal extends Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php index d02bdaf9a8..6af2fad556 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php @@ -27,9 +27,9 @@ /** * PayPalUK Direct through Pbridge Payment method xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Paypaluk extends Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php index 9598488315..2fdbe679ed 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php @@ -27,9 +27,9 @@ /** * Payflow Pro through Pbridge Payment method xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Verisign extends Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Available.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Available.php index 1ed6166a72..ca6bcb1ef6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Available.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Available.php @@ -27,9 +27,9 @@ /** * One page checkout shipping methods xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Checkout_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available @@ -49,24 +49,16 @@ protected function _toHtml() $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates) { $methodXmlObj = $methodsXmlObj->addChild('method'); - $methodXmlObj->addAttribute( - 'label', - $methodsXmlObj->xmlentities($this->getCarrierName($code)) - ); + $methodXmlObj->addAttribute('label', $methodsXmlObj->xmlentities($this->getCarrierName($code))); $ratesXmlObj = $methodXmlObj->addChild('rates'); $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate) { $rateXmlObj = $ratesXmlObj->addChild('rate'); - $rateXmlObj->addAttribute( - 'label', - $methodsXmlObj->xmlentities($_rate->getMethodTitle()) - ); + $rateXmlObj->addAttribute('label', $methodsXmlObj->xmlentities($_rate->getMethodTitle())); $rateXmlObj->addAttribute('code', $_rate->getCode()); if ($_rate->getErrorMessage()) { - $rateXmlObj->addChild( - 'error_message', - $methodsXmlObj->xmlentities($_rate->getErrorMessage())); + $rateXmlObj->addChild('error_message', $methodsXmlObj->xmlentities($_rate->getErrorMessage())); } else { $price = Mage::helper('tax')->getShippingPrice( $_rate->getPrice(), @@ -74,12 +66,9 @@ protected function _toHtml() $this->getAddress() ); $formattedPrice = $store->convertPrice($price, true, false); - $rateXmlObj->addAttribute( - 'price', - Mage::helper('xmlconnect')->formatPriceForXml( - $store->convertPrice($price, false, false) - ) - ); + $rateXmlObj->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml( + $store->convertPrice($price, false, false) + )); $rateXmlObj->addAttribute('formated_price', $formattedPrice); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Cms/Page.php b/app/code/core/Mage/XmlConnect/Block/Cms/Page.php index 2598c21573..be878e7134 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cms/Page.php +++ b/app/code/core/Mage/XmlConnect/Block/Cms/Page.php @@ -27,11 +27,10 @@ /** * Cms Page xml renderer * - * @category Mage - * @package Mage_XmlConnect + * @category Mage + * @package Mage_XmlConnect * @author Magento Core Team */ - class Mage_XmlConnect_Block_Cms_Page extends Mage_Cms_Block_Page { /** diff --git a/app/code/core/Mage/XmlConnect/Block/Configuration.php b/app/code/core/Mage/XmlConnect/Block/Configuration.php index cc73ace607..6d6ba86331 100644 --- a/app/code/core/Mage/XmlConnect/Block/Configuration.php +++ b/app/code/core/Mage/XmlConnect/Block/Configuration.php @@ -31,7 +31,6 @@ * @package Mage_XmlConnect * @author Magento Core Team */ - class Mage_XmlConnect_Block_Configuration extends Mage_Core_Block_Template { /** @@ -100,7 +99,7 @@ protected function _buildRecursive($section, $subtree) } else { $value = (string)$value; if ($value != '') { - $section->addChild($key, Mage::helper('core')->htmlEscape($value)); + $section->addChild($key, Mage::helper('core')->escapeHtml($value)); } } } 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 f204de994d..ab998621c4 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php @@ -31,8 +31,44 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Block_Customer_Address_Form extends Mage_Core_Block_Template +class Mage_XmlConnect_Block_Customer_Address_Form extends Mage_Customer_Block_Address_Edit { + /** + * Customer name widget block + * + * @var Mage_Customer_Block_Widget_Name + */ + protected $_nameWidgetBlock; + + /** + * Enterprise customer field renderer list as type => renderer block + * + * Original block relations: + * - 'text' => 'enterprise_customer/form_renderer_text', + * - 'textarea' => 'enterprise_customer/form_renderer_textarea', + * - 'multiline' => 'enterprise_customer/form_renderer_multiline', + * - 'date' => 'enterprise_customer/form_renderer_date', + * - 'select' => 'enterprise_customer/form_renderer_select', + * - 'multiselect' => 'enterprise_customer/form_renderer_multiselect', + * - 'boolean' => 'enterprise_customer/form_renderer_boolean', + * - 'file' => 'enterprise_customer/form_renderer_file' + * - 'image' => 'enterprise_customer/form_renderer_image' + * + * @see customer.xml layout customer_form_template_handle node + * @var array + */ + protected $_customerFiledRenderer = array( + 'text' => 'xmlconnect/customer_form_renderer_text', + 'textarea' => 'xmlconnect/customer_form_renderer_textarea', + 'multiline' => 'xmlconnect/customer_form_renderer_multiline', + 'date' => 'xmlconnect/customer_form_renderer_date', + 'select' => 'xmlconnect/customer_form_renderer_select', + 'multiselect' => 'xmlconnect/customer_form_renderer_multiselect', + 'boolean' => 'xmlconnect/customer_form_renderer_boolean', + 'file' => 'xmlconnect/customer_form_renderer_file', + 'image' => 'xmlconnect/customer_form_renderer_image' + ); + /** * Render customer address form xml * @@ -41,140 +77,361 @@ class Mage_XmlConnect_Block_Customer_Address_Form extends Mage_Core_Block_Templa protected function _toHtml() { $address = $this->getAddress(); - $xmlModel = Mage::getModel('xmlconnect/simplexml_element', ''); /** * Init address object and save its data to variables */ $addressId = (int)$this->getRequest()->getParam('id'); + $billingChecked = $shippingChecked = false; + if ($addressId && $address && $address->getId()) { $defaultBillingAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling(); $defaultShippingAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping(); - $billingChecked = $addressId == $defaultBillingAddressId ? ' checked="1"' : ''; - $shippingChecked = $addressId == $defaultShippingAddressId ? ' checked="1"' : ''; - - $firstname = $xmlModel->xmlentities(strip_tags($address->getFirstname())); - $lastname = $xmlModel->xmlentities(strip_tags($address->getLastname())); - $company = $xmlModel->xmlentities(strip_tags($address->getCompany())); - $street1 = $xmlModel->xmlentities(strip_tags($address->getStreet(1))); - $street2 = $xmlModel->xmlentities(strip_tags($address->getStreet(2))); - $city = $xmlModel->xmlentities(strip_tags($address->getCity())); - $regionId = $xmlModel->xmlentities($address->getRegionId()); - $region = Mage::getModel('directory/region')->load($regionId)->getName(); - if (!$region) { - $region = $address->getRegion(); - } - $region = $xmlModel->xmlentities(strip_tags($region)); - $postcode = $xmlModel->xmlentities(strip_tags($address->getPostcode())); - $countryId = $xmlModel->xmlentities($address->getCountryId()); - $telephone = $xmlModel->xmlentities(strip_tags($address->getTelephone())); - $fax = $xmlModel->xmlentities(strip_tags($address->getFax())); - } else { - $firstname = $lastname = $company = $street1 = $street2 = $billingChecked = $shippingChecked = ''; - $city = $region = $postcode = $telephone = $fax = ''; - $countryId = $regionId = null; + $billingChecked = (int)$addressId == $defaultBillingAddressId; + $shippingChecked = (int)$addressId == $defaultShippingAddressId; + + $company = $address->getCompany(); + $street1 = $address->getStreet(1); + $street2 = $address->getStreet(2); + $city = $address->getCity(); + $regionId = $address->getRegionId(); + $region = $address->getRegion(); + $postcode = $address->getPostcode(); + $countryId = $address->getCountryId(); + $telephone = $address->getTelephone(); + $fax = $address->getFax(); } - $countries = $this->_getCountryOptions(); + $action = Mage::helper('xmlconnect')->getActionUrl('xmlconnect/customer/saveaddress'); - $regions = array(); - $countryOptionsXml = ''; - if (is_array($countries)) { - foreach ($countries as $key => $data) { - if ($data['value']) { - $regions = $this->_getRegionOptions($data['value']); - } - $region = is_array($regions) && !empty($regions) ? 'region_id' : 'region'; - $countryOptionsXml .= ' - - - ' . $xmlModel->xmlentities($data['value']) . ''; - if (is_array($regions) && !empty($regions)) { - $countryOptionsXml .= ''; - foreach ($regions as $_key => $regionData) { - $region = $regionId == $regionData['value'] ? ' selected="1"' : ''; - $countryOptionsXml .= ''; - $countryOptionsXml .= - ' - ' . $xmlModel->xmlentities($regionData['value']) . ''; - $countryOptionsXml .= ''; - } - $countryOptionsXml .= ''; - } - $countryOptionsXml .= ''; + /** @var Mage_XmlConnect_Model_Simplexml_Form $fromXmlObj */ + $fromXmlObj = Mage::getModel('xmlconnect/simplexml_form', array( + 'xml_id' => 'address_form', + 'action' => $action, + 'use_container' => true + )); + + $contactInfoFieldset = $fromXmlObj->addFieldset('contact_info', array( + 'legend' => $this->__('Contact Information') + ))->setCustomAttributes(array('legend')); + + $this->_addCustomerContactInfo($contactInfoFieldset); + + $contactInfoFieldset->addField('company', 'text', array( + 'label' => $this->__('Company'), + 'value' => isset($company) ? $company : '' + )); + $contactInfoFieldset->addField('telephone', 'text', array( + 'label' => $this->__('Telephone'), + 'required' => 'true', + 'value' => isset($telephone) ? $telephone : '' + )); + $contactInfoFieldset->addField('fax', 'text', array( + 'label' => $this->__('Fax'), + 'value' => isset($fax) ? $fax : '' + )); + + $addressFieldset = $fromXmlObj->addFieldset('address_info', array('legend' => $this->__('Address'))) + ->setCustomAttributes(array('legend')); + + $addressFieldset->addField('street', 'text', array( + 'name' => 'street[]', + 'label' => $this->__('Street Address'), + 'required' => 'true', + 'value' => isset($street1) ? $street1 : '' + )); + $addressFieldset->addField('street_2', 'text', array( + 'name' => 'street[]', + 'label' => $this->__('Street Address 2'), + 'value' => isset($street2) ? $street2 : '' + )); + $addressFieldset->addField('city', 'text', array( + 'label' => $this->__('City'), + 'required' => 'true', + 'value' => isset($city) ? $city : '' + )); + + $countryId = isset($countryId) ? $countryId : null; + $regionId = isset($regionId) ? $regionId : null; + $region = isset($region) ? $region : null; + + $addressFieldset->addField('country_id', 'countryListSelect', array( + 'label' => $this->__('Country'), + 'required' => 'true', + 'value' => array( + 'country_id' => $countryId, + 'region_id' => $regionId, + 'region' => $region + ), + 'old_format' => true + )); + $addressFieldset->addField('region', 'text', array( + 'label' => $this->__('State/Province'), + 'value' => isset($region) ? $region : '' + )); + $addressFieldset->addField('region_id', 'select', array( + 'label' => $this->__('State/Province'), + 'required' => 'true', + )); + $addressFieldset->addField('postcode', 'text', array( + 'label' => $this->__('Zip/Postal Code'), + 'required' => 'true', + 'value' => isset($postcode) ? $postcode : '' + )); + $addressFieldset->addField('default_billing', 'checkbox', array( + 'label' => $this->__('Use as my default billing address'), + 'value' => $billingChecked ? $billingChecked : 0 + )); + + $addressFieldset->addField('default_shipping', 'checkbox', array( + 'label' => $this->__('Use as my default shipping address'), + 'value' => $shippingChecked ? $shippingChecked : 0 + )); + + $this->_addCustomAddressAttributes($addressFieldset); + + return $fromXmlObj->getXml(); + } + + /** + * Add customer contact attributes + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + * @return Mage_XmlConnect_Block_Customer_Address_Form + */ + protected function _addCustomerContactInfo( + Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + ) { + if (is_object(Mage::getConfig()->getNode('modules/Enterprise_Customer'))) { + $this->setNameWidgetBlock( + $this->getLayout()->createBlock('customer/widget_name')->setObject( + $this->getAddress()->getFirstname() ? $this->getAddress() : $this->getCustomer() + )); + + if ($this->getNameWidgetBlock()->showPrefix()) { + $this->_addPrefix($contactInfoFieldset); + } + + $this->_addFirstName($contactInfoFieldset); + + if ($this->getNameWidgetBlock()->showMiddlename()) { + $this->_addMiddleName($contactInfoFieldset); + } + + $this->_addLastName($contactInfoFieldset); + + if ($this->getNameWidgetBlock()->showSuffix()) { + $this->_addSuffix($contactInfoFieldset); } + } else { + $this->_addFirstName($contactInfoFieldset); + $this->_addLastName($contactInfoFieldset); } - $countryOptionsXml .= ''; - - $xml = << -
- - - - - -
-
- - - - - $countryOptionsXml - - - - - - -
- -EOT; - return $xml; + return $this; } /** - * Retrieve regions by country + * Add customer prefix field * - * @param string $countryId - * @return array + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + * @return Mage_XmlConnect_Block_Customer_Address_Form */ - protected function _getRegionOptions($countryId) + protected function _addPrefix(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset) { - $cacheKey = 'DIRECTORY_REGION_SELECT_STORE'.Mage::app()->getStore()->getId().$countryId; - if (Mage::app()->useCache('config') && $cache = Mage::app()->loadCache($cacheKey)) { - $options = unserialize($cache); + $attributes = array(); + $attributes += $contactInfoFieldset->checkAttribute( + 'value', $this->getNameWidgetBlock()->getObject()->getPrefix() + ); + + $attributes += $contactInfoFieldset->checkAttribute( + 'required', (int)$this->getNameWidgetBlock()->isPrefixRequired() + ); + + if ($this->getNameWidgetBlock()->getPrefixOptions() === false) { + $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('prefix'), 'text', array( + 'label' => $this->getNameWidgetBlock()->__('Prefix'), + 'name' => $this->getNameWidgetBlock()->getFieldName('prefix') + ) + $attributes); } else { - $collection = Mage::getModel('directory/region')->getResourceCollection() - ->addCountryFilter($countryId) - ->load(); - $options = $collection->toOptionArray(); - if (Mage::app()->useCache('config')) { - Mage::app()->saveCache(serialize($options), $cacheKey, array('config')); - } + $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('prefix'), 'select', array( + 'label' => $this->getNameWidgetBlock()->__('Prefix'), + 'name' => $this->getNameWidgetBlock()->getFieldName('prefix'), + 'options' => $this->getNameWidgetBlock()->getPrefixOptions() + ) + $attributes); } - return $options; + return $this; } /** - * Retrieve countries + * Add customer suffix field * - * @return array + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + * @return Mage_XmlConnect_Block_Customer_Address_Form */ - protected function _getCountryOptions() + protected function _addSuffix( + Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + ) { - $cacheKey = 'DIRECTORY_COUNTRY_SELECT_STORE_'.Mage::app()->getStore()->getCode(); - if (Mage::app()->useCache('config') && $cache = Mage::app()->loadCache($cacheKey)) { - $options = unserialize($cache); + $attributes = array(); + $attributes += $contactInfoFieldset->checkAttribute( + 'value', $this->getNameWidgetBlock()->getObject()->getSuffix() + ); + + $attributes += $contactInfoFieldset->checkAttribute( + 'required', (int)$this->getNameWidgetBlock()->isSuffixRequired() + ); + + if ($this->getNameWidgetBlock()->getSuffixOptions() === false) { + $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('suffix'), 'text', array( + 'label' => $this->getNameWidgetBlock()->__('Suffix'), + 'name' => $this->getNameWidgetBlock()->getFieldName('suffix') + ) + $attributes); } else { - $collection = Mage::getModel('directory/country')->getResourceCollection() - ->loadByStore(); - $options = $collection->toOptionArray(); - if (Mage::app()->useCache('config')) { - Mage::app()->saveCache(serialize($options), $cacheKey, array('config')); + $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('suffix'), 'select', array( + 'label' => $this->getNameWidgetBlock()->__('Suffix'), + 'name' => $this->getNameWidgetBlock()->getFieldName('suffix'), + 'options' => $this->getNameWidgetBlock()->getSuffixOptions() + ) + $attributes); + } + return $this; + } + + /** + * Add customer middle name field + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + * @return Mage_XmlConnect_Block_Customer_Address_Form + */ + protected function _addMiddleName( + Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + ) + { + $attributes = array(); + $attributes += $contactInfoFieldset->checkAttribute( + 'value', + $this->getNameWidgetBlock()->getObject()->getMiddlename() + ); + + $contactInfoFieldset->addField($this->getNameWidgetBlock()->getFieldId('middlename'), 'text', array( + 'label' => $this->getNameWidgetBlock()->__('M.I.'), + 'name' => $this->getNameWidgetBlock()->getFieldName('middlename') + ) + $attributes); + + return $this; + } + + /** + * Add customer first name field + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + * @return Mage_XmlConnect_Block_Customer_Address_Form + */ + protected function _addFirstName( + Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + ) { + $firstName = $this->getAddress()->getFirstname(); + $contactInfoFieldset->addField('firstname', 'text', array( + 'label' => $this->__('First Name'), + 'required' => 'true', + 'value' => isset($firstName) ? $firstName : '' + )); + return $this; + } + + /** + * Add customer last name field + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + * @return Mage_XmlConnect_Block_Customer_Address_Form + */ + protected function _addLastName( + Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $contactInfoFieldset + ) { + $lastName = $this->getAddress()->getLastname(); + $contactInfoFieldset->addField('lastname', 'text', array( + 'label' => $this->__('Last Name'), + 'required' => 'true', + 'value' => isset($lastName) ? $lastName : '' + )); + return $this; + } + + /** + * Add custom customer attributes + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $addressFieldset + * @return Mage_XmlConnect_Block_Customer_Address_Form + */ + protected function _addCustomAddressAttributes( + Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $addressFieldset + ) { + if (is_object(Mage::getConfig()->getNode('modules/Enterprise_Customer'))) { + /** @var $addressAttrBlock Enterprise_Customer_Block_Form */ + $addressAttrBlock = $this->getLayout() + ->addBlock('enterprise_customer/form', 'customer_address_attr'); + $addressAttrBlock->setFormCode('customer_address_edit'); + $addressAttrBlock->setEntity($this->getAddress()); + + foreach ($this->_customerFiledRenderer as $type => $rendererBlock) { + $addressAttrBlock->addRenderer($type, $rendererBlock, 'customer/form/renderer/text.phtml'); + } + + if ($addressAttrBlock->hasUserDefinedAttributes()) { + foreach ($addressAttrBlock->getUserDefinedAttributes() as $attribute) { + $type = $attribute->getFrontendInput(); + $block = $addressAttrBlock->getRenderer($type); + if ($block) { + $block->setAttributeObject($attribute)->setEntity($addressAttrBlock->getEntity()) + ->addFieldToXmlObj($addressFieldset); + } + } } } - return $options; + return $this; + } + + /** + * Get customer name widget block + * + * @return Mage_Customer_Block_Widget_Name + */ + public function getNameWidgetBlock() + { + return $this->_nameWidgetBlock; + } + + /** + * Set customer name widget block + * + * @param Mage_Customer_Block_Widget_Name $nameWidgetBlock + * @return Mage_XmlConnect_Block_Customer_Address_Form + */ + public function setNameWidgetBlock($nameWidgetBlock) + { + $this->_nameWidgetBlock = $nameWidgetBlock; + return $this; + } + + /** + * Get enterprise customer fields renderer + * + * @return array + */ + public function getCustomerFiledRenderer() + { + return $this->_customerFiledRenderer; + } + + /** + * Set enterprise customer fields renderer + * + * @param array $customerFiledRenderer + * @return Mage_XmlConnect_Block_Customer_Address_Form + */ + public function setCustomerFiledRenderer($customerFiledRenderer) + { + $this->_customerFiledRenderer = $customerFiledRenderer; + return $this; } } 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 aeb1e423f3..b0f2381891 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php @@ -92,9 +92,7 @@ public function prepareAddressData( $attributes = Mage::helper('customer/address')->getAttributes(); - $data = array( - 'entity_id' => $address->getId() - ); + $data = array('entity_id' => $address->getId()); foreach ($attributes as $attribute) { /* @var $attribute Mage_Customer_Model_Attribute */ @@ -110,7 +108,7 @@ public function prepareAddressData( $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $address); $value = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE); if ($attribute->getFrontendInput() == 'multiline') { - $values = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY); + $values = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY); // explode lines foreach ($values as $k => $v) { $key = sprintf('%s%d', $attribute->getAttributeCode(), $k + 1); @@ -122,9 +120,10 @@ public function prepareAddressData( } foreach ($data as $key => $value) { - if (!empty($value)) { - $item->addChild($key, $item->xmlentities($value)); + if (empty($value)) { + continue; } + $item->addChild($key, $item->xmlentities($value)); } } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form.php index b82d43db08..24431c1e84 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form.php @@ -42,12 +42,13 @@ protected function _toHtml() { $editFlag = (int)$this->getRequest()->getParam('edit'); $customer = $this->getCustomer(); + /** @var $xmlModel Mage_XmlConnect_Model_Simplexml_Element */ $xmlModel = Mage::getModel('xmlconnect/simplexml_element', ''); - + //Enterprise_Customer if ($editFlag == 1 && $customer && $customer->getId()) { - $firstname = $xmlModel->xmlentities(strip_tags($customer->getFirstname())); - $lastname = $xmlModel->xmlentities(strip_tags($customer->getLastname())); - $email = $xmlModel->xmlentities(strip_tags($customer->getEmail())); + $firstname = $xmlModel->xmlentities($customer->getFirstname()); + $lastname = $xmlModel->xmlentities($customer->getLastname()); + $email = $xmlModel->xmlentities($customer->getEmail()); } else { $firstname = $lastname = $email = ''; } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Boolean.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Boolean.php new file mode 100644 index 0000000000..fa6d20a8fd --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Boolean.php @@ -0,0 +1,49 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_Boolean extends Mage_XmlConnect_Block_Customer_Form_Renderer_Select +{ + /** + * Return array of select options + * + * @return array + */ + public function getOptions() + { + return array( + array('value' => '', 'label' => ''), + array('value' => '0', 'label' => Mage::helper('enterprise_customer')->__('No')), + array('value' => '1', 'label' => Mage::helper('enterprise_customer')->__('Yes')) + ); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Date.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Date.php new file mode 100644 index 0000000000..b410dc34a0 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Date.php @@ -0,0 +1,97 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_Date extends Enterprise_Customer_Block_Form_Renderer_Date +{ + /** + * Field type + * + * @var string + */ + protected $_filedType = 'date'; + + /** + * Prepare values for renderer + * + * @return array + */ + protected function _prepareValues() + { + return array('day' => array( + 'id' => $this->getHtmlId('day'), + 'title' => $this->__('Day'), + 'label' => $this->__('DD'), + 'value' => $this->getDay() + ), 'month' => array( + 'id' => $this->getHtmlId('month'), + 'title' => $this->__('Month'), + 'label' => $this->__('MM'), + 'value' => $this->getMonth() + ), 'year' => array( + 'id' => $this->getHtmlId('year'), + 'title' => $this->__('Year'), + 'label' => $this->__('YYYY'), + 'value' => $this->getYear() + )); + } + + /** + * Add date field to fieldset xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Date + */ + public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj) + { + $attributes = array( + 'label' => $this->getLabel(), + 'name' => $this->getFieldName(), + 'format'=> $this->getDateFormat(), + 'value' => $this->_prepareValues() + ); + + $attributes += Mage::helper('xmlconnect/customer_form_renderer') + ->addTitleAndRequiredAttr($fieldsetXmlObj, $this); + $fieldXmlObj = $fieldsetXmlObj->addField($this->getHtmlId('full'), $this->_filedType, $attributes); + $validateRules = $this->getAttributeObject()->getValidateRules(); + + if (!empty($validateRules)) { + $validatorXmlObj = $fieldXmlObj->addValidator(); + if (!empty($validateRules['input_validation'])) { + $validatorXmlObj->addRule(array('type' => $validateRules['input_validation'])); + } + } + + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/File.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/File.php new file mode 100644 index 0000000000..4cb85354b7 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/File.php @@ -0,0 +1,112 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_File extends Enterprise_Customer_Block_Form_Renderer_File +{ + /** + * Field type + * + * @var string + */ + protected $_filedType = 'file'; + + /** + * Change form post params for file upload compliance + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldsetXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_File + */ + protected function _setFormPostParams(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldsetXmlObj) + { + $fieldsetXmlObj->getForm()->setData('method', 'post'); + $fieldsetXmlObj->getForm()->setData('enctype', 'multipart/form-data'); + return $this; + } + + /** + * Add file field to fieldset xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_File + */ + public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj) + { + $this->_setFormPostParams($fieldsetXmlObj); + + $attributes = array( + 'label' => $this->getLabel(), 'name' => $this->getFieldName(), 'value' => $this->getEscapedValue() + ); + + $attributes += Mage::helper('xmlconnect/customer_form_renderer') + ->addTitleAndRequiredAttr($fieldsetXmlObj, $this); + + $fieldXmlObj = $fieldsetXmlObj->addField($this->getHtmlId(), $this->_filedType, $attributes); + $this->_addValidator($fieldXmlObj); + + return $this; + } + + /** + * Add validator for file field to fieldset xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_File + */ + protected function _addValidator(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldXmlObj) + { + $validateRules = $this->getAttributeObject()->getValidateRules(); + + if (!empty($validateRules)) { + $validatorXmlObj = $fieldXmlObj->addValidator(); + + if (!empty($validateRules['max_file_size'])) { + $minTextLength = (int) $validateRules['max_file_size']; + $validatorXmlObj->addRule(array( + 'type' => 'max_file_size', + 'value' => $minTextLength, + 'field_label' => $this->getLabel() + )); + } + + if (!empty($validateRules['file_extensions'])) { + $maxTextLength = $validateRules['file_extensions']; + $validatorXmlObj->addRule(array( + 'type' => 'file_extensions', + 'value' => $maxTextLength, + 'field_label' => $this->getLabel() + )); + } + } + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Image.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Image.php new file mode 100644 index 0000000000..784e6f0e6b --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Image.php @@ -0,0 +1,83 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_Image extends Mage_XmlConnect_Block_Customer_Form_Renderer_File +{ + /** + * Field type + * + * @var string + */ + protected $_filedType = 'image'; + + /** + * Add validator for image file field to fieldset xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Image + */ + protected function _addValidator(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $fieldXmlObj) + { + parent::_addValidator($fieldXmlObj); + + $validateRules = $this->getAttributeObject()->getValidateRules(); + + if (!empty($validateRules)) { + + foreach ($fieldXmlObj->getElements() as $element) { + if ($element->getType() == 'validator') { + $validatorXmlObj = $element; + } + } + + if (!isset($validatorXmlObj)) { + $validatorXmlObj = $fieldXmlObj->addValidator(); + } + + if (!empty($validateRules['max_image_width'])) { + $minTextLength = (int) $validateRules['max_image_width']; + $validatorXmlObj->addRule(array( + 'type' => 'max_image_width', 'value' => $minTextLength, 'field_label' => $this->getLabel() + )); + } + + if (!empty($validateRules['max_image_heght'])) { + $maxTextLength = $validateRules['max_image_heght']; + $validatorXmlObj->addRule(array( + 'type' => 'max_image_height', 'value' => $maxTextLength, 'field_label' => $this->getLabel() + )); + } + } + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiline.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiline.php new file mode 100644 index 0000000000..5c625721ab --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiline.php @@ -0,0 +1,88 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_Multiline extends Enterprise_Customer_Block_Form_Renderer_Multiline +{ + /** + * Field type + * + * @var string + */ + protected $_filedType = 'multiline'; + + /** + * Add multiline field to fieldset xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Multiline + */ + public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj) + { + $attributes = array( + 'label' => $this->getLabel(), + 'name' => $this->getFieldName(), + 'line_count' => $this->getLineCount(), + 'attribute_code' => $this->getAttributeObject()->getAttributeCode(), + 'value' => $this->getValues() + ); + + $attributes += Mage::helper('xmlconnect/customer_form_renderer') + ->addTitleAndRequiredAttr($fieldsetXmlObj, $this); + + $fieldXmlObj = $fieldsetXmlObj->addField( + $this->_filedType . '_' . $this->getHtmlId(), $this->_filedType, $attributes + ); + + $validateRules = $this->getAttributeObject()->getValidateRules(); + + if (!empty($validateRules)) { + $validatorXmlObj = $fieldXmlObj->addValidator(); + + if (!empty($validateRules['min_text_length'])) { + $minTextLength = (int) $validateRules['min_text_length']; + $validatorXmlObj->addRule(array('type' => 'min_length', 'value' => $minTextLength)); + } + + if (!empty($validateRules['max_text_length'])) { + $maxTextLength = (int) $validateRules['max_text_length']; + $validatorXmlObj->addRule(array('type' => 'max_length', 'value' => $maxTextLength)); + } + + if (!empty($validateRules['input_validation'])) { + $validatorXmlObj->addRule(array('type' => $validateRules['input_validation'])); + } + } + + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiselect.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiselect.php new file mode 100644 index 0000000000..f529399c48 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Multiselect.php @@ -0,0 +1,66 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_Multiselect + extends Enterprise_Customer_Block_Form_Renderer_Multiselect +{ + /** + * Field type + * + * @var string + */ + protected $_filedType = 'multiselect'; + + /** + * Add select field to fieldset xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Select + */ + public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj) + { + $attributes = array( + 'label' => $this->getLabel(), + 'name' => $this->getFieldName(''), + 'value' => $this->getValues(), + 'options' => $this->getOptions() + ); + + $attributes += Mage::helper('xmlconnect/customer_form_renderer') + ->addTitleAndRequiredAttr($fieldsetXmlObj, $this); + + $fieldsetXmlObj->addField($this->getHtmlId(), $this->_filedType, $attributes); + + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Select.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Select.php new file mode 100644 index 0000000000..8f4af08613 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Select.php @@ -0,0 +1,65 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_Select extends Enterprise_Customer_Block_Form_Renderer_Select +{ + /** + * Field type + * + * @var string + */ + protected $_filedType = 'select'; + + /** + * Add select field to fieldset xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Select + */ + public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj) + { + $attributes = array( + 'label' => $this->getLabel(), + 'name' => $this->getFieldName(), + 'value' => $this->getValue(), + 'options' => $this->getOptions() + ); + + $attributes += Mage::helper('xmlconnect/customer_form_renderer') + ->addTitleAndRequiredAttr($fieldsetXmlObj, $this); + + $fieldsetXmlObj->addField($this->getHtmlId(), $this->_filedType, $attributes); + + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Text.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Text.php new file mode 100644 index 0000000000..21cbace073 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Text.php @@ -0,0 +1,82 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_Text extends Enterprise_Customer_Block_Form_Renderer_Text +{ + /** + * Field type + * + * @var string + */ + protected $_filedType = 'text'; + + /** + * Add text field to fieldset xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj + * @return Mage_XmlConnect_Block_Customer_Form_Renderer_Text + */ + public function addFieldToXmlObj(Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset $fieldsetXmlObj) + { + $attributes = array( + 'label' => $this->getLabel(), 'name' => $this->getFieldName(), 'value' => $this->getEscapedValue() + ); + + $attributes += Mage::helper('xmlconnect/customer_form_renderer') + ->addTitleAndRequiredAttr($fieldsetXmlObj, $this); + + $fieldXmlObj = $fieldsetXmlObj->addField($this->getHtmlId(), $this->_filedType, $attributes); + + $validateRules = $this->getAttributeObject()->getValidateRules(); + + if (!empty($validateRules)) { + $validatorXmlObj = $fieldXmlObj->addValidator(); + + if (!empty($validateRules['min_text_length'])) { + $minTextLength = (int) $validateRules['min_text_length']; + $validatorXmlObj->addRule(array('type' => 'min_length', 'value' => $minTextLength)); + } + + if (!empty($validateRules['max_text_length'])) { + $maxTextLength = (int) $validateRules['max_text_length']; + $validatorXmlObj->addRule(array('type' => 'max_length', 'value' => $maxTextLength)); + } + + if (!empty($validateRules['input_validation'])) { + $validatorXmlObj->addRule(array('type' => $validateRules['input_validation'])); + } + } + + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Textarea.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Textarea.php new file mode 100644 index 0000000000..ced68edd34 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form/Renderer/Textarea.php @@ -0,0 +1,42 @@ + + */ +class Mage_XmlConnect_Block_Customer_Form_Renderer_Textarea extends Mage_XmlConnect_Block_Customer_Form_Renderer_Text +{ + /** + * Field type + * + * @var string + */ + protected $_filedType = 'textarea'; +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/GiftcardCheck.php b/app/code/core/Mage/XmlConnect/Block/Customer/GiftcardCheck.php new file mode 100644 index 0000000000..fccd8e5ac8 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/GiftcardCheck.php @@ -0,0 +1,65 @@ + + */ +class Mage_XmlConnect_Block_Customer_GiftcardCheck extends Enterprise_GiftCardAccount_Block_Check +{ + /** + * Render gift card info xml + * + * @return string + */ + protected function _toHtml() + { + $card = $this->getCard(); + if ($card->getId()) { + /** @var $xmlModel Mage_XmlConnect_Model_Simplexml_Element */ + $xmlModel = Mage::getModel('xmlconnect/simplexml_element', ''); + + $balance = Mage::helper('core')->currency($card->getBalance(), true, false); + + $result[] = $this->__("Gift Card: %s", $card->getCode()); + $result[] = $this->__('Current Balance: %s', $balance); + + if ($card->getDateExpires()) { + $result[] = $this->__('Expires: %s', $this->formatDate($card->getDateExpires(), 'short')); + } + $xmlModel->addCustomChild('info', implode(PHP_EOL, $result)); + } else { + $xmlModel = Mage::getModel('xmlconnect/simplexml_element', ''); + $xmlModel->addCustomChild('status', Mage_XmlConnect_Controller_Action::MESSAGE_STATUS_ERROR); + $xmlModel->addCustomChild('text', $this->__('Wrong or expired Gift Card Code.')); + } + + return $xmlModel->asNiceXml(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Details.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Details.php index 51f73a472c..5cf64fc278 100755 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Details.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Details.php @@ -33,6 +33,27 @@ */ class Mage_XmlConnect_Block_Customer_Order_Details extends Mage_Payment_Block_Info { + /** + * Pre-defined array of methods that we are going to render + * + * Core renderer list: + * - 'ccsave' => Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Ccsave + * - 'checkmo' => Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Checkmo + * - 'purchaseorder' => Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Purchaseorder + * - 'authorizenet' => Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet + * - 'pbridge_authorizenet' => Mage_Paygate_Block_Authorizenet_Info_Cc + * - 'pbridge_verisign' => Mage_Payment_Block_Info_Cc + * - 'paypal_express' => Mage_Paypal_Block_Payment_Info + * - 'paypal_mecl' => Mage_Paypal_Block_Payment_Info + * - 'pbridge_paypal_direct' => Mage_Paypal_Block_Payment_Info + * - 'pbridge_paypaluk_direct' => Mage_Paypal_Block_Payment_Info + * - 'free' => Mage_Payment_Block_Info + */ + protected $_methodArray = array( + 'ccsave', 'checkmo', 'purchaseorder', 'authorizenet', 'pbridge_authorizenet', 'pbridge_verisign', + 'paypal_express', 'paypal_mecl', 'pbridge_paypal_direct', 'pbridge_paypaluk_direct', 'free' + ); + /** * Render customer orders list xml * @@ -42,31 +63,18 @@ protected function _toHtml() { /** @var $orderXmlObj Mage_XmlConnect_Model_Simplexml_Element */ $orderXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); - /** @var $order Mage_Sales_Model_Order */ - $order = Mage::registry('current_order'); - if (!($order instanceof Mage_Sales_Model_Order)) { - Mage::throwException($this->__('Model of order is not loaded.')); - } + + $order = $this->_getOrder(); + $orderDate = $this->formatDate($order->getCreatedAtStoreDate(), 'long'); - $orderXmlObj->addCustomChild( - 'order', - null, - array( - 'label' => Mage::helper('sales')->__('Order #%s - %s', $order->getRealOrderId(), $order->getStatusLabel()), - 'order_date' => Mage::helper('sales')->__('Order Date: %s', $orderDate) - ) - ); + $orderXmlObj->addCustomChild('order', null, array( + 'label' => $this->__('Order #%s - %s', $order->getRealOrderId(), $order->getStatusLabel()), + 'order_date' => $this->__('Order Date: %s', $orderDate) + )); if (!$order->getIsVirtual()) { - $shipping = preg_replace( - array('@\r@', '@\n+@'), - array('', "\n"), - $order->getShippingAddress()->format('text') - ); - $billing = preg_replace( - array('@\r@', '@\n+@'), - array('', "\n"), - $order->getBillingAddress()->format('text') - ); + $shipping = Mage::helper('xmlconnect')->trimLineBreaks($order->getShippingAddress()->format('text')); + $billing = Mage::helper('xmlconnect')->trimLineBreaks($order->getBillingAddress()->format('text')); + $orderXmlObj->addCustomChild('shipping_address', $shipping); $orderXmlObj->addCustomChild('billing_address', $billing); @@ -77,36 +85,43 @@ protected function _toHtml() } $orderXmlObj->addCustomChild('shipping_method', $shippingMethodDescription); } - /** - * Pre-defined array of methods that we are going to render - */ - $methodArray = array( - 'ccsave' => 'Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Ccsave', - 'checkmo' => 'Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Checkmo', - 'purchaseorder' => 'Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Purchaseorder', - 'authorizenet' => 'Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet', - ); - // TODO: create info blocks for Payment Bridge methods -// /** -// * Check if the Payment Bridge module is available and add methods for rendering -// */ -// if (is_object(Mage::getConfig()->getNode('modules/Enterprise_Pbridge'))) { -// $pbridgeMethodArray = array( -// 'pbridge_authorizenet' => 'Enterprise_Pbridge_Model_Payment_Method_Authorizenet', -// 'pbridge_paypal' => 'Enterprise_Pbridge_Model_Payment_Method_Paypal', -// 'pbridge_verisign' => 'Enterprise_Pbridge_Model_Payment_Method_Payflow_Pro', -// 'pbridge_paypaluk' => 'Enterprise_Pbridge_Model_Payment_Method_Paypaluk', -// ); -// $methodArray = $methodArray + $pbridgeMethodArray; -// } - // TODO: it's need to create an info blocks for other payment methods (including Enterprise) + $this->_addPaymentMethodInfoToXmlObj($orderXmlObj); + + $itemsBlock = $this->getLayout()->getBlock('xmlconnect.customer.order.items'); + if ($itemsBlock) { + /** @var $itemsBlock Mage_XmlConnect_Block_Customer_Order_Items */ + $itemsBlock->setItems($order->getItemsCollection()); + $itemsBlock->addItemsToXmlObject($orderXmlObj); + $totalsBlock = $this->getLayout()->getBlock('xmlconnect.customer.order.totals'); + if ($totalsBlock) { + $totalsBlock->setOrder($order); + $totalsBlock->addTotalsToXmlObject($orderXmlObj); + } + } else { + $orderXmlObj->addChild('ordered_items'); + } + + return $orderXmlObj->asNiceXml(); + } + /** + * Add payment method info to order xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + protected function _addPaymentMethodInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj) + { + $order = $this->_getOrder(); + + // TODO: it's need to create an info blocks for other payment methods (including Enterprise) $method = $this->helper('payment')->getInfoBlock($order->getPayment())->getMethod(); $methodCode = $method->getCode(); $paymentNode = $orderXmlObj->addChild('payment_method'); - if (array_key_exists($methodCode, $methodArray)) { + + if (in_array($methodCode, $this->_methodArray, true)) { $currentBlockRenderer = 'xmlconnect/checkout_payment_method_info_' . $methodCode; $currentBlockName = 'xmlconnect.checkout.payment.method.info.' . $methodCode; $this->getLayout()->addBlock($currentBlockRenderer, $currentBlockName); @@ -126,9 +141,7 @@ protected function _toHtml() if (!empty($specificInfo)) { foreach ($specificInfo as $label => $value) { if ($value) { - $paymentNode->addCustomChild( - 'item', - implode($this->getValueAsArray($value, true), PHP_EOL), + $paymentNode->addCustomChild('item', implode($this->getValueAsArray($value, true), '\n'), array('label' => $label) ); } @@ -136,20 +149,37 @@ protected function _toHtml() } } - $itemsBlock = $this->getLayout()->getBlock('xmlconnect.customer.order.items'); - if ($itemsBlock) { - /** @var $itemsBlock Mage_XmlConnect_Block_Customer_Order_Items */ - $itemsBlock->setItems($order->getItemsCollection()); - $itemsBlock->addItemsToXmlObject($orderXmlObj); - $totalsBlock = $this->getLayout()->getBlock('xmlconnect.customer.order.totals'); - if ($totalsBlock) { - $totalsBlock->setOrder($order); - $totalsBlock->addTotalsToXmlObject($orderXmlObj); - } - } else { - $orderXmlObj->addChild('ordered_items'); + return $orderXmlObj; + } + + /** + * Get order model + * + * @through Mage_Core_Exception + * @return Mage_Sales_Model_Order + */ + protected function _getOrder() + { + $order = Mage::registry('current_order'); + if (!($order instanceof Mage_Sales_Model_Order)) { + Mage::throwException($this->__('Order is not available.')); } + return $order; + } - return $orderXmlObj->asNiceXml(); + /** + * Format address string + * + * @deprecated after 1.6.0.0 + * @param string $address + * @return string + */ + protected function _formatAddress($address) + { + return preg_replace( + array('@\r@', '@\n+@'), + array('', '\n'), + $address + ); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Bundle.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Bundle.php index d5b500f052..6efc33fe0c 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Bundle.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Bundle.php @@ -31,20 +31,19 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Bundle - extends Mage_Bundle_Block_Sales_Order_Items_Renderer +class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Bundle extends Mage_Bundle_Block_Sales_Order_Items_Renderer { /** * Add item to XML object + * (get from template: bundle/sales/order/items/renderer.phtml) * * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj - * @return void + * @return null */ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) { /** @var $parentItem Mage_Sales_Model_Order_Item */ $parentItem = $this->getItem(); - $items = array_merge(array($parentItem), $parentItem->getChildrenItems()); $_prevOptionId = ''; @@ -58,21 +57,29 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde /** @var $optionsXml Mage_XmlConnect_Model_Simplexml_Element */ $optionsXml = $itemXml->addChild('related_products'); - $weeeTaxAppliedAmount = (float)$parentItem->getWeeeTaxAppliedAmount(); - $weeeTaxDisposition = (float)$parentItem->getWeeeTaxDisposition(); - $typeOfDisplay1 = $weeeHelper->typeOfDisplay($parentItem, 1, 'sales') - && $weeeTaxAppliedAmount; - $typeOfDisplay2 = $weeeHelper->typeOfDisplay($parentItem, 2, 'sales') - && $weeeTaxAppliedAmount; - $typeOfDisplay4 = $weeeHelper->typeOfDisplay($parentItem, 4, 'sales') - && $weeeTaxAppliedAmount; - $typeOfDisplay014 = $weeeHelper->typeOfDisplay($parentItem, array(0, 1, 4), 'sales') - && $weeeTaxAppliedAmount; - $weeeTaxes = $weeeHelper->getApplied($parentItem); - - /** @var $_item Mage_Sales_Model_Order_Item */ - foreach ($items as $_item) { - $isOption = $_item->getParentItem() ? true : false; + $this->setWeeeTaxAppliedAmount($parentItem->getWeeeTaxAppliedAmount()); + $this->setWeeeTaxDisposition($parentItem->getWeeeTaxDisposition()); + + $typeOfDisplay1 = $weeeHelper->typeOfDisplay($parentItem, 1, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay2 = $weeeHelper->typeOfDisplay($parentItem, 2, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay4 = $weeeHelper->typeOfDisplay($parentItem, 4, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay014 = $weeeHelper->typeOfDisplay($parentItem, array(0, 1, 4), 'sales') + && $this->getWeeeTaxAppliedAmount(); + + $this->setTypesOfDisplay(array( + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_1 => $typeOfDisplay1, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_2 => $typeOfDisplay2, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_4 => $typeOfDisplay4, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_14 => $typeOfDisplay014, + )); + $this->setWeeeTaxes($weeeHelper->getApplied($parentItem)); + + /** @var $item Mage_Sales_Model_Order_Item */ + foreach ($items as $item) { + $isOption = $item->getParentItem() ? true : false; /** @var $objectXml Mage_XmlConnect_Model_Simplexml_Element */ if ($isOption) { @@ -80,23 +87,23 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde } else { $objectXml = $itemXml; } - $objectXml->addAttribute('product_id', $_item->getProductId()); - $objectXml->addCustomChild('entity_type', $_item->getProductType()); + $objectXml->addAttribute('product_id', $item->getProductId()); + $objectXml->addCustomChild('entity_type', $item->getProductType()); if ($isOption) { - $attributes = $this->getSelectionAttributes($_item); + $attributes = $this->getSelectionAttributes($item); if ($_prevOptionId != $attributes['option_id']) { $objectXml->addAttribute('label', $objectXml->xmlAttribute($attributes['option_label'])); $_prevOptionId = $attributes['option_id']; } } - $objectXml->addCustomChild('sku', Mage::helper('core/string')->splitInjection($_item->getSku())); + $objectXml->addCustomChild('sku', Mage::helper('core/string')->splitInjection($item->getSku())); if ($isOption) { - $name = $this->getValueHtml($_item); + $name = $this->getValueHtml($item); } else { - $name = $_item->getName(); + $name = $item->getName(); } $objectXml->addCustomChild('name', $name); @@ -104,129 +111,24 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde if (!$isOption) { /** @var $priceXml Mage_XmlConnect_Model_Simplexml_Element */ $priceXml = $objectXml->addChild('price'); + /** @var $subtotalXml Mage_XmlConnect_Model_Simplexml_Element */ + $subtotalXml = $objectXml->addChild('subtotal'); // Price excluding tax if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) { - - if ($typeOfDisplay014) { - $price = $parentItem->getPrice() + $weeeTaxAppliedAmount + $weeeTaxDisposition; - } else { - $price = $parentItem->getPrice(); - } - - $config = array( - 'value' => $this->_formatPrice($price) + Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml( + $this, + $parentItem, + $priceXml, + $subtotalXml ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Excl. Tax'); - } - $exclPriceXml = $priceXml->addCustomChild( - 'excluding_tax', - null, - $config - ); - - // TODO: move repeated code into another place - if ($weeeTaxes) { - /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */ - if ($typeOfDisplay1) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount']), - array('label' => $tax['title']) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount_incl_tax']), - array('label' => $tax['title']) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $exclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice( - $parentItem->getPrice() + $weeeTaxAppliedAmount + $weeeTaxDisposition - ), - array('label' => $weeeHelper->__('Total')) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } } // Price including tax if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) { - $incl = $this->helper('checkout')->getPriceInclTax($parentItem); - - if ($typeOfDisplay014) { - $price = $incl + $weeeTaxAppliedAmount; - } else { - $price = $incl - $weeeTaxDisposition; - } - - $config = array( - 'value' => $this->_formatPrice($price) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Incl. Tax'); - } - - $inclPriceXml = $priceXml->addCustomChild( - 'including_tax', - null, - $config + Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml( + $this, $parentItem, $priceXml, $subtotalXml, true ); - - if ($weeeTaxes) { - if ($typeOfDisplay1) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount']), - array('label' => $tax['title']) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount_incl_tax']), - array('label' => $tax['title']) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $inclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice( - $incl + $weeeTaxAppliedAmount - ), - array('label' => $weeeHelper->__('Total incl. tax')) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } } } @@ -236,205 +138,39 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde || (!$isOption && !$this->isChildCalculated()) ) { $qtyXml = $objectXml->addChild('qty'); - if ($_item->getQtyOrdered() > 0) { - $qtyXml->addCustomChild( - 'value', - $_item->getQtyOrdered() * 1, - array('label' => Mage::helper('sales')->__('Ordered')) - ); + if ($item->getQtyOrdered() > 0) { + $qtyXml->addCustomChild('value', $item->getQtyOrdered() * 1, array( + 'label' => Mage::helper('sales')->__('Ordered') + )); } - if ($_item->getQtyShipped() > 0 && !$this->isShipmentSeparately()) { - $qtyXml->addCustomChild( - 'value', - $_item->getQtyShipped() * 1, - array('label' => Mage::helper('sales')->__('Shipped')) - ); + if ($item->getQtyShipped() > 0 && !$this->isShipmentSeparately()) { + $qtyXml->addCustomChild('value', $item->getQtyShipped() * 1, array( + 'label' => Mage::helper('sales')->__('Shipped') + )); } - if ($_item->getQtyCanceled() > 0) { - $qtyXml->addCustomChild( - 'value', - $_item->getQtyCanceled() * 1, - array('label' => Mage::helper('sales')->__('Canceled')) - ); + if ($item->getQtyCanceled() > 0) { + $qtyXml->addCustomChild('value', $item->getQtyCanceled() * 1, array( + 'label' => Mage::helper('sales')->__('Canceled') + )); } - if ($_item->getQtyRefunded() > 0) { - $qtyXml->addCustomChild( - 'value', - $_item->getQtyRefunded() * 1, - array('label' => Mage::helper('sales')->__('Refunded')) - ); + if ($item->getQtyRefunded() > 0) { + $qtyXml->addCustomChild('value', $item->getQtyRefunded() * 1, array( + 'label' => Mage::helper('sales')->__('Refunded') + )); } - } elseif ($_item->getQtyShipped() > 0 && $isOption && $this->isShipmentSeparately()) { + } elseif ($item->getQtyShipped() > 0 && $isOption && $this->isShipmentSeparately()) { $qtyXml = $objectXml->addChild('qty'); - $qtyXml->addCustomChild( - 'value', - $_item->getQtyShipped() * 1, - array('label' => Mage::helper('sales')->__('Shipped')) - ); - } - - // set subtotals exactly for the Bundle product, but not for related products - if (!$isOption) { - /** @var $subtotalXml Mage_XmlConnect_Model_Simplexml_Element */ - $subtotalXml = $objectXml->addChild('subtotal'); - - // Subtotal excluding tax - if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) { - if ($typeOfDisplay014) { - $subtotal = $parentItem->getRowTotal() - + $parentItem->getWeeeTaxAppliedRowAmount() - + $parentItem->getWeeeTaxRowDisposition(); - } else { - $subtotal = $parentItem->getRowTotal(); - } - - $config = array( - 'value' => $this->_formatPrice($subtotal) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Excl. Tax'); - } - $exclPriceXml = $subtotalXml->addCustomChild( - 'excluding_tax', - null, - $config - ); - - if ($weeeTaxes) { - /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */ - if ($typeOfDisplay1) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount']), - array('label' => $tax['title']) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount_incl_tax']), - array('label' => $tax['title']) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $exclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice( - $parentItem->getRowTotal() - + $parentItem->getWeeeTaxAppliedRowAmount() - + $parentItem->getWeeeTaxRowDisposition() - ), - array('label' => $weeeHelper->__('Total')) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } - } - - // Subtotal including tax - if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) { - $incl = $this->helper('checkout')->getSubtotalInclTax($parentItem); - - if ($typeOfDisplay014) { - $subtotal = $incl + $parentItem->getWeeeTaxAppliedRowAmount(); - } else { - $subtotal = $incl - $parentItem->getWeeeTaxRowDisposition(); - } - - $config = array( - 'value' => $this->_formatPrice($subtotal) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Incl. Tax'); - } - - $inclPriceXml = $subtotalXml->addCustomChild( - 'including_tax', - null, - $config - ); - - if ($weeeTaxes) { - if ($typeOfDisplay1) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount']), - array('label' => $tax['title']) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount_incl_tax']), - array('label' => $tax['title']) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $inclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice( - $incl + $parentItem->getWeeeTaxAppliedRowAmount() - ), - array('label' => $weeeHelper->__('Total incl. tax')) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } - } + $qtyXml->addCustomChild('value', $item->getQtyShipped() * 1, array( + 'label' => Mage::helper('sales')->__('Shipped') + )); } } if ($parentItem->getDescription()) { - $itemXml->addCustomChild( - 'description', - $parentItem->getDescription() - ); + $itemXml->addCustomChild('description', $parentItem->getDescription()); } - if ($options = $this->getItemOptions()) { - /** @var $optionsXml Mage_XmlConnect_Model_Simplexml_Element */ - $optionsXml = $itemXml->addChild('options'); - foreach ($options as $option) { - $formatedOptionValue = $this->getFormatedOptionValue($option); - if (isset($formatedOptionValue['full_view']) && isset($formatedOptionValue['value'])) { - $value = $formatedOptionValue['value']; - } elseif (isset($option['print_value'])) { - $value = $option['print_value']; - } else { - $value = $option['value']; - } - - if ($value) { - $optionsXml->addCustomChild( - 'option', - strip_tags($value), - array('label' => $option['label']) - ); - } - } - } + Mage::helper('xmlconnect/customer_order')->addItemOptionsToXml($this, $itemXml); } /** @@ -447,9 +183,8 @@ public function getValueHtml($item) { $attributes = $this->getSelectionAttributes($item); if ($attributes) { - return sprintf('%d', $attributes['qty']) . ' x ' - . $item->getName() - . ' - ' . $this->_formatPrice($attributes['price']); + return sprintf('%d', $attributes['qty']) . ' x ' . $item->getName() . ' - ' + . $this->_formatPrice($attributes['price']); } else { return $item->getName(); } @@ -463,6 +198,6 @@ public function getValueHtml($item) */ protected function _formatPrice($price) { - return $this->getOrder()->getOrderCurrency()->formatPrecision($price, 2, array(), false); + return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $price); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Default.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Default.php index 7b7a692407..3f6b45d5c8 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Default.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Default.php @@ -31,14 +31,14 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Default - extends Mage_Sales_Block_Order_Item_Renderer_Default +class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Default extends Mage_Sales_Block_Order_Item_Renderer_Default { /** * Add item to XML object + * (get from template: sales/order/items/renderer/default.phtml) * * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj - * @return void + * @return null */ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) { @@ -46,13 +46,9 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde $item = $this->getItem(); /** @var $itemXml Mage_XmlConnect_Model_Simplexml_Element */ - $itemXml = $orderItemXmlObj->addCustomChild( - 'item', - null, - array( - 'product_id' => $item->getProductId() - ) - ); + $itemXml = $orderItemXmlObj->addCustomChild('item', null, array( + 'product_id' => $item->getProductId() + )); $itemXml->addCustomChild('name', $item->getName()); /** @var $weeeHelper Mage_Weee_Helper_Data */ @@ -60,347 +56,57 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde /** @var $taxHelper Mage_Tax_Helper_Data */ $taxHelper = $this->helper('tax'); - $options = $this->getItemOptions(); - if ($options) { - /** @var $optionsXml Mage_XmlConnect_Model_Simplexml_Element */ - $optionsXml = $itemXml->addChild('options'); - foreach ($options as $option) { - $value = false; - $formatedOptionValue = $this->getFormatedOptionValue($option); - if (isset($formatedOptionValue['full_view']) && isset($formatedOptionValue['value'])) { - $value = $formatedOptionValue['value']; - } elseif (isset($option['print_value'])) { - $value = $option['print_value']; - } elseif (isset($option['value'])) { - $value = $option['value']; - } - if ($value) { - $optionsXml->addCustomChild( - 'option', - strip_tags($value), - array('label' => $option['label']) - ); - } - } + Mage::helper('xmlconnect/customer_order')->addItemOptionsToXml($this, $itemXml); - $addtInfoBlock = $this->getProductAdditionalInformationBlock(); - if ($addtInfoBlock) { - // TODO: find how to set additional info block - // $addtInfoBlock->setItem($item)->toHtml(); - } + $addtInfoBlock = $this->getProductAdditionalInformationBlock(); + if ($addtInfoBlock) { + // TODO: find how to set additional info block + // $addtInfoBlock->setItem($item)->toHtml(); } $itemXml->addCustomChild('entity_type', $item->getProductType()); $itemXml->addCustomChild('description', $item->getDescription()); $itemXml->addCustomChild('sku', Mage::helper('core/string')->splitInjection($this->getSku())); + $this->setWeeeTaxAppliedAmount($item->getWeeeTaxAppliedAmount()); + $this->setWeeeTaxDisposition($item->getWeeeTaxDisposition()); + + $typeOfDisplay1 = $weeeHelper->typeOfDisplay($item, 1, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay2 = $weeeHelper->typeOfDisplay($item, 2, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay4 = $weeeHelper->typeOfDisplay($item, 4, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay014 = $weeeHelper->typeOfDisplay($item, array(0, 1, 4), 'sales') + && $this->getWeeeTaxAppliedAmount(); + + $this->setTypesOfDisplay(array( + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_1 => $typeOfDisplay1, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_2 => $typeOfDisplay2, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_4 => $typeOfDisplay4, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_14 => $typeOfDisplay014, + )); + $this->setWeeeTaxes($weeeHelper->getApplied($item)); + /** @var $priceXml Mage_XmlConnect_Model_Simplexml_Element */ $priceXml = $itemXml->addChild('price'); - $weeeTaxAppliedAmount = (float)$item->getWeeeTaxAppliedAmount(); - $weeeTaxDisposition = (float)$item->getWeeeTaxDisposition(); - $typeOfDisplay1 = $weeeHelper->typeOfDisplay($item, 1, 'sales') && $weeeTaxAppliedAmount; - $typeOfDisplay2 = $weeeHelper->typeOfDisplay($item, 2, 'sales') && $weeeTaxAppliedAmount; - $typeOfDisplay4 = $weeeHelper->typeOfDisplay($item, 4, 'sales') && $weeeTaxAppliedAmount; - $typeOfDisplay014 = $weeeHelper->typeOfDisplay($item, array(0, 1, 4), 'sales') && $weeeTaxAppliedAmount; - $weeeTaxes = $weeeHelper->getApplied($item); - - // Price excluding tax - if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) { - if ($typeOfDisplay014) { - $price = $item->getPrice() + $weeeTaxAppliedAmount + $weeeTaxDisposition; - } else { - $price = $item->getPrice(); - } - - $config = array( - 'value' => $this->_formatPrice($price) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Excl. Tax'); - } - - /** @var $exclPriceXml Mage_XmlConnect_Model_Simplexml_Element */ - $exclPriceXml = $priceXml->addCustomChild( - 'excluding_tax', - null, - $config - ); - - // TODO: move repeated code into another place - if ($weeeTaxes) { - /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */ - if ($typeOfDisplay1) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount']), - array('label' => $tax['title']) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount_incl_tax']), - array('label' => $tax['title']) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $exclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice( - $item->getPrice() + $weeeTaxAppliedAmount + $weeeTaxDisposition - ), - array('label' => $weeeHelper->__('Total')) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } - } - - // Price including tax - if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) { - $incl = $this->helper('checkout')->getPriceInclTax($item); - - if ($typeOfDisplay014) { - $price = $incl + $weeeTaxAppliedAmount; - } else { - $price = $incl - $weeeTaxDisposition; - } - - $config = array( - 'value' => $this->_formatPrice($price) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Incl. Tax'); - } - - /** @var $inclPriceXml Mage_XmlConnect_Model_Simplexml_Element */ - $inclPriceXml = $priceXml->addCustomChild( - 'including_tax', - null, - $config - ); - - if ($weeeTaxes) { - /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */ - if ($typeOfDisplay1) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount']), - array('label' => $tax['title']) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount_incl_tax']), - array('label' => $tax['title']) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $inclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice($incl + $weeeTaxAppliedAmount), - array('label' => $weeeHelper->__('Total incl. tax')) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } - } // Quantity: Ordered, Shipped, Cancelled, Refunded - /** @var $quantityXml Mage_XmlConnect_Model_Simplexml_Element */ - $quantityXml = $itemXml->addChild('qty'); - $qty = 1 * $item->getQtyOrdered(); - if ($qty > 0) { - $quantityXml->addCustomChild( - 'value', - $qty, - array('label' => $this->__('Ordered')) - ); - } - $qty = 1 * $item->getQtyShipped(); - if ($qty > 0) { - $quantityXml->addCustomChild( - 'value', - $qty, - array('label' => $this->__('Shipped')) - ); - } - $qty = 1 * $item->getQtyCanceled(); - if ($qty > 0) { - $quantityXml->addCustomChild( - 'value', - $qty, - array('label' => $this->__('Canceled')) - ); - } - $qty = 1 * $item->getQtyRefunded(); - if ($qty > 0) { - $quantityXml->addCustomChild( - 'value', - $qty, - array('label' => $this->__('Refunded')) - ); - } + Mage::helper('xmlconnect/customer_order')->addQuantityToXml($this, $itemXml->addChild('qty'), $item); - // Subtotal excluding tax /** @var $subtotalXml Mage_XmlConnect_Model_Simplexml_Element */ $subtotalXml = $itemXml->addChild('subtotal'); + // Price & subtotal - excluding tax if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) { - - if ($typeOfDisplay014) { - $subtotal = $item->getRowTotal() - + $item->getWeeeTaxAppliedRowAmount() - + $item->getWeeeTaxRowDisposition(); - } else { - $subtotal = $item->getRowTotal(); - } - - $config = array( - 'value' => $this->_formatPrice($subtotal) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Excl. Tax'); - } - - /** @var $exclPriceXml Mage_XmlConnect_Model_Simplexml_Element */ - $exclPriceXml = $subtotalXml->addCustomChild( - 'excluding_tax', - null, - $config - ); - - if ($weeeTaxes) { - if ($typeOfDisplay1) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount']), - array('label' => $tax['title']) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount_incl_tax']), - array('label' => $tax['title']) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $exclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice( - $item->getRowTotal() - + $item->getWeeeTaxAppliedRowAmount() - + $item->getWeeeTaxRowDisposition() - ), - array('label' => $weeeHelper->__('Total')) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } + Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml($this, $item, $priceXml, $subtotalXml); } - // Subtotal including tax + // Price & subtotal - including tax if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) { - $incl = $this->helper('checkout')->getSubtotalInclTax($item); - - if ($typeOfDisplay014) { - $subtotal = $incl + $item->getWeeeTaxAppliedRowAmount(); - } else { - $subtotal = $incl - $item->getWeeeTaxRowDisposition(); - } - - $config = array( - 'value' => $this->_formatPrice($subtotal) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Incl. Tax'); - } - - /** @var $inclPriceXml Mage_XmlConnect_Model_Simplexml_Element */ - $inclPriceXml = $subtotalXml->addCustomChild( - 'including_tax', - null, - $config + Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml( + $this, $item, $priceXml, $subtotalXml, true ); - - if ($weeeTaxes) { - if ($typeOfDisplay1) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount']), - array('label' => $tax['title']) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount_incl_tax']), - array('label' => $tax['title']) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $inclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice($incl + $item->getWeeeTaxAppliedRowAmount()), - array('label' => $weeeHelper->__('Total incl. tax')) - ); - } - } } } - - /** - * Format price using order currency - * - * @param float $price - * @return string - */ - protected function _formatPrice($price) - { - return $this->getOrder()->getOrderCurrency()->formatPrecision($price, 2, array(), false); - } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Downloadable.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Downloadable.php index 2b9ca910ef..b6f00368e0 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Downloadable.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Downloadable.php @@ -36,9 +36,10 @@ class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Downloadable { /** * Add item to XML object + * (get from template: downloadable/sales/order/items/renderer/downloadable.phtml) * * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj - * @return void + * @return null */ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) { @@ -46,13 +47,9 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde $item = $this->getItem(); /** @var $itemXml Mage_XmlConnect_Model_Simplexml_Element */ - $itemXml = $orderItemXmlObj->addCustomChild( - 'item', - null, - array( - 'product_id' => $item->getProductId() - ) - ); + $itemXml = $orderItemXmlObj->addCustomChild('item', null, array( + 'product_id' => $item->getProductId() + )); $itemXml->addCustomChild('name', $item->getName()); /** @var $weeeHelper Mage_Weee_Helper_Data */ @@ -60,47 +57,19 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde /** @var $taxHelper Mage_Tax_Helper_Data */ $taxHelper = $this->helper('tax'); - $options = $this->getItemOptions(); - if ($options) { - /** @var $optionsXml Mage_XmlConnect_Model_Simplexml_Element */ - $optionsXml = $itemXml->addChild('options'); - foreach ($options as $option) { - $formatedOptionValue = $this->getFormatedOptionValue($option); - if (isset($formatedOptionValue['full_view']) && isset($formatedOptionValue['value'])) { - $value = $formatedOptionValue['value']; - } elseif (isset($option['print_value'])) { - $value = $option['print_value']; - } else { - $value = $option['value']; - } - $optionsXml->addCustomChild( - 'option', - strip_tags($value), - array( - 'label' => $option['label'] - ) - ); - } + Mage::helper('xmlconnect/customer_order')->addItemOptionsToXml($this, $itemXml); - $addtInfoBlock = $this->getProductAdditionalInformationBlock(); - if ($addtInfoBlock) { - // TODO: find how to set additional info block - // $addtInfoBlock->setItem($item)->toHtml(); - } + $addtInfoBlock = $this->getProductAdditionalInformationBlock(); + if ($addtInfoBlock) { + // TODO: find how to set additional info block + // $addtInfoBlock->setItem($item)->toHtml(); } $links = $this->getLinks(); if ($links) { - $linksXml = $itemXml->addCustomChild( - 'links', - null, - array('label' => $this->getLinksTitle()) - ); + $linksXml = $itemXml->addCustomChild('links', null, array('label' => $this->getLinksTitle())); foreach ($links->getPurchasedItems() as $link) { - $linksXml->addCustomChild( - 'link', - $link->getLinkTitle() - ); + $linksXml->addCustomChild('link', $link->getLinkTitle()); } } @@ -110,342 +79,48 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde /** @var $priceXml Mage_XmlConnect_Model_Simplexml_Element */ $priceXml = $itemXml->addChild('price'); - $weeeTaxAppliedAmount = (float)$item->getWeeeTaxAppliedAmount(); - $weeeTaxDisposition = (float)$item->getWeeeTaxDisposition(); - $typeOfDisplay1 = $weeeHelper->typeOfDisplay($item, 1, 'sales') && $weeeTaxAppliedAmount; - $typeOfDisplay2 = $weeeHelper->typeOfDisplay($item, 2, 'sales') && $weeeTaxAppliedAmount; - $typeOfDisplay4 = $weeeHelper->typeOfDisplay($item, 4, 'sales') && $weeeTaxAppliedAmount; - $typeOfDisplay014 = $weeeHelper->typeOfDisplay($item, array(0, 1, 4), 'sales') && $weeeTaxAppliedAmount; - $weeeTaxes = $weeeHelper->getApplied($item); - - // Price excluding tax - if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) { - if ($typeOfDisplay014) { - $price = $item->getPrice() + $weeeTaxAppliedAmount + $weeeTaxDisposition; - } else { - $price = $item->getPrice(); - } - - $config = array( - 'value' => $this->_formatPrice($price) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Excl. Tax'); - } - - /** @var $exclPriceXml Mage_XmlConnect_Model_Simplexml_Element */ - $exclPriceXml = $priceXml->addCustomChild( - 'excluding_tax', - null, - $config - ); - - if ($weeeTaxes) { - /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */ - if ($typeOfDisplay1) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount']), - array( - 'label' => $tax['title'] - ) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount_incl_tax']), - array( - 'label' => $tax['title'] - ) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $exclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice( - $item->getPrice() + $weeeTaxAppliedAmount + $weeeTaxDisposition - ), - array( - 'label' => $weeeHelper->__('Total') - ) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } - } - - // Price including tax - if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) { - $incl = $this->helper('checkout')->getPriceInclTax($item); - - if ($typeOfDisplay014) { - $price = $incl + $weeeTaxAppliedAmount; - } else { - $price = $incl - $weeeTaxDisposition; - } - - $config = array( - 'value' => $this->_formatPrice($price) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Incl. Tax'); - } - - /** @var $inclPriceXml Mage_XmlConnect_Model_Simplexml_Element */ - $inclPriceXml = $priceXml->addCustomChild( - 'including_tax', - null, - $config - ); - - if ($weeeTaxes) { - /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */ - if ($typeOfDisplay1) { - $weeeXml = $inclPriceXml->tddChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount']), - array( - 'label' => $tax['title'] - ) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $inclPriceXml->tddChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['amount_incl_tax']), - array( - 'label' => $tax['title'] - ) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $inclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice($incl + $weeeTaxAppliedAmount), - array( - 'label' => $weeeHelper->__('Total incl. tax') - ) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } - } // Quantity: Ordered, Shipped, Cancelled, Refunded - /** @var $quantityXml Mage_XmlConnect_Model_Simplexml_Element */ - $quantityXml = $itemXml->addChild('qty'); - $qty = 1 * $item->getQtyOrdered(); - if ($qty > 0) { - $quantityXml->addCustomChild( - 'value', - $qty, - array( - 'label' => $this->__('Ordered') - ) - ); - } - $qty = 1 * $item->getQtyShipped(); - if ($qty > 0) { - $quantityXml->addCustomChild( - 'value', - $qty, - array( - 'label' => $this->__('Shipped') - ) - ); - } - $qty = 1 * $item->getQtyCanceled(); - if ($qty > 0) { - $quantityXml->addCustomChild( - 'value', - $qty, - array( - 'label' => $this->__('Canceled') - ) - ); - } - $qty = 1 * $item->getQtyRefunded(); - if ($qty > 0) { - $quantityXml->addCustomChild( - 'value', - $qty, - array( - 'label' => $this->__('Refunded') - ) - ); - } + Mage::helper('xmlconnect/customer_order')->addQuantityToXml($this, $itemXml->addChild('qty'), $item); - // Subtotal excluding tax /** @var $subtotalXml Mage_XmlConnect_Model_Simplexml_Element */ $subtotalXml = $itemXml->addChild('subtotal'); + $this->setWeeeTaxAppliedAmount($item->getWeeeTaxAppliedAmount()); + $this->setWeeeTaxDisposition($item->getWeeeTaxDisposition()); + + $typeOfDisplay1 = $weeeHelper->typeOfDisplay($item, 1, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay2 = $weeeHelper->typeOfDisplay($item, 2, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay4 = $weeeHelper->typeOfDisplay($item, 4, 'sales') + && $this->getWeeeTaxAppliedAmount(); + $typeOfDisplay014 = $weeeHelper->typeOfDisplay($item, array(0, 1, 4), 'sales') + && $this->getWeeeTaxAppliedAmount(); + + $this->setTypesOfDisplay(array( + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_1 => $typeOfDisplay1, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_2 => $typeOfDisplay2, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_4 => $typeOfDisplay4, + Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_14 => $typeOfDisplay014, + )); + $this->setWeeeTaxes($weeeHelper->getApplied($item)); + + // Price & subtotal - excluding tax if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) { - - if ($typeOfDisplay014) { - $subtotal = $item->getRowTotal() - + $item->getWeeeTaxAppliedRowAmount() - + $item->getWeeeTaxRowDisposition(); - } else { - $subtotal = $item->getRowTotal(); - } - - $config = array( - 'value' => $this->_formatPrice($subtotal) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Excl. Tax'); - } - - /** @var $exclPriceXml Mage_XmlConnect_Model_Simplexml_Element */ - $exclPriceXml = $subtotalXml->addCustomChild( - 'excluding_tax', - null, - $config + Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml( + $this, + $item, + $priceXml, + $subtotalXml ); - - if ($weeeTaxes) { - if ($typeOfDisplay1) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount']), - array( - 'label' => $tax['title'] - ) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $exclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount_incl_tax']), - array( - 'label' => $tax['title'] - ) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $exclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice( - $item->getRowTotal() - + $item->getWeeeTaxAppliedRowAmount() - + $item->getWeeeTaxRowDisposition() - ), - array( - 'label' => $weeeHelper->__('Total') - ) - ); - } - if (isset($weeeXml)) { - unset($weeeXml); - } - } } - // Subtotal including tax + // Price & subtotal - including tax if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) { - $incl = $this->helper('checkout')->getSubtotalInclTax($item); - - if ($typeOfDisplay014) { - $subtotal = $incl + $item->getWeeeTaxAppliedRowAmount(); - } else { - $subtotal = $incl - $item->getWeeeTaxRowDisposition(); - } - - $config = array( - 'value' => $this->_formatPrice($subtotal) - ); - if ($taxHelper->displaySalesBothPrices()) { - $config['label'] = $this->__('Incl. Tax'); - } - - /** @var $inclPriceXml Mage_XmlConnect_Model_Simplexml_Element */ - $inclPriceXml = $subtotalXml->addCustomChild( - 'including_tax', - null, - $config + Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml( + $this, $item, $priceXml, $subtotalXml, true ); - - if ($weeeHelper->getApplied($item)) { - if ($typeOfDisplay1) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount']), - array( - 'label' => $tax['title'] - ) - ); - } - } elseif ($typeOfDisplay2 || $typeOfDisplay4) { - $weeeXml = $inclPriceXml->addChild('weee'); - foreach ($weeeTaxes as $tax) { - $weeeXml->addCustomChild( - 'tax', - $this->_formatPrice($tax['row_amount_incl_tax']), - array( - 'label' => $tax['title'] - ) - ); - } - } - - if ($typeOfDisplay2) { - if (!isset($weeeXml)) { - $weeeXml = $inclPriceXml->addChild('weee'); - } - $weeeXml->addCustomChild( - 'total', - $this->_formatPrice($incl + $item->getWeeeTaxAppliedRowAmount()), - array( - 'label' => $weeeHelper->__('Total incl. tax') - ) - ); - } - } } } - - /** - * Format price using order currency - * - * @param float $price - * @return string - */ - protected function _formatPrice($price) - { - return $this->getOrder()->getOrderCurrency()->formatPrecision($price, 2, array(), false); - } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Giftcard.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Giftcard.php index b635e7e374..0b700a2d12 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Giftcard.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Giftcard.php @@ -62,16 +62,17 @@ protected function _getNameEmailString($name, $email) /** * Add item to XML object + * (get from template: sales/order/items/renderer/default.phtml) * * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj - * @return void + * @return null */ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) { $item = $this->getOrderItem(); $item->setProductOptions(array('additional_options' => $this->getItemOptions())); - $defaultRenderer = $this->getLayout()->getBlock('xmlconnect.customer.order.items')->getItemRenderer(); + $defaultRenderer = $this->getLayout()->getBlock('xmlconnect.customer.order.items')->getItemRenderer(null); $defaultRenderer->setItem($item); $defaultRenderer->addItemToXmlObject($orderItemXmlObj); } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Grouped.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Grouped.php index 4cbce05dc5..d7fe114c3b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Grouped.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Item/Renderer/Grouped.php @@ -31,8 +31,7 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Grouped - extends Mage_Sales_Block_Order_Item_Renderer_Grouped +class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Grouped extends Mage_Sales_Block_Order_Item_Renderer_Grouped { /** * Default product type @@ -41,9 +40,10 @@ class Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Grouped /** * Add item to XML object + * (get from template: sales/order/items/renderer/default.phtml) * * @param Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj - * @return void + * @return null */ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj) { @@ -55,7 +55,6 @@ public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orde } $renderer = $this->getRenderedBlock()->getItemRenderer($productType); $renderer->setItem($this->getItem()); - $renderer->addItemToXmlObject($orderItemXmlObj); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Items.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Items.php index c34a128482..536d420611 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Items.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Items.php @@ -39,25 +39,7 @@ class Mage_XmlConnect_Block_Customer_Order_Items extends Mage_Sales_Block_Order_ protected function _construct() { parent::_construct(); - $this->addItemRender('default', 'xmlconnect/customer_order_item_renderer_default'); - } - - /** - * Add renderer for item product type - * - * @param string $type - * @param string $block - * @param string $template - * @return Mage_Checkout_Block_Cart_Abstract - */ - public function addItemRender($type, $block, $template = '') - { - $this->_itemRenders[$type] = array( - 'block' => $block, - 'renderer' => null - ); - - return $this; + $this->addItemRender('default', 'xmlconnect/customer_order_item_renderer_default', null); } /** @@ -66,25 +48,25 @@ public function addItemRender($type, $block, $template = '') * @param string $type * @return Mage_Core_Block_Abstract */ - public function getItemRenderer($type = 'default') + public function getItemRenderer($type) { - if (!isset($this->_itemRenders[$type])) { + if (empty($type) || !isset($this->_itemRenders[$type])) { $type = 'default'; } if (is_null($this->_itemRenders[$type]['renderer'])) { $this->_itemRenders[$type]['renderer'] = $this->getLayout() - ->createBlock($this->_itemRenders[$type]['block']) - ->setRenderedBlock($this); + ->createBlock($this->_itemRenders[$type]['block'])->setRenderedBlock($this); } return $this->_itemRenders[$type]['renderer']; } /** * Render XML for items + * (get from template: sales/order/items.phtml) * * @param Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj - * @return void + * @return null */ public function addItemsToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj) { diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php index 27e12330be..90734f5fe9 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php @@ -47,19 +47,13 @@ protected function _toHtml() { $ordersXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); - $orders = Mage::getResourceModel('sales/order_collection') - ->addFieldToSelect('*') - ->addFieldToFilter( - 'customer_id', - Mage::getSingleton('customer/session')->getCustomer()->getId() - ) - ->addFieldToFilter( - 'state', - array( - 'in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates() - ) - ) - ->setOrder('created_at', 'desc'); + $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter( + 'customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId() + ) + ->addFieldToFilter( + 'state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()) + ) + ->setOrder('created_at', 'desc'); $orders->getSelect()->limit(self::ORDERS_LIST_LIMIT, 0); $orders->load(); @@ -71,21 +65,11 @@ protected function _toHtml() $item->addChild('number', $_order->getRealOrderId()); $item->addChild('date', $this->formatDate($_order->getCreatedAtStoreDate())); if ($_order->getShippingAddress()) { - $item->addChild( - 'ship_to', - $ordersXmlObj->xmlentities($_order->getShippingAddress()->getName()) - ); + $item->addChild('ship_to', $ordersXmlObj->xmlentities($_order->getShippingAddress()->getName())); } - $item->addChild( - 'total', - $_order->getOrderCurrency()->formatPrecision( - $_order->getGrandTotal(), - 2, - array(), - false, - false - ) - ); + $item->addChild('total', $_order->getOrderCurrency()->formatPrecision( + $_order->getGrandTotal(), 2, array(), false, false + )); $item->addChild('status', $_order->getStatusLabel()); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals.php index 55684e9a5b..5f0a980e68 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals.php @@ -35,9 +35,10 @@ class Mage_XmlConnect_Block_Customer_Order_Totals extends Mage_Sales_Block_Order { /** * Add order totals rendered to XML object + * (get from template: sales/order/totals.phtml) * * @param Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj - * @return void + * @return null */ public function addTotalsToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj) { @@ -112,20 +113,13 @@ public function addTotalsToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $or * * @param Varien_Object $total * @param Mage_XmlConnect_Model_Simplexml_Element $totalsXml - * @return void + * @return null */ private function _addTotalToXml($total, Mage_XmlConnect_Model_Simplexml_Element $totalsXml) { - if ( - $total instanceof Varien_Object - && $total->getCode() - && $total->getLabel() - && $total->hasData('value') - ) { - $totalsXml->addCustomChild( - preg_replace('@[\W]+@', '_', trim($total->getCode())), - $this->_formatPrice($total), - array('label' => strip_tags($total->getLabel())) + if ($total instanceof Varien_Object && $total->getCode() && $total->getLabel() && $total->hasData('value')) { + $totalsXml->addCustomChild(preg_replace('@[\W]+@', '_', trim($total->getCode())), + $this->_formatPrice($total), array('label' => strip_tags($total->getLabel())) ); } } @@ -139,7 +133,7 @@ private function _addTotalToXml($total, Mage_XmlConnect_Model_Simplexml_Element protected function _formatPrice($total) { if (!$total->getIsFormated()) { - return $this->getOrder()->getOrderCurrency()->formatPrecision($total->getValue(), 2, array(), false); + return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $total->getValue()); } return $total->getValue(); } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance.php index 53ade18541..7bed9048b3 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance.php @@ -38,15 +38,13 @@ class Mage_XmlConnect_Block_Customer_Order_Totals_Customerbalance * Add order total rendered to XML object * * @param $totalsXml Mage_XmlConnect_Model_Simplexml_Element - * @return void + * @return null */ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXml) { $balance = $this->getSource()->getCustomerBalanceAmount(); if ($balance) { - $totalsXml->addCustomChild( - $this->getTotal()->getCode(), - '-' . $this->_formatPrice($balance), + $totalsXml->addCustomChild($this->getTotal()->getCode(), '-' . $this->_formatPrice($balance), array('label' => Mage::helper('enterprise_giftcardaccount')->__('Store Credit')) ); } @@ -60,6 +58,6 @@ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXm */ protected function _formatPrice($amount) { - return $this->getOrder()->getOrderCurrency()->formatPrecision($amount, 2, array(), false); + return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $amount); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance/Refunded.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance/Refunded.php index 3843036ba6..4faca89b0a 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance/Refunded.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Customerbalance/Refunded.php @@ -38,15 +38,13 @@ class Mage_XmlConnect_Block_Customer_Order_Totals_Customerbalance_Refunded * Add order total rendered to XML object * * @param $totalsXml Mage_XmlConnect_Model_Simplexml_Element - * @return void + * @return null */ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXml) { $balance = $this->getSource()->getCustomerBalanceTotalRefunded(); if ($balance) { - $totalsXml->addCustomChild( - $this->getTotal()->getCode(), - $this->_formatPrice($balance), + $totalsXml->addCustomChild($this->getTotal()->getCode(), $this->_formatPrice($balance), array('label' => Mage::helper('enterprise_giftcardaccount')->__('Refunded to Store Credit')) ); } @@ -60,6 +58,6 @@ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXm */ protected function _formatPrice($amount) { - return $this->getOrder()->getOrderCurrency()->formatPrecision($amount, 2, array(), false); + return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $amount); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Giftcards.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Giftcards.php index 12af538af5..68d24a0206 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Giftcards.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Giftcards.php @@ -38,7 +38,7 @@ class Mage_XmlConnect_Block_Customer_Order_Totals_Giftcards * Add order total rendered to XML object * * @param $totalsXml Mage_XmlConnect_Model_Simplexml_Element - * @return void + * @return null */ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXml) { @@ -46,18 +46,14 @@ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXm if ($cards) { foreach ($cards as $card) { $label = Mage::helper('enterprise_giftcardaccount')->__('Gift Card (%s)', $card->getCode()); - $totalsXml->addCustomChild( - $this->getTotal()->getCode(), - '-' . $this->_formatPrice($card->getAmount()), + $totalsXml->addCustomChild($this->getTotal()->getCode(), '-' . $this->_formatPrice($card->getAmount()), array('label' => $label) ); } } else { $cardsAmount = $this->getSource()->getGiftCardsAmount(); if ($cardsAmount > 0) { - $totalsXml->addCustomChild( - $this->getTotal()->getCode(), - '-' . $this->_formatPrice($cardsAmount), + $totalsXml->addCustomChild($this->getTotal()->getCode(), '-' . $this->_formatPrice($cardsAmount), array('label' => Mage::helper('enterprise_giftcardaccount')->__('Gift Card')) ); } @@ -72,6 +68,6 @@ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXm */ protected function _formatPrice($amount) { - return $this->getOrder()->getOrderCurrency()->formatPrecision($amount, 2, array(), false); + return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $amount); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Tax.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Tax.php index 563a2fa301..328aaad6a0 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Tax.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals/Tax.php @@ -37,7 +37,7 @@ class Mage_XmlConnect_Block_Customer_Order_Totals_Tax extends Mage_Tax_Block_Sal * Add order taxes rendered to XML object * * @param Mage_XmlConnect_Model_Simplexml_Element $totalsXmlObj - * @return void + * @return null */ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXmlObj) { @@ -54,16 +54,12 @@ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXm foreach ((array)$info['rates'] as $rate) { if (isset($info['amount'])) { - $config = array( - 'label' => $rate['title'] - ); + $config = array('label' => $rate['title']); if (!is_null($rate['percent'])) { - $config['percent'] = '(' . (float)$rate['percent'] . '%)'; + $config['percent'] = sprintf('(%0.2f%%)', $rate['percent']); } $taxesXmlObj->addCustomChild( - 'item', - is_null($rate['percent']) ? '' : $this->_formatPrice($info['amount']), - $config + 'item', is_null($rate['percent']) ? '' : $this->_formatPrice($info['amount']), $config ); } } @@ -71,11 +67,7 @@ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXm } $taxesXmlObj->addCustomChild( - 'summary', - $this->_formatPrice($this->getSource()->getTaxAmount()), - array( - 'label' => $this->__('Tax') - ) + 'summary', $this->_formatPrice($this->getSource()->getTaxAmount()), array('label' => $this->__('Tax')) ); } @@ -87,6 +79,6 @@ public function addToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $totalsXm */ protected function _formatPrice($amount) { - return $this->getOrder()->getOrderCurrency()->formatPrecision($amount, 2, array(), false); + return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $amount); } } diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Storecredit.php b/app/code/core/Mage/XmlConnect/Block/Customer/Storecredit.php new file mode 100644 index 0000000000..2412011ac0 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Storecredit.php @@ -0,0 +1,91 @@ + + */ +class Mage_XmlConnect_Block_Customer_Storecredit extends Mage_Core_Block_Template +{ + /** + * Render customer store credits xml + * + * @return string + */ + protected function _toHtml() + { + /** @var $xmlModel Mage_XmlConnect_Model_Simplexml_Element */ + $xmlModel = Mage::getModel('xmlconnect/simplexml_element', ''); + + $accountBalance = $this->getLayout() + ->addBlock('enterprise_customerbalance/account_balance', 'account_balance'); + + $customerBalanceHelper = Mage::helper('enterprise_customerbalance'); + + $xmlModel->addCustomChild('balance', null, array( + 'label' => $customerBalanceHelper->__('Your current balance is:'), + 'value' => $accountBalance->getBalance(), + 'formatted_value' => Mage::helper('core')->currency($accountBalance->getBalance(), true, false) + )); + + $accountHistory = $this->getLayout() + ->addBlock('enterprise_customerbalance/account_history', 'account_history'); + + if ($accountHistory->canShow() && $accountHistory->getEvents() && count($accountHistory->getEvents())) { + $balanceHistory = $xmlModel->addCustomChild('balance_history', null, array( + 'label' => $customerBalanceHelper->__('Balance History'), + 'action_label' => $customerBalanceHelper->__('Action'), + 'balance_change_label' => $customerBalanceHelper->__('Balance Change'), + 'balance_label' => $customerBalanceHelper->__('Balance'), + 'date_label' => $customerBalanceHelper->__('Date') + )); + + foreach ($accountHistory->getEvents() as $event) { + $item = $balanceHistory->addCustomChild('item'); + $item->addCustomChild('action', null, array( + 'value' => $accountHistory->getActionLabel($event->getAction()) + )); + + $item->addCustomChild('balance_change', null, array( + 'value' => Mage::helper('core')->currency($event->getBalanceDelta(), true, false) + )); + + $item->addCustomChild('balance', null, array( + 'value' => Mage::helper('core')->currency($event->getBalanceAmount(), true, false) + )); + + $item->addCustomChild('date', null, array( + 'value' => Mage::helper('core')->formatDate($event->getUpdatedAt(), 'short', true) + )); + } + } + + return $xmlModel->asNiceXml(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Home.php b/app/code/core/Mage/XmlConnect/Block/Home.php index f2f4aa48d6..af9a7d34ae 100644 --- a/app/code/core/Mage/XmlConnect/Block/Home.php +++ b/app/code/core/Mage/XmlConnect/Block/Home.php @@ -50,13 +50,13 @@ protected function _toHtml() $categoryCollection = array(); $helper = Mage::helper('catalog/category'); - $i = 0; + $categoryCount = 0; foreach ($helper->getStoreCategories() as $child) { if ($child->getIsActive()) { $categoryCollection[] = $child; - $i++; + $categoryCount++; } - if ($i == self::HOME_PAGE_CATEGORIES_COUNT) { + if ($categoryCount == self::HOME_PAGE_CATEGORIES_COUNT) { break; } } @@ -69,16 +69,14 @@ protected function _toHtml() /** @var $item Mage_Catalog_Model_Category */ $item = Mage::getModel('catalog/category')->load($item->getId()); $itemXmlObj = $itemsXmlObj->addChild('item'); - $itemXmlObj->addChild('label', $homeXmlObj->xmlentities(strip_tags($item->getName()))); + $itemXmlObj->addChild('label', $homeXmlObj->xmlentities($item->getName())); $itemXmlObj->addChild('entity_id', $item->getId()); $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products'); $icon = Mage::helper('xmlconnect/catalog_category_image')->initialize($item, 'thumbnail') ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('category')); $iconXml = $itemXmlObj->addChild('icon', $icon); - $file = Mage::helper('xmlconnect')->urlToPath($icon); - $iconXml->addAttribute('modification_time', filemtime($file)); } $homeXmlObj->addChild('home_banner', '/current/media/catalog/category/banner_home.png'); diff --git a/app/code/core/Mage/XmlConnect/Block/Review/Form.php b/app/code/core/Mage/XmlConnect/Block/Review/Form.php index 21dfdaee5e..5e55d76826 100644 --- a/app/code/core/Mage/XmlConnect/Block/Review/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Review/Form.php @@ -27,9 +27,9 @@ /** * Product review form xml renderer * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Block_Review_Form extends Mage_Core_Block_Template { @@ -55,27 +55,19 @@ protected function _toHtml() $nickname = ''; if ($customer->getId()) { - $nickname = strip_tags($customer->getFirstname()); + $nickname = $xmlReview->xmlentities($customer->getFirstname()); } if ($this->getRatings()) { - $ratingsFieldset = $xmlReview->addCustomChild( - 'fieldset', - null, - array( - 'label' => $this->__('How do you rate this product?') - ) - ); + $ratingsFieldset = $xmlReview->addCustomChild('fieldset', null, array( + 'label' => $this->__('How do you rate this product?') + )); foreach ($this->getRatings() as $rating) { - $ratingField = $ratingsFieldset->addField( - 'ratings[' . $rating->getId() . ']', - 'radio', - array( - 'label' => $rating->getRatingCode(), - 'required' => 'true' - ) - ); + $ratingField = $ratingsFieldset->addField('ratings[' . $rating->getId() . ']', 'radio', array( + 'label' => $rating->getRatingCode(), + 'required' => 'true' + )); foreach ($rating->getOptions() as $option) { $ratingField->addCustomChild('value', $option->getId()); } @@ -83,31 +75,19 @@ protected function _toHtml() } $reviewFieldset = $xmlReview->addCustomChild('fieldset'); - $reviewFieldset->addField( - 'nickname', - 'text', - array( - 'label' => $this->__('Nickname'), - 'required' => 'true', - 'value' => $nickname - ) - ); - $reviewFieldset->addField( - 'title', - 'text', - array( - 'label' => $this->__('Summary of Your Review'), - 'required' => 'true' - ) - ); - $reviewFieldset->addField( - 'detail', - 'textarea', - array( - 'label' => $this->__('Review'), - 'required' => 'true' - ) - ); + $reviewFieldset->addField('nickname', 'text', array( + 'label' => $this->__('Nickname'), + 'required' => 'true', + 'value' => $nickname + )); + $reviewFieldset->addField('title', 'text', array( + 'label' => $this->__('Summary of Your Review'), + 'required' => 'true' + )); + $reviewFieldset->addField('detail', 'textarea', array( + 'label' => $this->__('Review'), + 'required' => 'true' + )); return $xmlReview->asNiceXml(); } @@ -120,14 +100,9 @@ protected function _toHtml() public function getRatings() { if (is_null($this->_ratings)) { - $this->_ratings = Mage::getModel('rating/rating') - ->getResourceCollection() - ->addEntityFilter('product') - ->setPositionOrder() - ->addRatingPerStoreName(Mage::app()->getStore()->getId()) - ->setStoreFilter(Mage::app()->getStore()->getId()) - ->load() - ->addOptionToItems(); + $this->_ratings = Mage::getModel('rating/rating')->getResourceCollection()->addEntityFilter('product') + ->setPositionOrder()->addRatingPerStoreName(Mage::app()->getStore()->getId()) + ->setStoreFilter(Mage::app()->getStore()->getId())->load()->addOptionToItems(); if (!$this->_ratings->getSize()) { $this->_ratings = false; diff --git a/app/code/core/Mage/XmlConnect/Block/Wishlist.php b/app/code/core/Mage/XmlConnect/Block/Wishlist.php index c8866a0804..f2ca53bf46 100644 --- a/app/code/core/Mage/XmlConnect/Block/Wishlist.php +++ b/app/code/core/Mage/XmlConnect/Block/Wishlist.php @@ -40,8 +40,8 @@ class Mage_XmlConnect_Block_Wishlist extends Mage_Wishlist_Block_Customer_Wishli */ protected function _toHtml() { + /** @var Mage_XmlConnect_Model_Simplexml_Element $wishlistXmlObj */ $wishlistXmlObj = Mage::getModel('xmlconnect/simplexml_element', ''); - $hasMoreItems = 0; /** * Apply offset and count */ @@ -50,6 +50,7 @@ protected function _toHtml() $count = (int)$request->getParam('count', 0); $offset = $offset < 0 ? 0 : $offset; $count = $count <= 0 ? 1 : $count; + $hasMoreItems = 0; if ($offset + $count < $this->getWishlistItems()->getSize()) { $hasMoreItems = 1; } @@ -67,12 +68,11 @@ protected function _toHtml() $itemXmlObj = $wishlistXmlObj->addChild('item'); $itemXmlObj->addChild('item_id', $item->getWishlistItemId()); - $itemXmlObj->addChild('entity_id', $item->getProductId()); $itemXmlObj->addChild('entity_type_id', $item->getProduct()->getTypeId()); - $itemXmlObj->addChild('name', $wishlistXmlObj->xmlentities(strip_tags($item->getName()))); - $itemXmlObj->addChild('in_stock', (int)$item->getProduct()->isInStock()); - $itemXmlObj->addChild('is_salable', (int)$item->getProduct()->getIsSalable()); + $itemXmlObj->addChild('name', $wishlistXmlObj->xmlentities($item->getName())); + $itemXmlObj->addChild('in_stock', (int)$item->getProduct()->getIsInStock()); + $itemXmlObj->addChild('is_salable', (int)$item->getProduct()->isSalable()); /** * If product type is grouped than it has options as its grouped items */ @@ -96,8 +96,7 @@ protected function _toHtml() $itemXmlObj->addChild('added_date', $addedDate); if ($this->getChild('product_price')) { - $this->getChild('product_price')->setProduct($item->getProduct()) - ->setProductXmlObj($itemXmlObj) + $this->getChild('product_price')->setProduct($item->getProduct())->setProductXmlObj($itemXmlObj) ->collectProductPrices(); } diff --git a/app/code/core/Mage/XmlConnect/Controller/Action.php b/app/code/core/Mage/XmlConnect/Controller/Action.php index fdf5625d18..670aeb9cb3 100644 --- a/app/code/core/Mage/XmlConnect/Controller/Action.php +++ b/app/code/core/Mage/XmlConnect/Controller/Action.php @@ -62,7 +62,7 @@ abstract class Mage_XmlConnect_Controller_Action extends Mage_Core_Controller_Fr * Declare content type header * Validate current application * - * @return void + * @return null */ public function preDispatch() { @@ -78,8 +78,7 @@ public function preDispatch() $screenSize = isset($_COOKIE[$screenSizeCookieName]) ? (string) $_COOKIE[$screenSizeCookieName] : ''; if (!$appCode) { $this->_message( - Mage::helper('xmlconnect')->__('Specified invalid app code.'), - self::MESSAGE_STATUS_ERROR + Mage::helper('xmlconnect')->__('Specified invalid app code.'), self::MESSAGE_STATUS_ERROR ); $this->setFlag('', self::FLAG_NO_DISPATCH, true); return; @@ -91,8 +90,7 @@ public function preDispatch() && (int)Mage::getStoreConfig('general/restriction/mode') == 0 ) { $this->_message( - Mage::helper('xmlconnect')->__('Website is offline.'), - self::MESSAGE_STATUS_SUCCESS + Mage::helper('xmlconnect')->__('Website is offline.'), self::MESSAGE_STATUS_SUCCESS ); $this->setFlag('', self::FLAG_NO_DISPATCH, true); return; @@ -108,8 +106,7 @@ public function preDispatch() Mage::register('current_app', $appModel); } else { $this->_message( - Mage::helper('xmlconnect')->__('Specified invalid app code.'), - self::MESSAGE_STATUS_ERROR + Mage::helper('xmlconnect')->__('Specified invalid app code.'), self::MESSAGE_STATUS_ERROR ); $this->setFlag('', self::FLAG_NO_DISPATCH, true); return; @@ -119,7 +116,7 @@ public function preDispatch() /** * Validate response body * - * @return void + * @return null */ public function postDispatch() { @@ -138,16 +135,20 @@ public function postDispatch() * * @param string $text * @param string $status - * @param string $type - * @param string $action - * @return void + * @param array $children + * @return null */ - protected function _message($text, $status, $type='', $action='') + protected function _message($text, $status, $children = array()) { /** @var $message Mage_XmlConnect_Model_Simplexml_Element */ $message = Mage::getModel('xmlconnect/simplexml_element', ''); - $message->addChild('status', $status); - $message->addChild('text', $text); + $message->addCustomChild('status', $status); + $message->addCustomChild('text', $text); + + foreach ($children as $node => $value) { + $message->addCustomChild($node, $value); + } + $this->getResponse()->setBody($message->asNiceXml()); } } diff --git a/app/code/core/Mage/XmlConnect/Helper/Android.php b/app/code/core/Mage/XmlConnect/Helper/Android.php index 17ad43f06b..961612bd39 100755 --- a/app/code/core/Mage/XmlConnect/Helper/Android.php +++ b/app/code/core/Mage/XmlConnect/Helper/Android.php @@ -141,7 +141,6 @@ public function getSubmitImages() /** * Get default application tabs * - * @param string * @return array */ public function getDefaultDesignTabs() @@ -196,74 +195,74 @@ public function getDefaultDesignTabs() */ 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', - ), - ), - ), - ); + 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', + ), + ), + ), + ); } /** @@ -492,7 +491,7 @@ public function getFontList() */ public function getFontSizes() { - $result = array( ); + $result = array(); for ($i = 6; $i < 32; $i++) { $result[] = array( 'value' => $i, @@ -560,14 +559,14 @@ public function validateSubmit($params) if (!Zend_Validate::is($resubmissionKey, 'NotEmpty')) { $errors[] = Mage::helper('xmlconnect')->__('Please enter the Resubmission Key.'); - } else if (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) { + } elseif (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) { $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided'); } } else { $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, $keyLenght))) { + } elseif (!Zend_Validate::is($key, 'StringLength', array(1, $keyLenght))) { $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided'); } } @@ -583,10 +582,9 @@ public function validateSubmit($params) public function validateConfig($native) { $errors = array(); - if ( ($native === false) - || (!isset($native['navigationBar']) || !is_array($native['navigationBar']) - || !isset($native['navigationBar']['icon']) - || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty'))) { + if ($native === false || !isset($native['navigationBar']['icon']) + || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty') + ) { $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Logo in Header" field from Design Tab.'); } @@ -672,16 +670,18 @@ public function getAndroidMarketCountriesArray() */ public function checkImages(array $data) { - if (isset($data['conf']['native']['navigationBar']['icon']) && - !file_exists($data['conf']['native']['navigationBar']['icon']) - ) { - $data['conf']['native']['navigationBar']['icon'] = ''; + /** @var $helper Mage_XmlConnect_Helper_Image */ + $helper = Mage::helper('xmlconnect/image'); + + $icon =& $data['conf']['native']['navigationBar']['icon']; + + if (!empty($icon) && !$helper->checkAndGetImagePath($icon)) { + $icon = ''; } - if (isset($data['conf']['native']['body']['bannerAndroidImage']) && - !file_exists($data['conf']['native']['body']['bannerAndroidImage']) - ) { - $data['conf']['native']['body']['bannerAndroidImage'] = ''; + $banner =& $data['conf']['native']['body']['bannerAndroidImage']; + if (!empty($banner) && !$helper->checkAndGetImagePath($banner)) { + $banner = ''; } return $data; } @@ -691,7 +691,7 @@ public function checkImages(array $data) * * @throws Mage_Core_Exception * @param array $data - * @return void + * @return null */ public function checkRequiredConfigFields($data) { @@ -699,19 +699,22 @@ public function checkRequiredConfigFields($data) return; } - if (isset($data['navigationBar']['icon']) - && empty($data['navigationBar']['icon']) - ) { - Mage::throwException( - Mage::helper('xmlconnect')->__('Logo in Header image missing.') - ); + if (isset($data['navigationBar']['icon']) && empty($data['navigationBar']['icon'])) { + Mage::throwException(Mage::helper('xmlconnect')->__('Logo in Header image missing.')); } - if (isset($data['body']['bannerAndroidImage']) - && empty($data['body']['bannerAndroidImage']) - ) { - Mage::throwException( - Mage::helper('xmlconnect')->__('Banner on Home Screen image missing.') - ); + + if (isset($data['body']['bannerAndroidImage']) && empty($data['body']['bannerAndroidImage'])) { + Mage::throwException(Mage::helper('xmlconnect')->__('Banner on Home Screen image missing.')); } } + + /** + * Check the notifications are allowed for current type of application + * + * @return bool + */ + public function isNotificationsAllowed() + { + return true; + } } diff --git a/app/code/core/Mage/XmlConnect/Helper/Customer/Form/Renderer.php b/app/code/core/Mage/XmlConnect/Helper/Customer/Form/Renderer.php new file mode 100644 index 0000000000..ea40a65c31 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Helper/Customer/Form/Renderer.php @@ -0,0 +1,58 @@ + + */ +class Mage_XmlConnect_Helper_Customer_Form_Renderer extends Mage_Core_Helper_Abstract +{ + /** + * Get title and required attributes for a field + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Abstract $fieldsetXmlObj + * @param Enterprise_Customer_Block_Form_Renderer_Abstract $blockObject + * @return array + */ + public function addTitleAndRequiredAttr(Mage_XmlConnect_Model_Simplexml_Form_Abstract $fieldsetXmlObj, + Enterprise_Customer_Block_Form_Renderer_Abstract $blockObject + ) { + $attributes = array(); + + if ($blockObject->isRequired()) { + $attributes += $fieldsetXmlObj->checkAttribute('required', (int)$blockObject->isRequired()); + } + + if ($blockObject->getAdditionalDescription()) { + $attributes += $fieldsetXmlObj->checkAttribute('title', $blockObject->getAdditionalDescription()); + } + + return $attributes; + } +} diff --git a/app/code/core/Mage/XmlConnect/Helper/Customer/Order.php b/app/code/core/Mage/XmlConnect/Helper/Customer/Order.php new file mode 100644 index 0000000000..b588441280 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Helper/Customer/Order.php @@ -0,0 +1,251 @@ + + */ +class Mage_XmlConnect_Helper_Customer_Order extends Mage_Core_Helper_Abstract +{ + /**#@+ + * Price display type + * @see Mage_Weee_Helper_Data::typeOfDisplay(...); + */ + const PRICE_DISPLAY_TYPE_1 = 1; + const PRICE_DISPLAY_TYPE_2 = 2; + const PRICE_DISPLAY_TYPE_4 = 4; + const PRICE_DISPLAY_TYPE_14 = 14; + /**#@-*/ + + /** + * Add Weee taxes child to the XML + * + * @param Mage_Core_Block_Template $renderer Product renderer + * @param Mage_Sales_Model_Order_Item $item + * @param Mage_XmlConnect_Model_Simplexml_Element $priceXml + * @param Mage_XmlConnect_Model_Simplexml_Element $subtotalXml + * @param bool $isIncludeTax + * @return null + */ + public function addPriceAndSubtotalToXml(Mage_Core_Block_Template $renderer, Mage_Sales_Model_Order_Item $item, + Mage_XmlConnect_Model_Simplexml_Element $priceXml, Mage_XmlConnect_Model_Simplexml_Element $subtotalXml, + $isIncludeTax = false + ) { + $weeeParams = array(); + + $typesOfDisplay = $renderer->getTypesOfDisplay(); + if ($isIncludeTax) { + $nodeName = 'including_tax'; + $nodeLabel = $renderer->__('Incl. Tax'); + + $inclPrice = $renderer->helper('checkout')->getPriceInclTax($item); + $inclSubtotal = $renderer->helper('checkout')->getSubtotalInclTax($item); + + if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_14]) { + $price = $inclPrice + $renderer->getWeeeTaxAppliedAmount(); + $subtotal = $inclSubtotal + $item->getWeeeTaxAppliedRowAmount(); + } else { + $price = $inclPrice - $renderer->getWeeeTaxDisposition(); + $subtotal = $inclSubtotal - $item->getWeeeTaxRowDisposition(); + } + $weeeParams['include'] = $inclPrice; + } else { + $nodeName = 'excluding_tax'; + $nodeLabel = $renderer->__('Excl. Tax'); + + if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_14]) { + $price = $item->getPrice() + $renderer->getWeeeTaxAppliedAmount() + + $renderer->getWeeeTaxDisposition(); + $subtotal = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount() + + $item->getWeeeTaxRowDisposition(); + } else { + $price = $item->getPrice(); + $subtotal = $item->getRowTotal(); + } + } + + $configNode = array( + 'value' => $this->formatPrice($renderer, $price) + ); + if ($renderer->helper('tax')->displaySalesBothPrices()) { + $configNode['label'] = $nodeLabel; + } + + $this->addWeeeTaxesToPriceXml( + $renderer, $item, $priceXml->addCustomChild($nodeName, null, $configNode), $weeeParams + ); + + $configNode['value'] = $this->formatPrice($renderer, $subtotal); + $weeeParams['include'] = $isIncludeTax ? $inclSubtotal : null; + $weeeParams['is_subtotal'] = true; + $this->addWeeeTaxesToPriceXml( + $renderer, $item, $subtotalXml->addCustomChild($nodeName, null, $configNode), $weeeParams + ); + } + + /** + * Add Product options to XML + * + * @param Mage_Core_Block_Template $renderer Product renderer + * @param Mage_XmlConnect_Model_Simplexml_Element $itemXml + * @return null + */ + public function addItemOptionsToXml(Mage_Core_Block_Template $renderer, + Mage_XmlConnect_Model_Simplexml_Element $itemXml + ) { + $options = $renderer->getItemOptions(); + if (!empty($options)) { + $optionsXml = $itemXml->addChild('options'); + + foreach ($options as $option) { + $value = false; + $formatedOptionValue = $renderer->getFormatedOptionValue($option); + if (isset($formatedOptionValue['full_view']) && isset($formatedOptionValue['value'])) { + $value = $formatedOptionValue['value']; + } elseif (isset($option['print_value'])) { + $value = $option['print_value']; + } elseif (isset($option['value'])) { + $value = $option['value']; + } + if ($value) { + $optionsXml->addCustomChild('option', strip_tags($value), array('label' => $option['label'])); + } + } + } + } + + /** + * Add Weee taxes child to the XML + * + * @param Mage_Core_Block_Template $renderer Product renderer + * @param Mage_Sales_Model_Order_Item $item + * @param Mage_XmlConnect_Model_Simplexml_Element $parentXml + * @param array $params Params for Weee taxes: 'include' - Price including tax, 'is_subtotal' - Flag of subtotal + * @return null + */ + public function addWeeeTaxesToPriceXml(Mage_Core_Block_Template $renderer, Mage_Sales_Model_Order_Item $item, + Mage_XmlConnect_Model_Simplexml_Element $parentXml, $params = array() + ) { + $weeTaxes = $renderer->getWeeeTaxes(); + if (empty($weeTaxes)) { + return; + } + + $typesOfDisplay = $renderer->getTypesOfDisplay(); + + $row = isset($params['is_subtotal']) && $params['is_subtotal'] ? 'row_' : ''; + + /** @var $weeeXml Mage_XmlConnect_Model_Simplexml_Element */ + if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_1]) { + $weeeXml = $parentXml->addChild('weee'); + foreach ($weeTaxes as $tax) { + $weeeXml->addCustomChild('tax', $this->formatPrice($renderer, $tax[$row . 'amount']), + array('label' => $tax['title']) + ); + } + } elseif ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_2] || $typesOfDisplay[self::PRICE_DISPLAY_TYPE_4]) { + $weeeXml = $parentXml->addChild('weee'); + foreach ($weeTaxes as $tax) { + $weeeXml->addCustomChild('tax', $this->formatPrice($renderer, $tax[$row . 'amount_incl_tax']), + array('label' => $tax['title']) + ); + } + } + + if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_2]) { + if (!is_null($params['include'])) { + // including tax + if (isset($params['is_subtotal'])) { + $total = $params['include'] + $item->getWeeeTaxAppliedRowAmount(); + } else { + $total = $params['include'] + $renderer->getWeeeTaxAppliedAmount(); + } + } else { + // excluding tax + if ($params['is_subtotal']) { + $total = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount() + + $item->getWeeeTaxRowDisposition(); + } else { + $total = $item->getPrice() + $renderer->getWeeeTaxAppliedAmount() + + $renderer->getWeeeTaxDisposition(); + } + } + + if (!isset($weeeXml)) { + $weeeXml = $parentXml->addChild('weee'); + } + $weeeXml->addCustomChild( + 'total', + $this->formatPrice($renderer, $total), + array('label' => $renderer->helper('weee')->__('Total')) + ); + } + } + + /** + * Add item quantities to the XML + * + * @param Mage_Core_Block_Template $renderer Product renderer + * @param Mage_XmlConnect_Model_Simplexml_Element $quantityXml + * @param Mage_Sales_Model_Order_Item $item + * @return null + */ + public function addQuantityToXml(Mage_Core_Block_Template $renderer, + Mage_XmlConnect_Model_Simplexml_Element $quantityXml, Mage_Sales_Model_Order_Item $item + ) { + $qty = 1 * $item->getQtyOrdered(); + if ($qty > 0) { + $quantityXml->addCustomChild('value', $qty, array('label' => $renderer->__('Ordered'))); + } + $qty = 1 * $item->getQtyShipped(); + if ($qty > 0) { + $quantityXml->addCustomChild('value', $qty, array('label' => $renderer->__('Shipped'))); + } + $qty = 1 * $item->getQtyCanceled(); + if ($qty > 0) { + $quantityXml->addCustomChild('value', $qty, array('label' => $renderer->__('Canceled'))); + } + $qty = 1 * $item->getQtyRefunded(); + if ($qty > 0) { + $quantityXml->addCustomChild('value', $qty, array('label' => $renderer->__('Refunded'))); + } + } + + /** + * Format price using order currency + * + * @param Mage_Core_Block_Template $renderer Product renderer + * @param float $price + * @return string + */ + public function formatPrice(Mage_Core_Block_Template $renderer, $price) + { + return $renderer->getOrder()->getOrderCurrency()->formatPrecision($price, 2, array(), false); + } +} diff --git a/app/code/core/Mage/XmlConnect/Helper/Data.php b/app/code/core/Mage/XmlConnect/Helper/Data.php index c90994cb7a..4b74798e4b 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Data.php +++ b/app/code/core/Mage/XmlConnect/Helper/Data.php @@ -48,9 +48,7 @@ class Mage_XmlConnect_Helper_Data extends Mage_Core_Helper_Abstract * * @var array */ - protected $_excludedXmlConfigKeys = array( - 'notifications/applicationMasterSecret', - ); + protected $_excludedXmlConfigKeys = array('notifications/applicationMasterSecret'); /** * Application names array @@ -194,10 +192,14 @@ public function getApplication() } /** - * Create filter object by key + * Create array with filter model and filter block by key + * + * Create array with: + * - Mage_Catalog_Model_Layer_Filter_Abstract + * - Mage_Catalog_Block_Layer_Filter_Abstract * * @param string $key - * @return Mage_Catalog_Model_Layer_Filter_Abstract + * @return array */ public function getFilterByKey($key) { @@ -215,7 +217,7 @@ public function getFilterByKey($key) $filterModelName = 'catalog/layer_filter_attribute'; break; } - return Mage::getModel($filterModelName); + return array(Mage::getModel($filterModelName), $this->getLayout()->createBlock($filterModelName)); } /** @@ -234,7 +236,7 @@ public function getUrl($route, $params = array()) * Retrieve device specific country options array * * @throws Mage_Core_Exception - * @param bool $isItunes + * @param bool $isItunes deprecated after 1.6.0.0 * @return array */ public function getCountryOptionsArray($isItunes = false) @@ -262,10 +264,8 @@ public function getCountryOptionsArray($isItunes = false) $options = unserialize($cache); } else { if (isset($deviceCountries)) { - $options = Mage::getModel('directory/country') - ->getResourceCollection() - ->addFieldToFilter('country_id', array('in' => $deviceCountries)) - ->loadByStore() + $options = Mage::getModel('directory/country')->getResourceCollection() + ->addFieldToFilter('country_id', array('in' => $deviceCountries))->loadByStore() ->toOptionArray(false); } if (Mage::app()->useCache('config')) { @@ -275,10 +275,7 @@ public function getCountryOptionsArray($isItunes = false) Varien_Profiler::stop('TEST: ' . __METHOD__); if (count($options)) { - $options[] = array( - 'value' => 'NEW_COUNTRIES', - 'label' => 'New Territories As Added' - ); + $options[] = array('value' => 'NEW_COUNTRIES', 'label' => 'New Territories As Added'); } return $options; @@ -333,7 +330,6 @@ public function getDeviceTypeOptions() /** * Get default application tabs * - * @param string * @return array */ public function getDefaultApplicationDesignTabs() @@ -439,8 +435,8 @@ public function htmlize($body) /** * Return select options for xml from array * - * @param array $dataArray - source array - * @param string $info - selected item + * @param array $dataArray source array + * @param string $selected selected item * @return string */ public function getArrayAsXmlItemValues($dataArray, $selected) @@ -570,13 +566,14 @@ public function getMessageTitleLength() public function getApplicationOptions() { $options = array(); + /** @var $app Mage_XmlConnect_Model_Application */ foreach (Mage::getModel('xmlconnect/application')->getCollection() as $app) { - if (self::isTemplateAllowedForApplication($app)) { - $options[] = array('value' => $app->getId(), 'label' => $app->getName()); - } + $options[] = array('value' => $app->getCode(), 'label' => $app->getName()); } if (count($options) > 1) { - $options[] = array('value' => '', 'label' => Mage::helper('xmlconnect')->__('Please Select Application')); + array_unshift($options, array( + 'value' => '', 'label' => Mage::helper('xmlconnect')->__('Please Select Application') + )); } return $options; } @@ -584,7 +581,7 @@ public function getApplicationOptions() /** * Get applications array like `code` as `name` * - * @staticvar array $apps + * @static array $apps * @return array */ public function getApplications() @@ -603,13 +600,12 @@ public function getApplications() * Check if creating AirMail template for the application is allowed * * @param Mage_XmlConnect_Model_Application $application + * @deprecated after 1.6.0.0 * @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; + return true; } /** @@ -626,7 +622,8 @@ public function sendBroadcastMessage(Mage_XmlConnect_Model_Queue $queue) try { $appCode = $queue->getAppCode(); - $app = Mage::getModel('xmlconnect/application')->load($appCode, 'code'); + /** @var $app Mage_XmlConnect_Model_Application */ + $app = Mage::getModel('xmlconnect/application')->loadByCode($appCode); if (!$app->getId()) { Mage::throwException( @@ -634,41 +631,44 @@ public function sendBroadcastMessage(Mage_XmlConnect_Model_Queue $queue) ); } + if (!$app->isNotificationsActive()) { + $queue->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED); + return; + } + $userpwd = $app->getUserpwd(); $sendType = $queue->getData('type'); switch ($sendType) { case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL: $configPath = 'xmlconnect/' . Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL . '/broadcast_url'; - $broadcastUrl = Mage::getStoreConfig($configPath); $params = $queue->getAirmailBroadcastParams(); break; case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH: default: $configPath = 'xmlconnect/' . Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH . '/broadcast_url'; - $broadcastUrl = Mage::getStoreConfig($configPath); $params = $queue->getPushBroadcastParams(); break; } - $ch = curl_init($broadcastUrl); + $curlHandler = curl_init(Mage::getStoreConfig($configPath)); $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); + curl_setopt($curlHandler, CURLOPT_POST, 1); + curl_setopt($curlHandler, CURLOPT_HTTPHEADER, $httpHeaders); + curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $params); + curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlHandler, CURLOPT_USERPWD, $userpwd); + curl_setopt($curlHandler, CURLOPT_TIMEOUT, 60); // Execute the request. - $result = curl_exec($ch); - $succeeded = curl_errno($ch) == 0 ? true : false; + $result = curl_exec($curlHandler); + $succeeded = curl_errno($curlHandler) == 0 ? true : false; // close cURL resource, and free up system resources - curl_close($ch); + curl_close($curlHandler); if ($succeeded && (is_null($result) || strtolower($result) == 'null')) { $queue->setStatus(Mage_XmlConnect_Model_Queue::STATUS_COMPLETED); @@ -743,7 +743,7 @@ public function getExcludedXmlConfigKeys() /** * Returns Application name by it's code - * @param string $appCode + * @param string $appCode * @return string */ public function getApplicationName($appCode = null) @@ -764,7 +764,7 @@ public function getApplicationName($appCode = null) /** * Returns Application name by it's code - * @param string $appCode + * @param string $templateId * @return string */ public function getTemplateName($templateId = null) @@ -786,10 +786,10 @@ public function getTemplateName($templateId = null) /** * 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 + * @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 = '/') @@ -829,13 +829,51 @@ public function urlToPath($icon) */ 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')) + 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; } + + /** + * Check the notifications are allowed for current type of application + * + * @param Mage_XmlConnect_Model_Application $application + * @return bool + */ + public function isNotificationsAllowed($application = null) + { + return $this->getDeviceHelper($application)->isNotificationsAllowed(); + } + + /** + * Get front url for action + * + * @param string $action + * @param array $params + * @return string url + */ + public function getActionUrl($action, $params = array()) + { + $defaultParams = array( + '_store' => $this->getApplication()->getStoreId(), + '_nosid' => true, + '_secure' => $this->getApplication()->getUseSecureURLInFrontend() + ); + $params = array_merge($defaultParams, $params); + return Mage::getUrl($action, $params); + } + + /** + * Remove trilling line breaks + * + * @param string $string + * @return string + */ + public function trimLineBreaks($string) + { + return preg_replace(array('@\r@', '@\n+@'), array('', PHP_EOL), $string); + } } diff --git a/app/code/core/Mage/XmlConnect/Helper/Image.php b/app/code/core/Mage/XmlConnect/Helper/Image.php index a76cb536cf..7d94289c51 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Image.php +++ b/app/code/core/Mage/XmlConnect/Helper/Image.php @@ -78,10 +78,9 @@ class Mage_XmlConnect_Helper_Image extends Mage_Core_Helper_Abstract * setup file names to the configuration * * @param string $field - * @param mixed &$target * @retun string */ - public function handleUpload($field, &$target) + public function handleUpload($field) { $uploadedFilename = ''; $uploadDir = $this->getOriginalSizeUploadDir(); @@ -111,7 +110,7 @@ public function handleUpload($field, &$target) Mage::logException($e); } } - return $uploadedFilename; + return basename($uploadedFilename); } /** @@ -130,7 +129,7 @@ protected function _getScreenSize() * @throws Mage_Core_Exception * @param string $fieldPath * @param string $fileName - * @param string $default + * @param bool $default * @return string */ protected function _getResizedFilename($fieldPath, $fileName, $default = false) @@ -143,7 +142,7 @@ protected function _getResizedFilename($fieldPath, $fileName, $default = false) } $customSizeFileName = $dir . DS . $fileName; $originalSizeFileName = $this->getOriginalSizeUploadDir(). DS . $fileName; - $error = false; + /** * Compatibility with old versions of XmlConnect */ @@ -151,9 +150,8 @@ protected function _getResizedFilename($fieldPath, $fileName, $default = false) $oldFileName = $this->getOldUploadDir() . DS . $fileName; if (file_exists($oldFileName)) { if (!(copy($oldFileName, $originalSizeFileName) - && (is_readable($customSizeFileName) - || chmod($customSizeFileName, 0644))) - ) { + && (is_readable($customSizeFileName) || chmod($customSizeFileName, 0644)) + )) { Mage::throwException( Mage::helper('xmlconnect')->__('Error while processing file "%s".', $fileName) ); @@ -163,11 +161,9 @@ protected function _getResizedFilename($fieldPath, $fileName, $default = false) } } - if (!$error - && copy($originalSizeFileName, $customSizeFileName) - && (is_readable($customSizeFileName) - || chmod($customSizeFileName, 0644)) - ) { + $isCopied = copy($originalSizeFileName, $customSizeFileName); + clearstatcache(); + if ($isCopied && (is_readable($customSizeFileName) || chmod($customSizeFileName, 0644))) { $this->_handleResize($fieldPath, $customSizeFileName); } else { $fileName = ''; @@ -184,7 +180,7 @@ protected function _getResizedFilename($fieldPath, $fileName, $default = false) * * @param string $fieldPath * @param string $file - * @return void + * @return null */ protected function _handleResize($fieldPath, $file) { @@ -219,9 +215,7 @@ protected function _handleResize($fieldPath, $file) $height = $conf['height']; } - if (($width != $image->getOriginalWidth()) - || ($height != $image->getOriginalHeight()) - ) { + if (($width != $image->getOriginalWidth()) || ($height != $image->getOriginalHeight())) { $image->keepTransparency(true); $image->keepFrame(true); $image->keepAspectRatio(true); @@ -246,11 +240,17 @@ protected function _forcedConvertPng($field) } $file['name'] .= '.png'; - $fileType = exif_imagetype($file['tmp_name']); +// We can't use exif extension, because magento doesn't require it. +// $fileType = exif_imagetype($file['tmp_name']); + list($unnecessaryVar, $unnecessaryVar, $fileType) = getimagesize($file['tmp_name']); + unset($unnecessaryVar); + if ($fileType != IMAGETYPE_PNG) { switch ($fileType) { case IMAGETYPE_GIF: $img = imagecreatefromgif($file['tmp_name']); + imagealphablending($img, false); + imagesavealpha($img, true); break; case IMAGETYPE_JPEG: $img = imagecreatefromjpeg($file['tmp_name']); @@ -264,8 +264,6 @@ protected function _forcedConvertPng($field) default: return; } - imagealphablending($img, false); - imagesavealpha($img, true); imagepng($img, $file['tmp_name']); imagedestroy($img); } @@ -441,7 +439,9 @@ public function getDefaultDesignSuffixAsUrl($image = '') /** * Retrieve thumbnail image url * + * @param string $imageUrl * @param int $width + * @param int $height * @return string|null */ public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100) @@ -614,9 +614,9 @@ public function getImageLimits($screenSize = Mage_XmlConnect_Model_Application:: /** * Return reference to the $path in $array * - * @param array $array + * @param array &$array * @param string $path - * @return &mixed //(reference) + * @return mixed reference */ public function &findPath(&$array, $path) { @@ -639,9 +639,9 @@ public function &findPath(&$array, $path) * Multiply given $item by $value if non array * * @param mixed $item (argument to change) - * @param mixed $key (not used) + * @param mixed $key (used with array_walk_recursive function as a key of given array) * @param string $value (contains float) - * @return void + * @return null */ protected function _zoom(&$item, $key, $value) { @@ -658,8 +658,12 @@ protected function _zoom(&$item, $key, $value) */ protected function _verifyDirExist($dir) { - $io = new Varien_Io_File(); - $io->checkAndCreateFolder($dir); + try { + $ioFile = new Varien_Io_File(); + $ioFile->checkAndCreateFolder($dir); + } catch (Exception $e) { + Mage::throwException($e->getMessage()); + } } /** @@ -718,11 +722,13 @@ public function getDefaultSizeUploadDir() public function getInterfaceImagesPathsConf() { if (!isset($this->_confPaths)) { - $paths = $this->getInterfaceImagesPaths(); $this->_confPaths = array(); - $len = strlen('conf/native/'); - foreach ($paths as $path => $defaultFileName) { - $this->_confPaths[$path] = substr($path, $len); + $paths = $this->getInterfaceImagesPaths(); + if (is_array($paths)) { + $len = strlen('conf/native/'); + while (list($path,) = each($paths)) { + $this->_confPaths[$path] = substr($path, $len); + } } } return $this->_confPaths; @@ -758,4 +764,20 @@ public function getInterfaceImagesPaths($imagePath = null) return null; } } + + /** + * Check image and get full file path + * + * @param string &$icon + * @return bool + */ + public function checkAndGetImagePath(&$icon) + { + $icon = basename($icon); + if (is_file($this->getDefaultSizeUploadDir() . DS . $icon)) { + $icon = $this->getDefaultSizeUploadDir() . DS . $icon; + return true; + } + return false; + } } diff --git a/app/code/core/Mage/XmlConnect/Helper/Ipad.php b/app/code/core/Mage/XmlConnect/Helper/Ipad.php index f7d60ed6ef..a128537611 100755 --- a/app/code/core/Mage/XmlConnect/Helper/Ipad.php +++ b/app/code/core/Mage/XmlConnect/Helper/Ipad.php @@ -98,11 +98,8 @@ class Mage_XmlConnect_Helper_Ipad extends Mage_Core_Helper_Abstract * * @var array */ - protected $_imageIds = array('icon', - 'ipad_loader_portrait_image', - 'ipad_loader_landscape_image', - 'ipad_logo', - 'big_logo' + protected $_imageIds = array( + 'icon', 'ipad_loader_portrait_image', 'ipad_loader_landscape_image', 'ipad_logo', 'big_logo' ); /** @@ -125,7 +122,6 @@ public function getSubmitImages() /** * Get default application tabs * - * @param string * @return array */ public function getDefaultDesignTabs() @@ -164,74 +160,74 @@ public function getDefaultDesignTabs() */ 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' => '20', - 'color' => '#FEFEFE', - ), - 'Title2' => array( - 'name' => 'HelveticaNeue-Bold', - 'size' => '15', - 'color' => '#222222', - ), - 'Title3' => array( - 'name' => 'HelveticaNeue', - 'size' => '14', - 'color' => '#222222', - ), - 'Title4' => array( - 'name' => 'HelveticaNeue', - 'size' => '12', - 'color' => '#FFFFFF', - ), - 'Title5' => array( - 'name' => 'HelveticaNeue-Bold', - 'size' => '18', - 'color' => '#d55000', - ), - 'Title6' => array( - 'name' => 'HelveticaNeue-Bold', - 'size' => '16', - 'color' => '#FFFFFF', - ), - 'Title7' => array( - 'name' => 'HelveticaNeue-Bold', - 'size' => '13', - 'color' => '#222222', - ), - 'Title8' => array( - 'name' => 'HelveticaNeue-Bold', - 'size' => '13', - 'color' => '#FFFFFF', - ), - 'Title9' => array( - 'name' => 'HelveticaNeue-Bold', - 'size' => '18', - 'color' => '#FFFFFF', - ), - 'Text1' => array( - 'name' => 'HelveticaNeue-Bold', - 'size' => '14', - 'color' => '#222222', - ), - 'Text2' => array( - 'name' => 'HelveticaNeue', - 'size' => '12', - 'color' => '#222222', - ), - ), - ), - ); + return array( + 'native' => array( + 'body' => array( + 'backgroundColor' => '#ABABAB', + 'scrollBackgroundColor' => '#EDEDED', + ), + 'itemActions' => array( + 'relatedProductBackgroundColor' => '#404040', + ), + 'fonts' => array( + 'Title1' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '20', + 'color' => '#FEFEFE', + ), + 'Title2' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '15', + 'color' => '#222222', + ), + 'Title3' => array( + 'name' => 'HelveticaNeue', + 'size' => '14', + 'color' => '#222222', + ), + 'Title4' => array( + 'name' => 'HelveticaNeue', + 'size' => '12', + 'color' => '#FFFFFF', + ), + 'Title5' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '18', + 'color' => '#d55000', + ), + 'Title6' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '16', + 'color' => '#FFFFFF', + ), + 'Title7' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '13', + 'color' => '#222222', + ), + 'Title8' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '13', + 'color' => '#FFFFFF', + ), + 'Title9' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '18', + 'color' => '#FFFFFF', + ), + 'Text1' => array( + 'name' => 'HelveticaNeue-Bold', + 'size' => '14', + 'color' => '#222222', + ), + 'Text2' => array( + 'name' => 'HelveticaNeue', + 'size' => '12', + 'color' => '#222222', + ), + ), + ), + ); } /** @@ -460,7 +456,7 @@ public function getFontList() */ public function getFontSizes() { - $result = array( ); + $result = array(); for ($i = 6; $i < 32; $i++) { $result[] = array( 'value' => $i, @@ -538,14 +534,14 @@ public function validateSubmit($params) } if (!Zend_Validate::is($resubmissionKey, 'NotEmpty')) { $errors[] = Mage::helper('xmlconnect')->__('Please enter the Resubmission Key.'); - } else if (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) { + } elseif (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) { $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided'); } } else { $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, $keyLenght))) { + } elseif (!Zend_Validate::is($key, 'StringLength', array(1, $keyLenght))) { $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided'); } } @@ -561,10 +557,11 @@ public function validateSubmit($params) public function validateConfig($native) { $errors = array(); - if ( ($native === false) - || (!isset($native['navigationBar']) || !is_array($native['navigationBar']) - || !isset($native['navigationBar']['icon']) - || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty'))) { + if ($native === false + || (!isset($native['navigationBar']['icon']) + || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty') + ) + ) { $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Logo in Header" field from Design Tab.'); } @@ -652,34 +649,39 @@ public function getCountryClass() */ public function checkImages(array $data) { - if (isset($data['conf']['native']['navigationBar']['icon']) - && !file_exists($data['conf']['native']['navigationBar']['icon']) - ) { - $data['conf']['native']['navigationBar']['icon'] = ''; + /** @var $helper Mage_XmlConnect_Helper_Image */ + $helper = Mage::helper('xmlconnect/image'); + + $icon =& $data['conf']['native']['navigationBar']['icon']; + + if (!empty($icon) && !$helper->checkAndGetImagePath($icon)) { + $icon = ''; } - if (isset($data['conf']['native']['body']['bannerIpadLandscapeImage']) - && !file_exists($data['conf']['native']['body']['bannerIpadLandscapeImage']) - ) { - $data['conf']['native']['body']['bannerIpadLandscapeImage'] = ''; + $bannerLand =& $data['conf']['native']['body']['bannerIpadLandscapeImage']; + + if (!empty($bannerLand) && !$helper->checkAndGetImagePath($bannerLand)) { + $bannerLand = ''; } - if (isset($data['conf']['native']['body']['bannerIpadImage']) - && !file_exists($data['conf']['native']['body']['bannerIpadImage']) - ) { - $data['conf']['native']['body']['bannerIpadImage'] = ''; + $banner =& $data['conf']['native']['body']['bannerIpadImage']; + + if (!empty($banner) && !$helper->checkAndGetImagePath($banner)) { + $banner = ''; } - if (isset($data['conf']['native']['body']['backgroundIpadLandscapeImage']) - && !file_exists($data['conf']['native']['body']['backgroundIpadLandscapeImage']) - ) { - $data['conf']['native']['body']['backgroundIpadLandscapeImage'] = ''; + $backgroundLand =& $data['conf']['native']['body']['backgroundIpadLandscapeImage']; + + if (!empty($backgroundLand) && !$helper->checkAndGetImagePath($backgroundLand)) { + $backgroundLand = ''; } - if (isset($data['conf']['native']['body']['backgroundIpadPortraitImage']) - && !file_exists($data['conf']['native']['body']['backgroundIpadPortraitImage']) - ) { - $data['conf']['native']['body']['backgroundIpadPortraitImage'] = ''; + + $background =& $data['conf']['native']['body']['backgroundIpadPortraitImage']; + + if (!empty($background) && !$helper->checkAndGetImagePath($background)) { + $background = ''; } + return $data; } @@ -688,7 +690,7 @@ public function checkImages(array $data) * * @throws Mage_Core_Exception * @param array $data - * @return void + * @return null */ public function checkRequiredConfigFields($data) { @@ -696,23 +698,17 @@ public function checkRequiredConfigFields($data) return; } - if (isset($data['navigationBar']['icon']) - && empty($data['navigationBar']['icon']) - ) { + if (isset($data['navigationBar']['icon']) && empty($data['navigationBar']['icon'])) { Mage::throwException( Mage::helper('xmlconnect')->__('Logo in Header image missing.') ); } - if (isset($data['body']['bannerIpadImage']) - && empty($data['body']['bannerIpadImage']) - ) { + if (isset($data['body']['bannerIpadImage']) && empty($data['body']['bannerIpadImage'])) { Mage::throwException( Mage::helper('xmlconnect')->__('Banner on Home Screen (portrait mode) image missing.') ); } - if (isset($data['body']['bannerIpadLandscapeImage']) - && empty($data['body']['bannerIpadLandscapeImage']) - ) { + if (isset($data['body']['bannerIpadLandscapeImage']) && empty($data['body']['bannerIpadLandscapeImage'])) { Mage::throwException( Mage::helper('xmlconnect')->__('Banner on Home Screen (landscape mode) image missing.') ); @@ -732,4 +728,14 @@ public function checkRequiredConfigFields($data) ); } } + + /** + * Check the notifications are allowed for current type of application + * + * @return bool + */ + public function isNotificationsAllowed() + { + return true; + } } diff --git a/app/code/core/Mage/XmlConnect/Helper/Iphone.php b/app/code/core/Mage/XmlConnect/Helper/Iphone.php index 9f81f57858..73f8954ac2 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Iphone.php +++ b/app/code/core/Mage/XmlConnect/Helper/Iphone.php @@ -59,13 +59,7 @@ class Mage_XmlConnect_Helper_Iphone extends Mage_Core_Helper_Abstract * @var array */ protected $_imageIds = array( - 'icon', - 'loader_image', - 'loader_image_i4', - 'logo', - 'logo_i4', - 'big_logo', - 'big_logo_i4' + 'icon', 'loader_image', 'loader_image_i4', 'logo', 'logo_i4', 'big_logo', 'big_logo_i4' ); /** @@ -190,7 +184,6 @@ public function getSubmitImages() /** * Get default application tabs * - * @param string * @return array */ public function getDefaultDesignTabs() @@ -244,74 +237,74 @@ public function getDefaultDesignTabs() */ 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', - ), - ), - ), - ); + 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', + ), + ), + ), + ); } /** @@ -540,7 +533,7 @@ public function getFontList() */ public function getFontSizes() { - $result = array( ); + $result = array(); for ($i = 6; $i < 32; $i++) { $result[] = array( 'value' => $i, @@ -618,14 +611,14 @@ public function validateSubmit($params) if (!Zend_Validate::is($resubmissionKey, 'NotEmpty')) { $errors[] = Mage::helper('xmlconnect')->__('Please enter the Resubmission Key.'); - } else if (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) { + } elseif (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) { $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided'); } } else { $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, $keyLenght))) { + } elseif (!Zend_Validate::is($key, 'StringLength', array(1, $keyLenght))) { $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided'); } } @@ -642,10 +635,9 @@ public function validateConfig($native) { $errors = array(); - if ( ($native === false) - || (!isset($native['navigationBar']) || !is_array($native['navigationBar']) - || !isset($native['navigationBar']['icon']) - || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty'))) { + if ($native === false || (!isset($native['navigationBar']['icon']) + || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty')) + ) { $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Logo in Header" field from Design Tab.'); } @@ -725,23 +717,27 @@ public function getCountryClass() */ public function checkImages(array $data) { - if (isset($data['conf']['native']['navigationBar']['icon']) && - !file_exists($data['conf']['native']['navigationBar']['icon']) - ) { - $data['conf']['native']['navigationBar']['icon'] = ''; + /** @var $helper Mage_XmlConnect_Helper_Image */ + $helper = Mage::helper('xmlconnect/image'); + + $icon =& $data['conf']['native']['navigationBar']['icon']; + + if (!empty($icon) && !$helper->checkAndGetImagePath($icon)) { + $icon = ''; } - if (isset($data['conf']['native']['body']['bannerImage']) && - !file_exists($data['conf']['native']['body']['bannerImage']) - ) { - $data['conf']['native']['body']['bannerImage'] = ''; + $banner =& $data['conf']['native']['body']['bannerImage']; + + if (!empty($banner) && !$helper->checkAndGetImagePath($banner)) { + $banner = ''; } - if (isset($data['conf']['native']['body']['backgroundImage']) && - !file_exists($data['conf']['native']['body']['backgroundImage']) - ) { - $data['conf']['native']['body']['backgroundImage'] = ''; + $background =& $data['conf']['native']['body']['backgroundImage']; + + if (!empty($background) && !$helper->checkAndGetImagePath($background)) { + $background = ''; } + return $data; } @@ -750,7 +746,7 @@ public function checkImages(array $data) * * @throws Mage_Core_Exception * @param array $data - * @return void + * @return null */ public function checkRequiredConfigFields($data) { @@ -758,26 +754,24 @@ public function checkRequiredConfigFields($data) return; } - if (isset($data['navigationBar']['icon']) - && empty($data['navigationBar']['icon']) - ) { - Mage::throwException( - Mage::helper('xmlconnect')->__('Logo in Header image missing.') - ); + if (isset($data['navigationBar']['icon']) && empty($data['navigationBar']['icon'])) { + Mage::throwException(Mage::helper('xmlconnect')->__('Logo in Header image missing.')); } - if (isset($data['body']['bannerImage']) && - empty($data['body']['bannerImage']) - ) { - Mage::throwException( - Mage::helper('xmlconnect')->__('Banner on Home Screen image missing.') - ); + if (isset($data['body']['bannerImage']) && empty($data['body']['bannerImage'])) { + Mage::throwException(Mage::helper('xmlconnect')->__('Banner on Home Screen image missing.')); } - if (isset($data['body']['backgroundImage']) - && empty($data['body']['backgroundImage']) - ) { - Mage::throwException( - Mage::helper('xmlconnect')->__('App Background image missing.') - ); + if (isset($data['body']['backgroundImage']) && empty($data['body']['backgroundImage'])) { + Mage::throwException(Mage::helper('xmlconnect')->__('App Background image missing.')); } } + + /** + * Check the notifications are allowed for current type of application + * + * @return bool + */ + public function isNotificationsAllowed() + { + return true; + } } diff --git a/app/code/core/Mage/XmlConnect/Helper/Payment.php b/app/code/core/Mage/XmlConnect/Helper/Payment.php index ca4938fdb4..4a1df2f794 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Payment.php +++ b/app/code/core/Mage/XmlConnect/Helper/Payment.php @@ -31,7 +31,7 @@ class Mage_XmlConnect_Helper_Payment extends Mage_Core_Helper_Abstract { /** * Return paymentMethod => methodCode array - * + * * @deprecated after 1.4.2.0 * @return array */ diff --git a/app/code/core/Mage/XmlConnect/Helper/Theme.php b/app/code/core/Mage/XmlConnect/Helper/Theme.php index 2414d0a2b5..bb69bc374b 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Theme.php +++ b/app/code/core/Mage/XmlConnect/Helper/Theme.php @@ -81,7 +81,7 @@ public function getThemeAjaxParameters() /** * Returns JSON ready Themes array * - * @param bool $flushCache - load defaults + * @param bool $flushCache load defaults * @return array */ public function getAllThemesArray($flushCache = false) @@ -128,6 +128,12 @@ public function getThemesSelector($themeId = '') $currentTheme = $this->getThemeByName($themeId); } + if (!($currentTheme instanceof Mage_XmlConnect_Model_Theme)) { + Mage::throwException( + Mage::helper('xmlconnect')->__('Can\'t load selected theme. Please check your media folder permissions.') + ); + } + $themeList = ''; foreach ($this->getAllThemes(true) as $theme) { $themeList .= '
  • '; @@ -168,11 +174,11 @@ public function getAllThemes($flushCache = false) $saveLibxmlErrors = libxml_use_internal_errors(true); $this->_themeArray = array(); $themeDir = $this->getMediaThemePath(); - $io = new Varien_Io_File(); - $io->checkAndCreateFolder($themeDir); - $io->open(array('path' => $themeDir)); + $ioFile = new Varien_Io_File(); + $ioFile->checkAndCreateFolder($themeDir); + $ioFile->open(array('path' => $themeDir)); try { - $fileList = $io->ls(Varien_Io_File::GREP_FILES); + $fileList = $ioFile->ls(Varien_Io_File::GREP_FILES); if (!count($fileList)) { $this->resetTheme(); $this->getAllThemes(true); @@ -204,10 +210,10 @@ public function getDefaultThemes() $saveLibxmlErrors = libxml_use_internal_errors(true); $defaultThemeArray = array(); $themeDir = $this->_getDefaultThemePath(); - $io = new Varien_Io_File(); - $io->open(array('path' => $themeDir)); + $ioFile = new Varien_Io_File(); + $ioFile->open(array('path' => $themeDir)); try { - $fileList = $io->ls(Varien_Io_File::GREP_FILES); + $fileList = $ioFile->ls(Varien_Io_File::GREP_FILES); foreach ($fileList as $file) { $src = $themeDir . DS . $file['text']; if (is_readable($src)) { @@ -220,9 +226,7 @@ public function getDefaultThemes() Mage::logException($e); } if (!count($defaultThemeArray)) { - Mage::throwException( - Mage::helper('xmlconnect')->__('Can\'t load default themes.') - ); + Mage::throwException(Mage::helper('xmlconnect')->__('Can\'t load default themes.')); } return $defaultThemeArray; } @@ -267,16 +271,16 @@ public function getMediaThemePath() * * @throws Mage_Core_Exception * @param null $theme - * @return void + * @return null */ public function resetTheme($theme = null) { $themeDir = $this->getMediaThemePath(); $defaultThemeDir = $this->_getDefaultThemePath(); - $io = new Varien_Io_File(); - $io->open(array('path' => $defaultThemeDir)); - $fileList = $io->ls(Varien_Io_File::GREP_FILES); + $ioFile = new Varien_Io_File(); + $ioFile->open(array('path' => $defaultThemeDir)); + $fileList = $ioFile->ls(Varien_Io_File::GREP_FILES); foreach ($fileList as $file) { $f = $file['text']; $src = $defaultThemeDir . DS . $f; @@ -286,12 +290,10 @@ public function resetTheme($theme = null) continue; } - if (!$io->cp($src, $dst)) { - Mage::throwException( - Mage::helper('xmlconnect')->__('Can\'t copy file "%s" to "%s".', $src, $dst) - ); + if (!$ioFile->cp($src, $dst)) { + Mage::throwException(Mage::helper('xmlconnect')->__('Can\'t copy file "%s" to "%s".', $src, $dst)); } else { - $io->chmod($dst, 0755); + $ioFile->chmod($dst, 0755); } } } @@ -378,11 +380,11 @@ public function getThemeLabel(array $themes, $themeId = false) public function deleteTheme($themeId) { $result = false; - $io = new Varien_Io_File(); - $io->cd($this->getMediaThemePath()); + $ioFile = new Varien_Io_File(); + $ioFile->cd($this->getMediaThemePath()); $themeFile = $themeId . '.xml'; - if ($io->fileExists($themeFile)) { - $result = $io->rm($themeFile); + if ($ioFile->fileExists($themeFile)) { + $result = $ioFile->rm($themeFile); } return $result; } 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 bfeb9dd081..e1a658cb99 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,12 +24,20 @@ * @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 +/** + * Xmlconnect system config base url model + * + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Baseurl + extends Mage_Adminhtml_Model_System_Config_Backend_Baseurl { /** * Update all applications "updated at" parameter with current date * - * @return this + * @return Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Baseurl */ protected function _afterSave() { 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 7d1c69861a..f8ae325735 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,15 @@ * @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 +/** + * Xmlconnect system config currency model + * + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Currency_Default + extends Mage_Adminhtml_Model_System_Config_Backend_Currency_Default { /** * Update all applications "updated at" parameter with current date diff --git a/app/code/core/Mage/XmlConnect/Model/Application.php b/app/code/core/Mage/XmlConnect/Model/Application.php index acfe8712a1..d8ba56aaac 100644 --- a/app/code/core/Mage/XmlConnect/Model/Application.php +++ b/app/code/core/Mage/XmlConnect/Model/Application.php @@ -25,7 +25,7 @@ */ /** - * XmlConnect Model Application + * Xmlconnect Application model * * @method Mage_XmlConnect_Model_Resource_Application _getResource() * @method Mage_XmlConnect_Model_Resource_Application getResource() @@ -56,17 +56,17 @@ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract /** * Application code cookie name */ - const APP_CODE_COOKIE_NAME = 'app_code'; + const APP_CODE_COOKIE_NAME = 'app_code'; /** * Device screen size name */ - const APP_SCREEN_SIZE_NAME = 'screen_size'; + const APP_SCREEN_SIZE_NAME = 'screen_size'; /** * Device screen size name */ - const APP_SCREEN_SIZE_DEFAULT = '320x480'; + const APP_SCREEN_SIZE_DEFAULT = '320x480'; /** * Device screen size source name @@ -76,12 +76,12 @@ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract /** * Application status "submitted" value */ - const APP_STATUS_SUCCESS = 1; + const APP_STATUS_SUCCESS = 1; /** * Application status "not submitted" value */ - const APP_STATUS_INACTIVE = 0; + const APP_STATUS_INACTIVE = 0; /** * Application prefix length of cutted part of deviceType and storeCode @@ -131,6 +131,13 @@ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract */ protected $_configModel; + /** + * Flag of loaded configuration + * + * @var bool + */ + protected $_isConfigurationLoaded = false; + /** * Social networking validation array * @@ -157,103 +164,106 @@ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract * for contact to receive credentials * of Urban Airship notifications */ - const XML_PATH_CONTACT_CREDENTIALS_EMAIL = 'xmlconnect/mobile_application/urbanairship_credentials_email'; + const XML_PATH_CONTACT_CREDENTIALS_EMAIL = 'xmlconnect/mobile_application/urbanairship_credentials_email'; /** * XML path to config with Urban Airship Terms of Service URL */ - const XML_PATH_URBAN_AIRSHIP_TOS_URL = 'xmlconnect/mobile_application/urbanairship_terms_of_service_url'; + const XML_PATH_URBAN_AIRSHIP_TOS_URL = 'xmlconnect/mobile_application/urbanairship_terms_of_service_url'; /** * XML path to config with Urban Airship partner's login URL */ - const XML_PATH_URBAN_AIRSHIP_PARTNER_LOGIN_URL = 'xmlconnect/mobile_application/urbanairship_login_url'; + const XML_PATH_URBAN_AIRSHIP_PARTNER_LOGIN_URL = 'xmlconnect/mobile_application/urbanairship_login_url'; /** * XML path to config with Urban Airship Push notifications product URL */ - const XML_PATH_URBAN_AIRSHIP_ABOUT_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_push_url'; + const XML_PATH_URBAN_AIRSHIP_ABOUT_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_push_url'; /** * XML path to config with Urban Airship Rich Push notifications product URL */ - const XML_PATH_URBAN_AIRSHIP_ABOUT_RICH_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_rich_push_url'; + const XML_PATH_URBAN_AIRSHIP_ABOUT_RICH_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_rich_push_url'; /** * XML path to config copyright data */ - const XML_PATH_DESIGN_FOOTER_COPYRIGHT = 'design/footer/copyright'; + const XML_PATH_DESIGN_FOOTER_COPYRIGHT = 'design/footer/copyright'; /** * XML path to config restriction status * (EE module) */ - const XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE = 'general/restriction/is_active'; + const XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE = 'general/restriction/is_active'; /** * XML path to config restriction mode * (EE module) */ - const XML_PATH_GENERAL_RESTRICTION_MODE = 'general/restriction/mode'; + const XML_PATH_GENERAL_RESTRICTION_MODE = 'general/restriction/mode'; /** * XML path to config secure base link URL */ - const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url'; + const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url'; /** * XML path to config for paypal business account */ - const XML_PATH_PAYPAL_BUSINESS_ACCOUNT = 'paypal/general/business_account'; + const XML_PATH_PAYPAL_BUSINESS_ACCOUNT = 'paypal/general/business_account'; /** * XML path to config for default cache time */ - const XML_PATH_DEFAULT_CACHE_LIFETIME = 'xmlconnect/mobile_application/cache_lifetime'; + const XML_PATH_DEFAULT_CACHE_LIFETIME = 'xmlconnect/mobile_application/cache_lifetime'; /** * XML path to How-To URL for twitter */ - const XML_PATH_HOWTO_TWITTER_URL = 'xmlconnect/social_networking/howto_twitter_url'; + const XML_PATH_HOWTO_TWITTER_URL = 'xmlconnect/social_networking/howto_twitter_url'; /** * XML path to How-To URL for facebook */ - const XML_PATH_HOWTO_FACEBOOK_URL = 'xmlconnect/social_networking/howto_facebook_url'; + const XML_PATH_HOWTO_FACEBOOK_URL = 'xmlconnect/social_networking/howto_facebook_url'; /** * XML path to How-To URL for linkedin */ - const XML_PATH_HOWTO_LINKEDIN_URL = 'xmlconnect/social_networking/howto_linkedin_url'; + const XML_PATH_HOWTO_LINKEDIN_URL = 'xmlconnect/social_networking/howto_linkedin_url'; + + /** + * XML path to XmlConnect module version + */ + const XML_PATH_MODULE_VERSION = 'modules/Mage_XmlConnect/innerVersion'; /** * Deprecated config flag * * @deprecated Serialized config storage has been removed */ - const DEPRECATED_CONFIG_FLAG = 'deprecated'; + const DEPRECATED_CONFIG_FLAG = 'deprecated'; /** * Delete on update paths for config data * * @var array */ - protected $_deleteOnUpdateConfig = array( + protected $_deleteOnUpdateConfig = array( self::DEPRECATED_CONFIG_FLAG => 'native/pages' ); /** * Initialize application * - * @return void + * @return null */ protected function _construct() { $this->_init('xmlconnect/application'); $this->_configModel = Mage::getModel('xmlconnect/configData'); - $this->_configModel->setDeleteOnUpdate( - $this->getDeleteOnUpdateConfig() - ); + $this->_configModel->setDeleteOnUpdate($this->getDeleteOnUpdateConfig()); } /** @@ -306,25 +316,25 @@ protected function _flatArray($subtree, $prefix=null) } /** - * Like array_merge_recursive(), but string values is replaced + * Like array_merge_recursive(), but string values will be replaced * - * @param array $a - * @param array $b + * @param array $array1 + * @param array $array2 * @return array */ - protected function _configMerge(array $a, array $b) + protected function _configMerge(array $array1, array $array2) { $result = array(); - $keys = array_unique(array_merge(array_keys($a), array_keys($b))); + $keys = array_unique(array_merge(array_keys($array1), array_keys($array2))); foreach ($keys as $key) { - if (!isset($a[$key])) { - $result[$key] = $b[$key]; - } elseif (!isset($b[$key])) { - $result[$key] = $a[$key]; - } elseif (is_scalar($a[$key]) || is_scalar($b[$key])) { - $result[$key] = $b[$key]; + if (!isset($array1[$key])) { + $result[$key] = $array2[$key]; + } elseif (!isset($array2[$key])) { + $result[$key] = $array1[$key]; + } elseif (is_scalar($array1[$key]) || is_scalar($array2[$key])) { + $result[$key] = $array2[$key]; } else { - $result[$key] = $this->_configMerge($a[$key], $b[$key]); + $result[$key] = $this->_configMerge($array1[$key], $array2[$key]); } } return $result; @@ -333,7 +343,7 @@ protected function _configMerge(array $a, array $b) /** * Set default configuration data * - * @return void + * @return null */ public function loadDefaultConfiguration() { @@ -383,7 +393,7 @@ public function getRenderConf() { $result = Mage::helper('xmlconnect')->getDeviceHelper()->getDefaultConfiguration(); $result = $result['native']; - $extra = array(); + if (isset($this->_data['conf'])) { if (isset($this->_data['conf']['native'])) { $result = $this->_configMerge($result, $this->_data['conf']['native']); @@ -401,8 +411,8 @@ public function getRenderConf() if (!empty($extra['fontColors']['primary'])) { $result['fonts']['Title2']['color'] = $extra['fontColors']['primary']; $result['fonts']['Title3']['color'] = $extra['fontColors']['primary']; - $result['fonts']['Text1']['color'] = $extra['fontColors']['primary']; - $result['fonts']['Text2']['color'] = $extra['fontColors']['primary']; + $result['fonts']['Text1']['color'] = $extra['fontColors']['primary']; + $result['fonts']['Text2']['color'] = $extra['fontColors']['primary']; $result['fonts']['Title7']['color'] = $extra['fontColors']['primary']; } if (!empty($extra['fontColors']['secondary'])) { @@ -417,23 +427,24 @@ public function getRenderConf() } } } + /** @var $helperImage Mage_XmlConnect_Helper_Image */ $helperImage = Mage::helper('xmlconnect/image'); $paths = $helperImage->getInterfaceImagesPathsConf(); + foreach ($paths as $confPath => $dataPath) { $imageNodeValue =& $helperImage->findPath($result, $dataPath); - if ($imageNodeValue) { - if (!file_exists($imageNodeValue)) { - /** - * We set empty string to get default image if original was missing in some reason - */ - $imageNodeValue = ''; - } else { - /** - * Creating file ending (some_inner/some_dir/filename.png) For url - */ - $imageNodeValue = $helperImage->getFileCustomDirSuffixAsUrl($confPath, $imageNodeValue); - } + + if (!$helperImage->checkAndGetImagePath($imageNodeValue)) { + /** + * We set empty string to get default image if original was missing in some reason + */ + $imageNodeValue = ''; + } else { + /** + * Creating file ending (some_inner/some_dir/filename.png) For url + */ + $imageNodeValue = $helperImage->getFileCustomDirSuffixAsUrl($confPath, $imageNodeValue); } } $result = $this->_absPath($result); @@ -444,10 +455,7 @@ 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( - self::XML_PATH_SECURE_BASE_LINK_URL, - $this->getStoreId() - ); + $result['general']['secureBaseUrl'] = $this->getSecureBaseUrl(); $maxRecipients = 0; $allowGuest = 0; @@ -461,11 +469,11 @@ public function getRenderConf() ->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE); $result['general']['magentoVersion'] = Mage::getVersion(); $result['general']['copyright'] = Mage::getStoreConfig( - self::XML_PATH_DESIGN_FOOTER_COPYRIGHT, - $this->getStoreId() + self::XML_PATH_DESIGN_FOOTER_COPYRIGHT, $this->getStoreId() ); + $result['general']['xmlconnectVersion'] = Mage::getConfig()->getNode(self::XML_PATH_MODULE_VERSION); - $result['general']['isAllowedGuestCheckout'] = Mage::getSingleton('checkout/session') + $result['general']['isAllowedGuestCheckout'] = (int)Mage::getSingleton('checkout/session') ->getQuote()->isAllowedGuestCheckout(); /** @@ -489,8 +497,28 @@ public function getRenderConf() /** * "Use Secure URLs in Frontend" flag */ - $result['general']['useSecureURLInFrontend'] = (int)Mage::getStoreConfigFlag( - Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND + $result['general']['useSecureURLInFrontend'] = $this->getUseSecureURLInFrontend(); + + /** + * Is enabled Store credit functionality + */ + if (is_object(Mage::getConfig()->getNode('modules/Enterprise_CustomerBalance'))) { + $storeCreditFlag = Mage::getStoreConfig(Enterprise_CustomerBalance_Helper_Data::XML_PATH_ENABLED); + $isStoreCreditEnable = (int)$storeCreditFlag; + $canShowHistoryFlag = (int) Mage::getStoreConfigFlag( + 'customer/enterprise_customerbalance/show_history' + ); + } else { + $isStoreCreditEnable = $canShowHistoryFlag = 0; + } + $result['general']['isStoreCreditEnabled'] = $isStoreCreditEnable; + $result['general']['isStoreCreditHistoryEnabled'] = $canShowHistoryFlag; + + /** + * Is available Gift Card functionality + */ + $result['general']['isGiftcardEnabled'] = (int) is_object( + Mage::getConfig()->getNode('modules/Enterprise_GiftCard') ); /** @@ -500,21 +528,52 @@ public function getRenderConf() $result['paypal']['merchantLabel'] = $this->getData('conf/special/merchantLabel'); $isActive = 0; - if (isset($result['paypal']) && isset($result['paypal']['isActive'])) { - $paypalMep = Mage::getModel('xmlconnect/payment_method_paypal_mep'); - $isActive = (int)($result['paypal']['isActive'] && $paypalMep->isAvailable(null)); + $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null); + if ($paypalMepIsAvailable && isset($result['paypal']['isActive'])) { + $isActive = (int) $result['paypal']['isActive']; } $result['paypal']['isActive'] = $isActive; + $paypalMeclIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mecl')->isAvailable(null); + + /** + * PayPal Mobile Express Library Checkout + */ + $result['paypalMecl']['isActive'] = (int) ( + $paypalMeclIsAvailable + && $this->getData('config_data/payment/paypalmecl_is_active') + ); + if ((int)Mage::getStoreConfig(self::XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE)) { $result['website_restrictions']['mode'] = (int)Mage::getStoreConfig( self::XML_PATH_GENERAL_RESTRICTION_MODE ); } + ksort($result); return $result; } + /** + * Get secure base url + * + * @return string + */ + public function getSecureBaseUrl() + { + return Mage::getStoreConfig(self::XML_PATH_SECURE_BASE_LINK_URL, $this->getStoreId()); + } + + /** + * Is forced front secure url + * + * @return int + */ + public function getUseSecureURLInFrontend() + { + return (int) Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND); + } + /** * Return current screen_size parameter * @@ -566,9 +625,7 @@ protected function _absPath($subtree) if (!empty($value)) { if (is_array($value)) { $subtree[$key] = $this->_absPath($value); - } elseif ((substr($key, -4) == 'icon') || - (substr($key, -4) == 'Icon') || - (substr($key, -5) == 'Image')) { + } elseif (strtolower(substr($key, -4)) == 'icon' || strtolower(substr($key, -5)) == 'image') { $subtree[$key] = Mage::getBaseUrl('media') . 'xmlconnect/' . $value; } } @@ -606,9 +663,7 @@ public function getConfigModel() */ protected function _beforeSave() { - $this->setUpdatedAt( - Mage::getSingleton('core/date')->gmtDate() - ); + $this->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate()); return $this; } @@ -634,9 +689,7 @@ protected function _saveConfigData() { $configuration = $this->getData('config_data'); if (is_array($configuration)) { - $this->getConfigModel() - ->setConfigData($this->getId(), $configuration) - ->initSaveConfig(); + $this->getConfigModel()->setConfigData($this->getId(), $configuration)->initSaveConfig(); } return $this; } @@ -652,9 +705,7 @@ private function _saveDeprecatedConfig() $deprecatedConfig = $this->getData('conf'); if (is_array($deprecatedConfig)) { $this->getConfigModel()->saveConfig( - $this->getId(), - $this->convertOldConfing($deprecatedConfig), - self::DEPRECATED_CONFIG_FLAG + $this->getId(), $this->convertOldConfing($deprecatedConfig), self::DEPRECATED_CONFIG_FLAG ); } return $this; @@ -689,12 +740,10 @@ public function convertOldConfing(array $conf, $path = false) */ public function loadConfiguration() { - static $isConfigurationLoaded = null; - if (is_null($isConfigurationLoaded)) { + if (!$this->_isConfigurationLoaded) { if ($this->getId()) { - $this->_loadDeprecatedConfig() - ->_loadConfigData(); - $isConfigurationLoaded = true; + $this->_loadDeprecatedConfig()->_loadConfigData(); + $this->_isConfigurationLoaded = true; } } return $this; @@ -708,15 +757,11 @@ public function loadConfiguration() */ protected function _loadConfigData() { - $configuration = $this->getConfigModel() - ->getCollection() - ->addArrayFilter( - array( - 'application_id' => $this->getId(), - 'category' => 'payment' - ) - ) - ->toOptionArray(); + $configuration = $this->getConfigModel()->getCollection()->addArrayFilter(array( + 'application_id' => $this->getId(), + 'category' => 'payment' + ))->toOptionArray(); + $this->setData('config_data', $configuration); return $this; } @@ -730,15 +775,10 @@ protected function _loadConfigData() private function _loadDeprecatedConfig() { $configuration = $this->_convertConfig( - $this->getConfigModel() - ->getCollection() - ->addArrayFilter( - array( - 'application_id' => $this->getId(), - 'category' => self::DEPRECATED_CONFIG_FLAG - ) - ) - ->toOptionArray() + $this->getConfigModel()->getCollection()->addArrayFilter(array( + 'application_id' => $this->getId(), + 'category' => self::DEPRECATED_CONFIG_FLAG + ))->toOptionArray() ); $this->setData('conf', $configuration); return $this; @@ -839,7 +879,7 @@ public function getImages() * Fetching data from session restored array */ $basename = basename($path); - } else if (isset($params[$id])) { + } elseif (isset($params[$id])) { /** * Fetching data from submission history table record * @@ -849,7 +889,7 @@ public function getImages() $basename = basename($params[$id]); } if (!empty($basename)) { - $images['conf/submit/'.$id] = Mage::getBaseUrl('media').'xmlconnect/' + $images['conf/submit/'.$id] = Mage::getBaseUrl('media') . 'xmlconnect/' . Mage::helper('xmlconnect/image')->getFileDefaultSizeSuffixAsUrl($basename); } } @@ -925,7 +965,7 @@ public function validateSubmit($params) */ protected function _validateConf() { - $conf = $this->getConf(); + $conf = $this->getConf(); $native = isset($conf['native']) && is_array($conf['native']) ? $conf['native'] : false; $errors = Mage::helper('xmlconnect')->getDeviceHelper($this)->validateConfig($native); @@ -981,9 +1021,7 @@ public function prepareSubmitParams($data) $params['code'] = $this->getCode(); $params['type'] = $this->getType(); $params['url'] = Mage::getUrl('xmlconnect/configuration/index', array( - '_store' => $this->getStoreId(), - '_nosid' => true, - 'app_code' => $this->getCode() + '_store' => $this->getStoreId(), '_nosid' => true, 'app_code' => $this->getCode() )); $params['magentoversion'] = Mage::getVersion(); @@ -1001,7 +1039,8 @@ public function prepareSubmitParams($data) } else { $params['key'] = isset($params['key']) ? trim($params['key']) : ''; } - // processing files : + + // processing files $submit = array(); if (isset($this->_data['conf']['submit']) && is_array($this->_data['conf']['submit'])) { $submit = $this->_data['conf']['submit']; @@ -1012,14 +1051,12 @@ public function prepareSubmitParams($data) $submitRestore = $this->_data['conf']['submit_restore']; } - $deviceImages = Mage::helper('xmlconnect') - ->getDeviceHelper() - ->getSubmitImages(); + $deviceImages = Mage::helper('xmlconnect')->getDeviceHelper()->getSubmitImages(); foreach ($deviceImages as $id) { if (isset($submit[$id])) { $params[$id] = '@' . $submit[$id]; - } else if (isset($submitRestore[$id])) { + } elseif (isset($submitRestore[$id])) { $params[$id] = $submitRestore[$id]; } } @@ -1049,9 +1086,7 @@ public function getStoreId() public function getActivationKey() { $key = null; - 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'])) { + if (isset($this->_data['conf']['submit_text']['key'])) { $key = $this->_data['conf']['submit_text']['key']; } return $key; @@ -1068,6 +1103,16 @@ public function updateAllAppsUpdatedAtParameter() return $this; } + /** + * Checks if notifications is active + * + * @return boolean + */ + public function isNotificationsActive() + { + return (boolean)$this->loadConfiguration()->getData('conf/native/notifications/isActive'); + } + /** * Getter return concatenated user and password * 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 66bfa13255..3e801a346a 100644 --- a/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php +++ b/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php @@ -27,9 +27,9 @@ /** * Catalog category link model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Model_Catalog_Category_Image extends Mage_Catalog_Model_Product_Image { @@ -58,21 +58,26 @@ public function setBaseFile($file) } if (!$file) { // check if placeholder defined in config - $isConfigPlaceholder = Mage::getStoreConfig("catalog/placeholder/{$this->getDestinationSubdir()}_placeholder"); + $isConfigPlaceholder = Mage::getStoreConfig( + 'catalog/placeholder/' . $this->getDestinationSubdir() . '_placeholder' + ); $configPlaceholder = '/placeholder/' . $isConfigPlaceholder; if ($isConfigPlaceholder && file_exists($baseDir . $configPlaceholder)) { $file = $configPlaceholder; } else { // replace file with skin or default skin placeholder $skinBaseDir = Mage::getDesign()->getSkinBaseDir(); - $skinPlaceholder = "/images/xmlconnect/catalog/category/placeholder/{$this->getDestinationSubdir()}.jpg"; + $skinPlaceholder = '/images/xmlconnect/catalog/category/placeholder/' . $this->getDestinationSubdir() + . '.jpg'; + $file = $skinPlaceholder; if (file_exists($skinBaseDir . $file)) { $baseDir = $skinBaseDir; } else { $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default')); if (!file_exists($baseDir . $file)) { - $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default', '_package' => 'base')); + $baseDir = Mage::getDesign() + ->getSkinBaseDir(array('_theme' => 'default', '_package' => 'base')); } } } @@ -82,30 +87,24 @@ public function setBaseFile($file) $baseFile = $baseDir . $file; if ((!$file) || (!file_exists($baseFile))) { - throw new Exception(Mage::helper('xmlconnect')->__('Image file was not found.')); + Mage::throwException(Mage::helper('xmlconnect')->__('Image file was not found.')); } $this->_baseFile = $baseFile; // build new filename (most important params) - $path = array( - Mage::getSingleton('xmlconnect/catalog_category_media_config')->getBaseMediaPath(), - 'cache', - Mage::app()->getStore()->getId(), - $path[] = $this->getDestinationSubdir() + $path = array(Mage::getSingleton('xmlconnect/catalog_category_media_config')->getBaseMediaPath(), 'cache', + Mage::app()->getStore()->getId(), $path[] = $this->getDestinationSubdir() ); - if ((!empty($this->_width)) || (!empty($this->_height))) + if ((!empty($this->_width)) || (!empty($this->_height))) { $path[] = "{$this->_width}x{$this->_height}"; + } // add misk params as a hash - $miscParams = array( - ($this->_keepAspectRatio ? '' : 'non') . 'proportional', - ($this->_keepFrame ? '' : 'no') . 'frame', - ($this->_keepTransparency ? '' : 'no') . 'transparency', - ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly', - $this->_rgbToString($this->_backgroundColor), - 'angle' . $this->_angle, - 'quality' . $this->_quality + $miscParams = array(($this->_keepAspectRatio ? '' : 'non') . 'proportional', + ($this->_keepFrame ? '' : 'no') . 'frame', ($this->_keepTransparency ? '' : 'no') . 'transparency', + ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly', $this->_rgbToString($this->_backgroundColor), + 'angle' . $this->_angle, 'quality' . $this->_quality ); // if has watermark add watermark params to hash @@ -141,17 +140,17 @@ protected function _getWatermarkFilePath() $baseDir = Mage::getSingleton('xmlconnect/catalog_category_media_config')->getBaseMediaPath(); - if ( file_exists($baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file) ) { + if (file_exists($baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file)) { $filePath = $baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file; - } elseif ( file_exists($baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file) ) { + } elseif (file_exists($baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file)) { $filePath = $baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file; - } elseif ( file_exists($baseDir . '/watermark/default/' . $file) ) { + } elseif (file_exists($baseDir . '/watermark/default/' . $file)) { $filePath = $baseDir . '/watermark/default/' . $file; - } elseif ( file_exists($baseDir . '/watermark/' . $file) ) { + } elseif (file_exists($baseDir . '/watermark/' . $file)) { $filePath = $baseDir . '/watermark/' . $file; } else { $baseDir = Mage::getDesign()->getSkinBaseDir(); - if ( file_exists($baseDir . $file) ) { + if (file_exists($baseDir . $file)) { $filePath = $baseDir . $file; } } @@ -162,13 +161,13 @@ protected function _getWatermarkFilePath() /** * Clear catalog cache * - * @return void + * @return null */ public function clearCache() { - $directory = Mage::getBaseDir('media') . DS.'catalog'.DS.'category'.DS.'cache'.DS; - $io = new Varien_Io_File(); - $io->rmdir($directory, true); + $directory = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS . 'cache' . DS; + $ioFile = new Varien_Io_File(); + $ioFile->rmdir($directory, true); } /** 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 a68fce610f..f4b47d32c5 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 @@ -45,7 +45,7 @@ public function getBaseMediaPath() /** * Getter, return catalog baseMediaUrl - * + * * @return string */ public function getBaseMediaUrl() diff --git a/app/code/core/Mage/XmlConnect/Model/ConfigData.php b/app/code/core/Mage/XmlConnect/Model/ConfigData.php index 3f0949cde7..486ff1c137 100644 --- a/app/code/core/Mage/XmlConnect/Model/ConfigData.php +++ b/app/code/core/Mage/XmlConnect/Model/ConfigData.php @@ -60,7 +60,7 @@ class Mage_XmlConnect_Model_ConfigData extends Mage_Core_Model_Abstract /** * Initialize configuration data * - * @return void + * @return null */ protected function _construct() { @@ -154,11 +154,7 @@ public function initSaveConfig() $applicationId = str_ireplace(self::CONFIG_PREFIX, '', $application); $this->_deleteOnUpdate($applicationId); foreach ($data as $category => $config) { - $this->saveConfig( - $applicationId, - $config, - $category - ); + $this->saveConfig($applicationId, $config, $category); } } return $this; @@ -176,9 +172,7 @@ public function saveConfig($applicationId, array $configData, $category = self:: { foreach ($configData as $path => $value) { if (!is_scalar($value)) { - Mage::throwException( - Mage::helper('xmlconnect')->__('Unsupported value type received') - ); + Mage::throwException(Mage::helper('xmlconnect')->__('Unsupported value type received')); } $this->getResource()->saveConfig($applicationId, $category, $path, $value); } diff --git a/app/code/core/Mage/XmlConnect/Model/History.php b/app/code/core/Mage/XmlConnect/Model/History.php index 3ac634eca2..0a84cc8398 100644 --- a/app/code/core/Mage/XmlConnect/Model/History.php +++ b/app/code/core/Mage/XmlConnect/Model/History.php @@ -24,9 +24,8 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** - * XmlConnect Model History + * Xmlconnect history model * * @method Mage_XmlConnect_Model_Resource_History _getResource() * @method Mage_XmlConnect_Model_Resource_History getResource() @@ -54,7 +53,7 @@ class Mage_XmlConnect_Model_History extends Mage_Core_Model_Abstract /** * Initialize application * - * @return void + * @return null */ protected function _construct() { @@ -64,7 +63,7 @@ protected function _construct() /** * Get array of existing images * - * @param int $id application instance Id + * @param int $id Application instance Id * @return array */ public function getLastParams($id) diff --git a/app/code/core/Mage/XmlConnect/Model/Observer.php b/app/code/core/Mage/XmlConnect/Model/Observer.php index d9ae7c2255..5bf0b4de8f 100644 --- a/app/code/core/Mage/XmlConnect/Model/Observer.php +++ b/app/code/core/Mage/XmlConnect/Model/Observer.php @@ -25,10 +25,10 @@ */ /** - * XmlConnect Model Observer + * XmlConnect module observer * * @category Mage - * @package Mage_XmlConnect + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Model_Observer @@ -70,11 +70,9 @@ public function restrictWebsite($observer) public function changeUpdatedAtParamOnConfigSave($observer) { $configData = $observer->getEvent()->getConfigData(); - if ($configData - && (int)$configData->isValueChanged() + if ($configData && (int)$configData->isValueChanged() && in_array($configData->getPath(), $this->_appDependOnConfigFieldPathes) - ) - { + ) { Mage::getModel('xmlconnect/application')->updateAllAppsUpdatedAtParameter(); } } @@ -83,16 +81,14 @@ public function changeUpdatedAtParamOnConfigSave($observer) * Send a message if Start Date (Queue Date) is empty * * @param Varien_Event_Observer $observer + * @return bool */ public function sendMessageImmediately($observer) { $message = $observer->getEvent()->getData('queueMessage'); - if ($message instanceof Mage_XmlConnect_Model_Queue - && (strtolower($message->getExecTime()) == 'null' - || !$message->getExecTime() - ) - ) - { + 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; @@ -102,19 +98,16 @@ public function sendMessageImmediately($observer) } /** - * Send sheduled messages + * Send scheduled messages * - * @param mixed $schedule + * @return null */ - public function scheduledSend($schedule = null) + public function scheduledSend() { $countOfQueue = Mage::getStoreConfig(Mage_XmlConnect_Model_Queue::XML_PATH_CRON_MESSAGES_COUNT); - $collection = Mage::getModel('xmlconnect/queue')->getCollection() - ->addOnlyForSendingFilter() - ->setPageSize($countOfQueue) - ->setCurPage(1) - ->load(); + $collection = Mage::getModel('xmlconnect/queue')->getCollection()->addOnlyForSendingFilter() + ->setPageSize($countOfQueue)->setCurPage(1)->load(); foreach ($collection as $message) { if ($message->getId()) { diff --git a/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Config.php b/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Config.php new file mode 100644 index 0000000000..30ff9fab3e --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Config.php @@ -0,0 +1,51 @@ + + */ +class Mage_XmlConnect_Model_Payment_Method_Paypal_Config extends Mage_Paypal_Model_Config +{ + /** + * PayPal Website Payments Pro - PayPal Mobile Express Checkout Library + */ + const METHOD_WPP_MECL = 'paypal_mecl'; + + /** + * Get url for dispatching customer to express checkout start + * + * @param string $token + * @return string + */ + public function getExpressCheckoutStartUrl($token) + { + return $this->getPaypalUrl(array('cmd' => '_express-checkout-mobile', 'token' => $token)); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mecl.php b/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mecl.php new file mode 100644 index 0000000000..e22886200f --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Payment/Method/Paypal/Mecl.php @@ -0,0 +1,101 @@ + + */ +class Mage_XmlConnect_Model_Payment_Method_Paypal_Mecl extends Mage_Paypal_Model_Express +{ + /** + * Store MECL payment method code + */ + const MECL_METHOD_CODE = 'paypal_mecl'; + + /** + * Payment method code + * + * @var string + */ + protected $_code = self::MECL_METHOD_CODE; + + /** + * Can use method for a frontend checkout + * + * @var bool + */ + protected $_canUseCheckout = false; + + /** + * Can method be used for multishipping checkout type + * + * @var bool + */ + protected $_canUseForMultishipping = false; + + /** + * Can method manage recurring profiles + * + * @var bool + */ + protected $_canManageRecurringProfiles = false; + + /** + * Check whether payment method can be used + * + * @param Mage_Sales_Model_Quote $quote + * @return bool + */ + 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 (bool) Mage::getModel('paypal/config')->setStoreId($storeId) + ->isMethodAvailable(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS); + } + + /** + * Return title of the PayPal Mobile Express Checkout Payment method + * + * @return string + */ + public function getTitle() + { + return Mage::helper('xmlconnect')->__('PayPal Mobile Express Checkout'); + } +} 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 249a23d465..f527565154 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 @@ -81,8 +81,7 @@ public function isAvailable($quote = null) $storeId = $quote ? $quote->getStoreId() : Mage::app()->getStore()->getId(); } - return Mage::getModel('paypal/config') - ->setStoreId($storeId) + return (bool) Mage::getModel('paypal/config')->setStoreId($storeId) ->isMethodAvailable(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS); } diff --git a/app/code/core/Mage/XmlConnect/Model/Paypal/Mecl/Checkout.php b/app/code/core/Mage/XmlConnect/Model/Paypal/Mecl/Checkout.php new file mode 100644 index 0000000000..02ce8c2ead --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Paypal/Mecl/Checkout.php @@ -0,0 +1,42 @@ + + */ +class Mage_XmlConnect_Model_Paypal_Mecl_Checkout extends Mage_Paypal_Model_Express_Checkout +{ + /** + * Payment method type + * + * @var string + */ + protected $_methodType = Mage_XmlConnect_Model_Payment_Method_Paypal_Config::METHOD_WPP_MECL; +} 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 38d05eb318..111b28b99d 100644 --- a/app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php +++ b/app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php @@ -74,7 +74,6 @@ class Mage_XmlConnect_Model_Paypal_Mep_Checkout * * @throws Mage_Core_Exception * @param array $params - * @return void */ public function __construct($params = array()) { @@ -82,7 +81,9 @@ public function __construct($params = array()) if (isset($params['quote']) && $params['quote'] instanceof Mage_Sales_Model_Quote) { $this->_quote = $params['quote']; } else { - Mage::throwException(Mage::helper('xmlconnect')->__('Quote instance is required.')); + Mage::throwException( + Mage::helper('xmlconnect')->__('Quote instance is required.') + ); } } @@ -113,7 +114,8 @@ public function initCheckout() $this->_quote->assignCustomer($customer); } if (!Mage::getSingleton('customer/session')->isLoggedIn() - && Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout()) { + && Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout() + ) { $this->_prepareGuestQuote(); } return $this->_quote->getReservedOrderId(); @@ -173,9 +175,7 @@ public function saveShipping($data) $billing->unsAddressId()->unsAddressType(); $shipping = $this->_quote->getShippingAddress(); $shippingMethod = $shipping->getShippingMethod(); - $shipping->addData($billing->getData()) - ->setSameAsBilling(1) - ->setShippingMethod($shippingMethod) + $shipping->addData($billing->getData())->setSameAsBilling(1)->setShippingMethod($shippingMethod) ->setCollectShippingRates(true); } @@ -204,10 +204,8 @@ public function saveShippingMethod($shippingMethod) if (!$this->_quote->getIsVirtual() && $shippingAddress) { if ($shippingMethod != $shippingAddress->getShippingMethod()) { $this->_ignoreAddressValidation(); - $this->_quote->getShippingAddress() - ->setShippingMethod($shippingMethod); - $this->_quote->collectTotals() - ->save(); + $this->_quote->getShippingAddress()->setShippingMethod($shippingMethod); + $this->_quote->collectTotals()->save(); } } @@ -235,8 +233,7 @@ public function savePayment($data) $email = isset($data['payer']) ? $data['payer'] : null; $payment->setAdditionalInformation(self::PAYMENT_INFO_PAYER_EMAIL, $email); $payment->setAdditionalInformation( - self::PAYMENT_INFO_TRANSACTION_ID, - isset($data['transaction_id']) ? $data['transaction_id'] : null + self::PAYMENT_INFO_TRANSACTION_ID, isset($data['transaction_id']) ? $data['transaction_id'] : null ); $this->_quote->setCustomerEmail($email); @@ -258,15 +255,14 @@ public function saveOrder() $order = Mage::getModel('sales/service_quote', $this->_quote)->submit(); $this->_quote->save(); + $this->_getCheckoutSession()->clear(); + /** * Prepare session to success or cancellation page */ $quoteId = $this->_quote->getId(); - $this->_getCheckoutSession() - ->setLastQuoteId($quoteId) - ->setLastSuccessQuoteId($quoteId) - ->setLastOrderId($order->getId()) - ->setLastRealOrderId($order->getIncrementId()); + $this->_getCheckoutSession()->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId) + ->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId()); if ($order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING && Mage::getSingleton('customer/session')->isLoggedIn() @@ -301,7 +297,7 @@ public function getLastOrderId() /** * Make sure addresses will be saved without validation errors * - * @return void + * @return null */ protected function _ignoreAddressValidation() { @@ -329,8 +325,7 @@ protected function _getCheckoutSession() protected function _prepareGuestQuote() { $quote = $this->_quote; - $quote->setCustomerId(null) - ->setCustomerIsGuest(true) + $quote->setCustomerId(null)->setCustomerIsGuest(true) ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); return $this; } @@ -339,7 +334,7 @@ protected function _prepareGuestQuote() * Adopt specified request array from PayPal * * @param array $request - * @return void + * @return null */ protected function _applyCountryWorkarounds(&$request) { diff --git a/app/code/core/Mage/XmlConnect/Model/Preview/Abstract.php b/app/code/core/Mage/XmlConnect/Model/Preview/Abstract.php index 24365f9781..34794c2b8a 100755 --- a/app/code/core/Mage/XmlConnect/Model/Preview/Abstract.php +++ b/app/code/core/Mage/XmlConnect/Model/Preview/Abstract.php @@ -58,7 +58,7 @@ abstract class Mage_XmlConnect_Model_Preview_Abstract extends Varien_Object * Internal constructor not depended on params. * It's used for application object initialization * - * @return void + * @return null */ final function _construct() { @@ -67,9 +67,9 @@ final function _construct() } /** - * Getter for current loaded application model + * Setter for current loaded application model * - * @return Mage_XmlConnect_Model_Application + * @return Mage_XmlConnect_Model_Preview_Abstract */ protected function setApplicationModel() { @@ -79,6 +79,12 @@ protected function setApplicationModel() return $this; } + + /** + * Getter for current loaded application model + * + * @return Mage_XmlConnect_Model_Application + */ public function getApplicationModel() { return $this->setApplicationModel()->_appModel; @@ -145,7 +151,7 @@ public function setConf($conf) if (!is_array($conf)) { $conf = array(); } - $tabs = isset($conf['tabBar']) && isset($conf['tabBar']['tabs']) ? $conf['tabBar']['tabs'] : false; + $tabs = isset($conf['tabBar']['tabs']) ? $conf['tabBar']['tabs'] : false; if ($tabs !== false) { foreach ($tabs->getEnabledTabs() as $tab) { $tab = (array) $tab; @@ -215,45 +221,44 @@ public function getLogoUrl() public function getCategoryItemTintColor() { if (!strlen($this->_categoryItemTintColor)) { - $percent = .4; - $mask = 255; + $percent = 0.4; + $mask = 255; - $hex = str_replace('#','',$this->getData('conf/categoryItem/tintColor')); - $hex2 = ''; - $_rgb = array(); + $hex = str_replace('#', '', $this->getData('conf/categoryItem/tintColor')); + $hex2 = ''; + $_rgb = array(); - $d = '[a-fA-F0-9]'; + $hexChars = '[a-fA-F0-9]'; - if (preg_match("/^($d$d)($d$d)($d$d)\$/", $hex, $rgb)) { + if (preg_match("/^($hexChars{2})($hexChars{2})($hexChars{2})$/", $hex, $rgb)) { $_rgb = array(hexdec($rgb[1]), hexdec($rgb[2]), hexdec($rgb[3])); - } - if (preg_match("/^($d)($d)($d)$/", $hex, $rgb)) { + } elseif (preg_match("/^($hexChars)($hexChars)($hexChars)$/", $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)); + 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) { + if (strlen($hex_digit) == 1) { $hex_digit = "0" . $hex_digit; } $hex2 .= $hex_digit; } - if($hex && $hex2){ + + if ($hex && $hex2) { // for IE $this->_categoryItemTintColor .= "filter: progid:DXImageTransform.Microsoft.gradient"; - $this->_categoryItemTintColor .= "(startColorstr='#".$hex2."', endColorstr='#".$hex."');"; + $this->_categoryItemTintColor .= "(startColorstr='#" . $hex2 . "', endColorstr='#" . $hex . "');"; // for webkit browsers $this->_categoryItemTintColor .= "background:-webkit-gradient"; - $this->_categoryItemTintColor .= "(linear, left top, left bottom, from(#".$hex2."), to(#".$hex."));"; + $this->_categoryItemTintColor .= "(linear, left top, left bottom,"; + $this->_categoryItemTintColor .= " from(#" . $hex2 . "), to(#" . $hex . "));"; // for firefox - $this->_categoryItemTintColor .= "background:-moz-linear-gradient(top, #".$hex2.", #".$hex.");"; + $this->_categoryItemTintColor .= "background:-moz-linear-gradient"; + $this->_categoryItemTintColor .= "(top, #" . $hex2 . ", #" . $hex . ");"; } } return $this->_categoryItemTintColor; diff --git a/app/code/core/Mage/XmlConnect/Model/Preview/Iphone.php b/app/code/core/Mage/XmlConnect/Model/Preview/Iphone.php index 639bfe6cd2..9a946e12e5 100755 --- a/app/code/core/Mage/XmlConnect/Model/Preview/Iphone.php +++ b/app/code/core/Mage/XmlConnect/Model/Preview/Iphone.php @@ -57,13 +57,12 @@ public function getBannerImage() */ public function getBackgroundImage() { - $backgroundImage = ''; $configPath = 'conf/body/backgroundImage'; $imageUrlOrig = $this->getData($configPath); if ($imageUrlOrig) { $backgroundImage = $imageUrlOrig; } else { - $backgroundImage = $this->getPreviewImagesUrl('banner.png'); + $backgroundImage = $this->getPreviewImagesUrl('background.png'); } return $backgroundImage; } diff --git a/app/code/core/Mage/XmlConnect/Model/Queue.php b/app/code/core/Mage/XmlConnect/Model/Queue.php index 329199428e..343b1bec06 100755 --- a/app/code/core/Mage/XmlConnect/Model/Queue.php +++ b/app/code/core/Mage/XmlConnect/Model/Queue.php @@ -25,10 +25,10 @@ */ /** - * XmlConnect Model Queue + * XmlConnect Queue model * * @category Mage - * @package Mage_XmlConnect + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Model_Queue extends Mage_Core_Model_Template @@ -84,7 +84,7 @@ class Mage_XmlConnect_Model_Queue extends Mage_Core_Model_Template /** * Initialize queue message * - * @return void + * @return null */ protected function _construct() { @@ -94,17 +94,16 @@ protected function _construct() /** * Load object data * - * @param integer $id - * @return Mage_Core_Model_Abstract + * @param int $id + * @param string $field + * @return Mage_XmlConnect_Model_Queue */ - public function load($id, $field=null) + public function load($id, $field = null) { parent::load($id, $field); if ($this->getTemplateId()) { - $this->setName( - Mage::getModel('xmlconnect/template')->load($this->getTemplateId())->getName() - ); + $this->setName(Mage::getModel('xmlconnect/template')->load($this->getTemplateId())->getName()); } return $this; } @@ -187,16 +186,16 @@ public function getProcessedTemplate(array $variables = array()) 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()); + . $this->getPushTitle() + . sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Message title')) + . $this->getMessageTitle() + . 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(); + . $this->getPushTitle(); break; } return $html; @@ -241,11 +240,7 @@ public function getAirmailBroadcastParams() ); $payload = array( - 'push' => array( - $notificationType => array( - 'alert' => $this->getPushTitle(), - ) - ), + 'push' => array($notificationType => array('alert' => $this->getPushTitle())), 'title' => $this->getMessageTitle(), 'message' => $this->getContent(), ); diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Application.php b/app/code/core/Mage/XmlConnect/Model/Resource/Application.php index f5cc05038a..7e78710983 100755 --- a/app/code/core/Mage/XmlConnect/Model/Resource/Application.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Application.php @@ -36,7 +36,7 @@ class Mage_XmlConnect_Model_Resource_Application extends Mage_Core_Model_Resourc /** * Constructor, setting table and index field * - * @return void + * @return null */ protected function _construct() { @@ -55,9 +55,7 @@ public function updateApplicationStatus($applicationId, $status) $this->_getWriteAdapter()->update( $this->getMainTable(), array('status' => $status), - $this->_getWriteAdapter()->quoteInto( - $this->getIdFieldName() . '=?', $applicationId - ) + $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $applicationId) ); return $this; } @@ -92,9 +90,7 @@ protected function _afterSave(Mage_Core_Model_Abstract $object) $this->_getWriteAdapter()->update( $this->getMainTable(), array('code' => $appCode . $object->getId()), - $this->_getWriteAdapter()->quoteInto( - $this->getIdFieldName() . '=?', $object->getId() - ) + $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId()) ); } return parent::_afterSave($object); @@ -107,10 +103,8 @@ protected function _afterSave(Mage_Core_Model_Abstract $object) */ public function getExistingStoreDeviceType() { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable(), array('store_id', 'type')) - ->group(array('store_id', 'type')) - ->order(array('store_id', 'type')); + $select = $this->_getWriteAdapter()->select()->from($this->getMainTable(), array('store_id', 'type')) + ->group(array('store_id', 'type'))->order(array('store_id', 'type')); return $this->_getReadAdapter()->fetchAll($select, array('store_id', 'type')); } @@ -121,10 +115,7 @@ public function getExistingStoreDeviceType() */ public function updateAllAppsUpdatedAtParameter() { - $this->_getWriteAdapter()->update( - $this->getMainTable(), - array('updated_at' => date('Y-m-d H:i:s')) - ); + $this->_getWriteAdapter()->update($this->getMainTable(), array('updated_at' => date('Y-m-d H:i:s'))); return $this; } } diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Application/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/Application/Collection.php index 4f4da73be8..8bcde33208 100755 --- a/app/code/core/Mage/XmlConnect/Model/Resource/Application/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Application/Collection.php @@ -36,7 +36,7 @@ class Mage_XmlConnect_Model_Resource_Application_Collection extends Mage_Core_Mo /** * Constructor, setting table * - * @return void + * @return null */ protected function _construct() { diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/ConfigData.php b/app/code/core/Mage/XmlConnect/Model/Resource/ConfigData.php index a4878549c5..37801f09b4 100644 --- a/app/code/core/Mage/XmlConnect/Model/Resource/ConfigData.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/ConfigData.php @@ -36,7 +36,7 @@ class Mage_XmlConnect_Model_Resource_ConfigData extends Mage_Core_Model_Mysql4_A /** * Initialize configuration data * - * @return void + * @return null */ protected function _construct() { @@ -61,11 +61,7 @@ public function saveConfig($applicationId, $category, $path, $value) 'value' => $value ); - $this->_getWriteAdapter()->insertOnDuplicate( - $this->getMainTable(), - $newData, - array('value') - ); + $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), $newData, array('value')); return $this; } @@ -88,8 +84,7 @@ public function deleteConfig($applicationId, $category = false, $path = false, $ $deleteWhere[] = $writeAdapter->quoteInto('category=?', $category); } if ($path) { - $deleteWhere[] = $pathLike - ? $writeAdapter->quoteInto('path like ?', $path . '/%') + $deleteWhere[] = $pathLike ? $writeAdapter->quoteInto('path like ?', $path . '/%') : $writeAdapter->quoteInto('path=?', $path); } $writeAdapter->delete($this->getMainTable(), $deleteWhere); diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/ConfigData/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/ConfigData/Collection.php index 2001503570..13705353a9 100644 --- a/app/code/core/Mage/XmlConnect/Model/Resource/ConfigData/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/ConfigData/Collection.php @@ -31,8 +31,7 @@ * @package Mage_Xmlconnect * @author Magento Core Team */ -class Mage_XmlConnect_Model_Resource_ConfigData_Collection - extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_XmlConnect_Model_Resource_ConfigData_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract { /** * Is application filter applied @@ -58,8 +57,7 @@ protected function _construct() public function addApplicationIdFilter($applicationId) { $this->_applicationFilter = true; - $this->getSelect() - ->where('application_id=?', $applicationId); + $this->getSelect()->where('application_id=?', $applicationId); return $this; } @@ -73,11 +71,9 @@ public function addApplicationIdFilter($applicationId) public function addPathFilter($path, $like = true) { if ($like) { - $this->getSelect() - ->where('path like ?', $path . '/%'); + $this->getSelect()->where('path like ?', $path . '/%'); } else { - $this->getSelect() - ->where('path=?', $path); + $this->getSelect()->where('path=?', $path); } return $this; } diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/History.php b/app/code/core/Mage/XmlConnect/Model/Resource/History.php index 355bed4aed..b538fe7ff8 100755 --- a/app/code/core/Mage/XmlConnect/Model/Resource/History.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/History.php @@ -36,7 +36,7 @@ class Mage_XmlConnect_Model_Resource_History extends Mage_Core_Model_Resource_Db /** * Constructor, setting table and index field * - * @return void + * @return null */ protected function _construct() { @@ -77,10 +77,8 @@ public function getLastParams($id) { $paramArray = array(); $idFieldName = Mage::getModel('xmlconnect/application')->getIdFieldName(); - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), 'params') - ->where($idFieldName . '=?', $id) - ->order(array('created_at ' . Zend_Db_Select::SQL_DESC)); + $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), 'params') + ->where($idFieldName . '=?', $id)->order(array('created_at ' . Zend_Db_Select::SQL_DESC)); $params = $this->_getReadAdapter()->fetchOne($select); diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/History/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/History/Collection.php index a33349e517..889f7b9159 100755 --- a/app/code/core/Mage/XmlConnect/Model/Resource/History/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/History/Collection.php @@ -31,8 +31,7 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Model_Resource_History_Collection - extends Mage_Core_Model_Resource_Db_Collection_Abstract +class Mage_XmlConnect_Model_Resource_History_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { /** * Internal constructor diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Queue.php b/app/code/core/Mage/XmlConnect/Model/Resource/Queue.php index c04108b179..21d483d3a9 100755 --- a/app/code/core/Mage/XmlConnect/Model/Resource/Queue.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Queue.php @@ -36,7 +36,7 @@ class Mage_XmlConnect_Model_Resource_Queue extends Mage_Core_Model_Resource_Db_A /** * Constructor, setting table and index field * - * @return void + * @return null */ protected function _construct() { diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Queue/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/Queue/Collection.php index 7d97e8101d..c9fb3bc50c 100755 --- a/app/code/core/Mage/XmlConnect/Model/Resource/Queue/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Queue/Collection.php @@ -31,13 +31,12 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Model_Resource_Queue_Collection - extends Mage_Core_Model_Resource_Db_Collection_Abstract +class Mage_XmlConnect_Model_Resource_Queue_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { /** * Internal constructor * - * @return void + * @return null */ protected function _construct() { @@ -75,11 +74,10 @@ protected function _joinNames() */ protected function _joinTemplateName() { - $this->getSelect() - ->joinLeft( - array('t' => $this->getTable('xmlconnect/template')), - 't.template_id = main_table.template_id', - array('template_name' => 't.name') + $this->getSelect()->joinLeft( + array('t' => $this->getTable('xmlconnect/template')), + 't.template_id = main_table.template_id', + array('template_name' => 't.name') ); return $this; } @@ -91,11 +89,10 @@ protected function _joinTemplateName() */ protected function _joinApplicationName() { - $this->getSelect() - ->joinLeft( - array('app' => $this->getTable('xmlconnect/application')), - 'app.application_id = t.application_id', - array('application_name' => 'app.name') + $this->getSelect()->joinLeft( + array('app' => $this->getTable('xmlconnect/application')), + 'app.application_id = t.application_id', + array('application_name' => 'app.name') ); return $this; } @@ -107,8 +104,7 @@ protected function _joinApplicationName() */ public function addOnlyForSendingFilter() { - $this->getSelect() - ->where('main_table.status in (?)', array(Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE)) + $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) ); diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Template.php b/app/code/core/Mage/XmlConnect/Model/Resource/Template.php index ae02a4cf6d..03dae7d771 100755 --- a/app/code/core/Mage/XmlConnect/Model/Resource/Template.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Template.php @@ -36,7 +36,7 @@ class Mage_XmlConnect_Model_Resource_Template extends Mage_Core_Model_Resource_D /** * Constructor, setting table and index field * - * @return void + * @return null */ protected function _construct() { diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Template/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/Template/Collection.php index 077fb210ec..f0f00699dd 100755 --- a/app/code/core/Mage/XmlConnect/Model/Resource/Template/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Template/Collection.php @@ -31,13 +31,12 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Model_Resource_Template_Collection - extends Mage_Core_Model_Resource_Db_Collection_Abstract +class Mage_XmlConnect_Model_Resource_Template_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { /** * Internal constructor * - * @return void + * @return null */ protected function _construct() { @@ -63,11 +62,10 @@ protected function _initSelect() */ protected function _joinApplicationName() { - $this->getSelect() - ->joinLeft( - array('app' => $this->getTable('xmlconnect/application')), - 'app.application_id = main_table.application_id', - array('app_name' => 'app.name', 'app_code' => 'app.code') + $this->getSelect()->joinLeft( + array('app' => $this->getTable('xmlconnect/application')), + 'app.application_id = main_table.application_id', + array('app_name' => 'app.name', 'app_code' => 'app.code') ); return $this; } diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php index d253ed12bc..67aea94c7a 100644 --- a/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php @@ -25,10 +25,11 @@ */ /** - * * XmlConnect fixed Varien SimpleXML Element class * - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Model_Simplexml_Element extends Varien_Simplexml_Element { @@ -41,14 +42,7 @@ class Mage_XmlConnect_Model_Simplexml_Element extends Varien_Simplexml_Element public function appendChild($source) { if (sizeof($source->children())) { - /** - * @link http://bugs.php.net/bug.php?id=41867 , fixed in 5.2.4 - */ - if (version_compare(phpversion(), '5.2.4', '<')===true) { - $name = $source->children()->getName(); - } else { - $name = $source->getName(); - } + $name = $source->getName(); $child = $this->addChild($name); } else { $child = $this->addChild($source->getName(), $this->xmlentities($source)); diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form.php new file mode 100644 index 0000000000..7af540c994 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form.php @@ -0,0 +1,388 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form extends Mage_XmlConnect_Model_Simplexml_Form_Abstract +{ + /** + * All form elements collection + * + * @var Mage_XmlConnect_Model_Simplexml_Form_Element_Collection + */ + protected $_allElements; + + /** + * form elements index + * + * @var array + */ + protected $_elementsIndex; + + /**#@+ + * Custom form components renderer + * + * @var object + */ + static protected $_defaultElementRenderer; + static protected $_defaultFieldsetRenderer; + static protected $_defaultValidatorRenderer; + static protected $_defaultValidatorRuleRenderer; + static protected $_defaultFieldsetElementRenderer; + /**#@-*/ + + /** + * Init simple xml form + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('form'); + $this->_allElements = Mage::getModel('xmlconnect/simplexml_form_element_collection', $this); + } + + /** + * Set element renderer + * + * @static $_defaultElementRenderer + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + * @return null + */ + public static function setElementRenderer( + Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + ) { + self::$_defaultElementRenderer = $renderer; + } + + /** + * Set validator renderer + * + * @static $_defaultValidatorRenderer + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + * @return null + */ + public static function setValidatorRenderer( + Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + ) { + self::$_defaultValidatorRenderer = $renderer; + } + + /** + * Set validator rule renderer + * + * @static $_defaultValidatorRuleRenderer + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + * @return null + */ + public static function setValidatorRuleRenderer( + Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + ) { + self::$_defaultValidatorRuleRenderer = $renderer; + } + + /** + * Set fieldset renderer + * + * @static $_defaultFieldsetRenderer + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + * @return null + */ + public static function setFieldsetRenderer( + Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + ) { + self::$_defaultFieldsetRenderer = $renderer; + } + + /** + * Set fieldset element renderer + * + * @static $_defaultFieldsetElementRenderer + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + * @return null + */ + public static function setFieldsetElementRenderer( + Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + ) { + self::$_defaultFieldsetElementRenderer = $renderer; + } + + /** + * Get element renderer + * + * @static $_defaultElementRenderer + * @return object + */ + public static function getElementRenderer() + { + return self::$_defaultElementRenderer; + } + + /** + * Get validator renderer + * + * @static $_defaultValidatorRenderer + * @return object + */ + public static function getValidatorRenderer() + { + return self::$_defaultValidatorRenderer; + } + + /** + * Get validator rule renderer + * + * @static $_defaultValidatorRuleRenderer + * @return object + */ + public static function getValidatorRuleRenderer() + { + return self::$_defaultValidatorRuleRenderer; + } + + /** + * Get fieldset renderer + * + * @static $_defaultFieldsetRenderer + * @return object + */ + public static function getFieldsetRenderer() + { + return self::$_defaultFieldsetRenderer; + } + + /** + * Get fieldset element renderer + * + * @static $_defaultFieldsetElementRenderer + * @return object + */ + public static function getFieldsetElementRenderer() + { + return self::$_defaultFieldsetElementRenderer; + } + + /** + * Add form element + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $element + * @param bool $after + * @return Mage_XmlConnect_Model_Simplexml_Form + */ + public function addElement(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $element, $after = false) + { + $this->checkElementId($element->getId()); + parent::addElement($element, $after); + $this->addElementToCollection($element); + return $this; + } + + /** + * Check existing element + * + * @param string $elementId + * @return bool + */ + protected function _elementIdExists($elementId) + { + return isset($this->_elementsIndex[$elementId]); + } + + /** + * Add form element to collection + * + * @param $element + * @return Mage_XmlConnect_Model_Simplexml_Form + */ + public function addElementToCollection($element) + { + $this->_elementsIndex[$element->getId()] = $element; + $this->_allElements->add($element); + return $this; + } + + /** + * Insure existing element + * + * @throws Exception + * @param $elementId + * @return bool + */ + public function checkElementId($elementId) + { + if ($this->_elementIdExists($elementId)) { + throw new Exception(Mage::helper('xmlconnect')->__('Element with id %s already exists', $elementId)); + } + return true; + } + + /** + * Get form object + * + * @return Mage_XmlConnect_Model_Simplexml_Form + */ + public function getForm() + { + return $this; + } + + /** + * Get element object + * + * @param $elementId + * @return null|Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + public function getElement($elementId) + { + if ($this->_elementIdExists($elementId)) { + return $this->_elementsIndex[$elementId]; + } + return null; + } + + /** + * Set values to the form elements + * + * @param array $values + * @return Mage_XmlConnect_Model_Simplexml_Form + */ + public function setValues($values) + { + foreach ($this->_allElements as $element) { + if (isset($values[$element->getId()])) { + $element->setValue($values[$element->getId()]); + } else { + $element->setValue(null); + } + } + return $this; + } + + /** + * Add values to the form elements + * + * @param array $values + * @return Mage_XmlConnect_Model_Simplexml_Form + */ + public function addValues($values) + { + if (!is_array($values)) { + return $this; + } + + foreach ($values as $elementId => $value) { + $element = $this->getElement($elementId); + if ($element) { + $element->setValue($value); + } + } + return $this; + } + + /** + * Remove field from collection + * + * @param string $elementId + * @return Mage_XmlConnect_Model_Simplexml_Form + */ + public function removeField($elementId) + { + if ($this->_elementIdExists($elementId)) { + unset($this->_elementsIndex[$elementId]); + } + return $this; + } + + /** + * Set field id prefix + * + * @param string $prefix + * @return Mage_XmlConnect_Model_Simplexml_Form + */ + public function setFieldContainerIdPrefix($prefix) + { + $this->setData('field_container_id_prefix', $prefix); + return $this; + } + + /** + * Get field container id prefix + * + * @return mixed + */ + public function getFieldContainerIdPrefix() + { + return $this->getData('field_container_id_prefix'); + } + + /** + * Retrieve form xml object or an array of Simplexml elements + * + * @return array|Mage_XmlConnect_Model_Simplexml_Element + */ + public function toXmlObject() + { + $xmlObj = $this->getXmlObject(); + if ($useContainer = $this->getUseContainer()) { + $this->_addRequiredAttributes($xmlObj); + foreach ($this->getAttributes() as $key => $val) { + $xmlObj->addAttribute($key, $xmlObj->xmlAttribute($val)); + } + } + + foreach ($this->getElements() as $element) { + $xmlObj->appendChild($element->toXmlObject()); + } + + if (!$useContainer) { + $result = array(); + foreach ($xmlObj->children() as $child) { + $result[] = $child; + } + } + return isset($result) ? $result : $xmlObj; + } + + /** + * Get from xml as string + * + * @throws Mage_Core_Exception + * @return string + */ + public function getXml() + { + if ($this->getUseContainer()) { + return $this->toXmlObject()->asNiceXml(); + } + Mage::throwException(Mage::helper('xmlconnect')->__('Container is not defined.')); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Abstract.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Abstract.php new file mode 100644 index 0000000000..7608e9068d --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Abstract.php @@ -0,0 +1,524 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Abstract extends Varien_Object +{ + /** + * Element unique id + * + * @var string + */ + protected $_id; + + /** + * Form level elements collection + * + * @var Mage_XmlConnect_Model_Simplexml_Form_Element_Collection + */ + protected $_elements; + + /** + * Element type classes + * + * @var array + */ + protected $_types = array(); + + /** + * From Simplexml object + * + * @var Mage_XmlConnect_Model_Simplexml_Element + */ + protected $_xml; + + /** + * Main element node + * + * @var string + */ + protected $_mainNode = 'form'; + + /** + * Is name attribute required + * + * @var bool + */ + protected $_nameRequired = true; + + /** + * Custom attributes array + * + * @var array + */ + protected $_customAttributes = array(); + + /** + * Init form model + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->_prepareXmlObject(); + } + + /** + * Init form parent Simplexml object + * + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected function _prepareXmlObject() + { + $this->setXmlObject( + Mage::getModel('xmlconnect/simplexml_element', '<' . $this->_mainNode . '>_mainNode . '>') + ); + return $this; + } + + /** + * Get base simple xml object + * + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function getXmlObject() + { + return $this->_xml; + } + + /** + * Set simple xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xml + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function setXmlObject(Mage_XmlConnect_Model_Simplexml_Element $xml) + { + $this->_xml = $xml; + return $this; + } + + /** + * Get element id + * + * @return string + */ + public function getId() + { + return $this->_id; + } + + /** + * Set element id + * + * @param $id + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function setId($id) + { + $this->_id = $id; + $this->setData('xml_id', $id); + return $this; + } + + /** + * Get element id + * + * @return string + */ + public function getXmlId() + { + return $this->getXmlIdPrefix() . $this->getData('xml_id') . $this->getXmlIdSuffix(); + } + + /** + * Add form element type + * + * @param string $type + * @param string $className + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function addType($type, $className) + { + $this->_types[$type] = $className; + return $this; + } + + /** + * Get elements collection + * + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Collection + */ + public function getElements() + { + if (empty($this->_elements)) { + $this->_elements = Mage::getModel('xmlconnect/simplexml_form_element_collection'); + } + return $this->_elements; + } + + /** + * Add form element + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $element + * @param bool|string $after + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function addElement(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $element, $after = false) + { + $element->setForm($this); + $this->getElements()->add($element, $after); + return $this; + } + + /** + * Add child element + * + * if $after parameter is false - add element to the end of a collection + * if $after parameter is ^ - prepend element to the beginning of a collection + * if $after parameter is string - add element after the element with some id + * + * @param string $elementId + * @param string $type + * @param array $config + * @param mixed $after + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function addField($elementId, $type, $config, $after = false) + { + if (isset($this->_types[$type])) { + $className = $this->_types[$type]; + } else { + $className = 'Mage_XmlConnect_Model_Simplexml_Form_Element_' . uc_words($type); + } + + $element = Mage::getModel($className, $config); + $element->setId($elementId); + $this->addElement($element, $after); + return $element; + } + + /** + * Remove element from collection + * + * @param string $elementId + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function removeField($elementId) + { + $this->getElements()->remove($elementId); + return $this; + } + + /** + * Add fieldset element + * + * @param string $elementId + * @param array $config + * @param bool|string $after + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset + */ + public function addFieldset($elementId, $config = array(), $after = false) + { + $element = Mage::getModel('xmlconnect/simplexml_form_element_fieldset', $config); + $element->setId($elementId); + $this->addElement($element, $after); + return $element; + } + + /** + * Add validator element + * + * @param array $config + * @param bool|string $after + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Validator + */ + public function addValidator($config = array(), $after = false) + { + $element = Mage::getModel('xmlconnect/simplexml_form_element_validator', $config); + $element->setId($this->getXmlId()); + $this->addElement($element, $after); + return $element; + } + + /** + * Get array of existing elements + * + * @param array $arrAttributes + * @return array + */ + public function __toArray(array $arrAttributes = array()) + { + $res = array(); + $res['config'] = $this->getData(); + $res['formElements']= array(); + foreach ($this->getElements() as $element) { + $res['formElements'][] = $element->toArray(); + } + return $res; + } + + /** + * Return allowed xml form attributes + * + * @return array + */ + public function getXmlAttributes() + { + return array('enctype'); + } + + /** + * Required form attribute array + * + * @return array + */ + public function getRequiredXmlAttributes() + { + return array('action' => null, 'method' => 'post'); + } + + /** + * Get after element xml + * + * @return array|Mage_XmlConnect_Model_Simplexml_Element + */ + public function getAfterElementXml() + { + return $this->getData('after_element_xml'); + } + + /** + * Get xml object attributes + * + * @param array $attributes + * @return array + */ + public function getXmlObjAttributes($attributes = array()) + { + $data = array(); + if (empty($attributes)) { + $attributes = array_keys($this->_data); + } + + foreach ($this->_data as $key => $value) { + if (in_array($key, $attributes)) { + $data[$key] = $value; + } + } + ksort($data); + return $data; + } + + /** + * Get object attributes array + * + * @return array + */ + public function getAttributes() + { + $attributes = array_merge($this->getXmlAttributes(), $this->getCustomAttributes()); + return $this->getXmlObjAttributes($attributes); + } + + /** + * Add after element xml to object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function addAfterXmlElementToObj(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + if ($this->_checkXmlInstance($this->getAfterElementXml())) { + $xmlObj->appendChild($this->getAfterElementXml()); + } elseif (is_array($this->getAfterElementXml())) { + foreach ($this->getAfterElementXml() as $afterElement) { + if (!$this->_checkXmlInstance($afterElement)) { + continue; + } + $xmlObj->appendChild($afterElement); + } + } + return $this; + } + + /** + * Add required attributes to element + * + * @throws Mage_Core_Exception + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected function _addRequiredAttributes(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $this->_addId($xmlObj); + $this->_addName($xmlObj); + + foreach ($this->getRequiredXmlAttributes() as $attribute => $defValue) { + $data = $this->getData($this->_underscore($attribute)); + if ($data) { + $xmlObj->addAttribute($attribute, $xmlObj->xmlAttribute($data)); + } elseif(null !== $defValue){ + $xmlObj->addAttribute($attribute, $xmlObj->xmlAttribute($defValue)); + } else { + Mage::throwException(Mage::helper('xmlconnect')->__('%s attribute is required.', $attribute)); + } + } + return $this; + } + + /** + * Add validator to element xml object + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected function _addValidator(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + return $this; + } + + /** + * Add form id to element + * + * @throws Mage_Core_Exception + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected function _addId(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + if ($this->getXmlId()) { + $xmlObj->addAttribute('id', $xmlObj->xmlAttribute($this->getXmlId())); + } else { + Mage::throwException( + Mage::helper('xmlconnect')->__('"id" attribute is required for a "%s" field.', $this->getType()) + ); + } + return $this; + } + + /** + * Add form name to element + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected function _addName(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + if ($this->getName()) { + $name = $this->getName(); + } elseif($this->getNameRequired()) { + $name = $this->getXmlId(); + } + + if (isset($name)) { + $xmlObj->addAttribute('name', $xmlObj->xmlAttribute($name)); + } + + return $this; + } + + /** + * Is object instance of Simplexml object + * + * @param $object + * @return bool + */ + protected function _checkXmlInstance($object) + { + return $object instanceof Mage_XmlConnect_Model_Simplexml_Element; + } + + /** + * Get is name required attribute + * + * @return boolean + */ + public function getNameRequired() + { + return $this->_nameRequired; + } + + /** + * Set is name required attribute + * + * @param boolean $nameRequired + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function setNameRequired($nameRequired) + { + $this->_nameRequired = $nameRequired; + return $this; + } + + /** + * Get custom attributes + * + * @return array + */ + public function getCustomAttributes() + { + return $this->_customAttributes; + } + + /** + * Set custom attributes + * + * @param array $customAttributes + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function setCustomAttributes(array $customAttributes) + { + $this->_customAttributes = $customAttributes; + return $this; + } + + /** + * Check value and return as array - attribute => value + * + * @param string $attribute + * @param mixed $value + * @return array + */ + public function checkAttribute($attribute, $value = null) + { + if (null === $value) { + $value = $this->getData($attribute); + } + + if (null !== $value) { + return array($attribute => $value); + } + return array(); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Abstract.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Abstract.php new file mode 100644 index 0000000000..2aed90b334 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Abstract.php @@ -0,0 +1,325 @@ + + */ +abstract class Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + extends Mage_XmlConnect_Model_Simplexml_Form_Abstract +{ + /** + * Element type + * + * @var string + */ + protected $_type; + + /** + * From element object + * + * @var Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected $_form; + + /** + * Main element node + * + * @var string + */ + protected $_mainNode = 'field'; + + /** + * Element renderer object + * + * @var object + */ + protected $_renderer; + + /** + * Init element object abstract + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->_renderer = Mage_XmlConnect_Model_Simplexml_Form::getElementRenderer(); + } + + /** + * Add form element + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $element + * @param bool $after + * @return Mage_XmlConnect_Model_Simplexml_Form + */ + public function addElement(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $element, $after = false) + { + if ($this->getForm()) { + $this->getForm()->checkElementId($element->getId()); + $this->getForm()->addElementToCollection($element); + } + + parent::addElement($element, $after); + return $this; + } + + /** + * Get element type + * + * @return string + */ + public function getType() + { + return $this->_type; + } + + /** + * Get form object + * + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function getForm() + { + return $this->_form; + } + + /** + * Get element id + * + * @return string + */ + public function getXmlId() + { + return $this->getForm()->getXmlIdPrefix() . $this->getData('xml_id') . $this->getForm()->getXmlIdSuffix(); + } + + /** + * Get element name + * + * @return string + */ + public function getName() + { + $name = $this->getData('name'); + if ($suffix = $this->getForm()->getFieldNameSuffix()) { + $name = $this->getForm()->addSuffixToName($name, $suffix); + } + return $name; + } + + /** + * Set element type + * + * @param $type + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + public function setType($type) + { + $this->_type = $type; + $this->setData('type', $type); + return $this; + } + + /** + * Set form object + * + * @param $form + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + public function setForm($form) + { + $this->_form = $form; + return $this; + } + + /** + * Remove field from a form + * + * @param $elementId + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function removeField($elementId) + { + $this->getForm()->removeField($elementId); + return parent::removeField($elementId); + } + + /** + * Element attributes array + * + * @return array + */ + public function getXmlAttributes() + { + return array('title', 'required', 'disabled', 'visible', 'relation'); + } + + /** + * Required element attribute array + * + * @return array + */ + public function getRequiredXmlAttributes() + { + return array('label' => null, 'type' => null); + } + + /** + * Retrieve element xml object + * + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function getElementXml() + { + $xmlObj = $this->getXmlObject(); + $this->_addRequiredAttributes($xmlObj); + foreach ($this->getAttributes() as $key => $val) { + $xmlObj->addAttribute($key, $xmlObj->xmlAttribute($val)); + } + $this->_addValue($xmlObj); + + foreach ($this->getElements() as $element) { + if ($element->getType() == 'validator') { + $xmlObj->appendChild($element->toXmlObject()); + } + } + + $this->addAfterXmlElementToObj($xmlObj); + + return $xmlObj; + } + + /** + * Get escaped value + * + * @param string $index + * @return string|null + */ + public function getEscapedValue($index = null) + { + $value = $this->getValue($index); + + if ($filter = $this->getValueFilter()) { + $value = $filter->filter($value); + } + + return $value; + } + + /** + * Set element renderer + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + public function setRenderer(Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface $renderer) + { + $this->_renderer = $renderer; + return $this; + } + + /** + * Get element renderer + * + * @return object + */ + public function getRenderer() + { + return $this->_renderer; + } + + /** + * Add value to element + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + protected function _addValue(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + if ($this->getEscapedValue()) { + $xmlObj->addAttribute('value', $xmlObj->xmlAttribute($this->getEscapedValue())); + } + return $this; + } + + /** + * Retrieve default form xml object + * + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function getDefaultXml() + { + $xml = $this->getData('default_xml'); + if (null === $xml) { + $xml = $this->getElementXml(); + } + return $xml; + } + + /** + * Get element xml as string + * + * @return string + */ + public function getXml() + { + return $this->toXmlObject->asNiceXml(); + } + + /** + * Retrieve form xml object + * + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function toXmlObject() + { + if ($this->_renderer) { + return $this->_renderer->render($this); + } else { + return $this->getDefaultXml(); + } + } + + /** + * Get xml container id + * + * @return string + */ + public function getXmlContainerId() + { + if ($this->hasData('container_id')) { + return $this->getData('container_id'); + } elseif ($idPrefix = $this->getForm()->getFieldContainerIdPrefix()) { + return $idPrefix . $this->getId(); + } + return ''; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Checkbox.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Checkbox.php new file mode 100644 index 0000000000..62bf94a76b --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Checkbox.php @@ -0,0 +1,59 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Checkbox + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Init checkbox element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('checkbox'); + } + + /** + * Add value to element + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + protected function _addValue(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $xmlObj->addAttribute('value', (int)$this->getValue()); + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Collection.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Collection.php new file mode 100644 index 0000000000..0694dd4d9a --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Collection.php @@ -0,0 +1,202 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Collection implements ArrayAccess, IteratorAggregate +{ + /** + * Elements storage + * + * @var array + */ + private $_elements; + + /** + * Elements container + * + * @var Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + private $_container; + + /** + * Class constructor + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Abstract $container + */ + public function __construct($container) + { + $this->_elements = array(); + $this->_container = $container; + } + + /** + * Implementation of IteratorAggregate::getIterator() + * + * @return ArrayIterator + */ + public function getIterator() + { + return new ArrayIterator($this->_elements); + } + + /** + * Implementation of ArrayAccess:offsetSet() + * + * @param mixed $key + * @param mixed $value + */ + public function offsetSet($key, $value) + { + $this->_elements[$key] = $value; + } + + /** + * Implementation of ArrayAccess:offsetGet() + * + * @param mixed $key + */ + public function offsetGet($key) + { + return $this->_elements[$key]; + } + + /** + * Implementation of ArrayAccess:offsetUnset() + * + * @param mixed $key + */ + public function offsetUnset($key) + { + unset($this->_elements[$key]); + } + + /** + * Implementation of ArrayAccess:offsetExists() + * + * @param mixed $key + * @return bool + */ + public function offsetExists($key) + { + return isset($this->_elements[$key]); + } + + /** + * Add element to collection + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Abstract $element + * @param bool|string $after + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function add(Mage_XmlConnect_Model_Simplexml_Form_Abstract $element, $after = false) + { + // Set the Form for the node + if ($this->_container->getForm() instanceof Mage_XmlConnect_Model_Simplexml_Form) { + $element->setContainer($this->_container); + $element->setForm($this->_container->getForm()); + } + + if ($after === false) { + $this->_elements[] = $element; + } elseif ($after === '^') { + array_unshift($this->_elements, $element); + } elseif (is_string($after)) { + $newOrderElements = array(); + foreach ($this->_elements as $index => $currElement) { + if ($currElement->getId() == $after) { + $newOrderElements[] = $currElement; + $newOrderElements[] = $element; + $this->_elements = array_merge($newOrderElements, array_slice($this->_elements, ++$index)); + return $element; + } + $newOrderElements[] = $currElement; + } + $this->_elements[] = $element; + } + + return $element; + } + + /** + * Sort elements by values using a user-defined comparison function + * + * @param mixed $callback + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Collection + */ + public function usort($callback) + { + usort($this->_elements, $callback); + return $this; + } + + /** + * Remove element from collection + * + * @param mixed $elementId + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Collection + */ + public function remove($elementId) + { + foreach ($this->_elements as $index => $element) { + if ($elementId == $element->getId()) { + unset($this->_elements[$index]); + } + } + return $this; + } + + /** + * Count elements in collection + * + * @return int + */ + public function count() + { + return count($this->_elements); + } + + /** + * Find element by ID + * + * @param mixed $elementId + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract|null + */ + public function searchById($elementId) + { + foreach ($this->_elements as $element) { + if ($element->getId() == $elementId) { + return $element; + } + } + return null; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/CountryListSelect.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/CountryListSelect.php new file mode 100644 index 0000000000..9872e45779 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/CountryListSelect.php @@ -0,0 +1,240 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_CountryListSelect + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Select +{ + /** + * Country list values array + * + * @var array + */ + protected $_countryListValues = array('country_id', 'region_id', 'region'); + + /** + * Init country list select element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + } + + /** + * Set country list values 'country_id' and 'region_id' + * + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_CountryListSelect + */ + protected function _setValues() + { + $value = $this->getValue(); + + foreach ($this->_countryListValues as $param) { + if (isset($value[$param])) { + $this->setData($param, $value[$param]); + } + } + + return $this; + } + + /** + * Get values using old standard + * + * @deprecated old output standard + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_CountryListSelect + */ + protected function _addOldStandardValue(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $countries = $this->_getCountryOptions(); + + if (is_array($countries)) { + $valuesXmlObj = $xmlObj->addCustomChild('values'); + foreach ($countries as $data) { + $regions = array(); + + if ($data['value']) { + $regions = $this->_getRegionOptions($data['value']); + } + + $relationType = is_array($regions) && !empty($regions) ? 'region_id' : 'region'; + + $selectedCountry = array(); + if ($this->getCountryId() == $data['value']) { + $selectedCountry = array('selected' => 1); + } + + $item = $valuesXmlObj->addCustomChild('item', null, + array('relation' => $relationType) + $selectedCountry + ); + + $item->addCustomChild('label', (string)$data['label']); + $item->addCustomChild('value', $data['value']); + + if ($relationType == 'region_id') { + $regionsXmlObj = $item->addCustomChild('regions'); + foreach ($regions as $regionData) { + $selectedRegion = array(); + + if (!empty($selectedCountry) && $this->getRegionId() == $regionData['value']) { + $selectedRegion = array('selected' => 1); + } + + $regionItem = $regionsXmlObj->addCustomChild('region_item', null, $selectedRegion); + $regionItem->addCustomChild('label', (string)$regionData['label']); + $regionItem->addCustomChild('value', (string)$regionData['value']); + } + } + } + } + + return $this; + } + + /** + * Add value to element + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + protected function _addValue(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $this->_setValues(); + + if ($this->getOldFormat()) { + $this->_addOldStandardValue($xmlObj); + return $this; + } + + if ($this->getCountryId()) { + $xmlObj->addAttribute('value', $xmlObj->xmlAttribute($this->getCountryId())); + } + $countries = $this->_getCountryOptions(); + + if (is_array($countries)) { + $values = $xmlObj->addCustomChild('values'); + foreach ($countries as $data) { + $regions = array(); + + if ($data['value']) { + $regions = $this->_getRegionOptions($data['value']); + } + + if (is_array($regions) && !empty($regions)) { + $relationType = 'region_id'; + } else { + $relationType = 'region'; + } + + $item = $values->addCustomChild('item', null, array( + 'relation' => $relationType, 'label' => (string)$data['label'], 'value' => $data['value'] + )); + + if ($relationType !== 'region') { + + $selectedRegion = array(); + if ($this->getCountryId() == $data['value']) { + $selectedRegion = array('value' => $this->getRegionId()); + } + + $regionsXmlObj = $item->addCustomChild('field', null, array( + 'id' => 'region_list_' . $data['value'], 'name' => 'region_id', + 'label' => Mage::helper('xmlconnect')->__('State/Province'), 'type' => 'select', + 'required' => 1 + ) + $selectedRegion); + + $regionValues = $regionsXmlObj->addCustomChild('values'); + + foreach ($regions as $regionData) { + $regionValues->addCustomChild('item', null, array( + 'label' => (string)$regionData['label'], 'value' => (string)$regionData['value'] + )); + } + } elseif ($this->getCountryId() == $data['value']) { + $item->addCustomChild('field', null, array( + 'id' => 'region_' . $data['value'], 'name' => 'region', + 'label' => Mage::helper('xmlconnect')->__('State/Province'), 'type' => 'text', + 'value' => $this->getRegion(), 'required' => 1 + )); + } + } + } + return $this; + } + + /** + * Retrieve regions by country + * + * @param string $countryId + * @return array + */ + protected function _getRegionOptions($countryId) + { + $cacheKey = 'DIRECTORY_REGION_SELECT_STORE' . Mage::app()->getStore()->getId() . $countryId; + $cache = Mage::app()->loadCache($cacheKey); + if (Mage::app()->useCache('config') && $cache) { + $options = unserialize($cache); + } else { + $collection = Mage::getModel('directory/region')->getResourceCollection()->addCountryFilter($countryId) + ->load(); + $options = $collection->toOptionArray(); + if (Mage::app()->useCache('config')) { + Mage::app()->saveCache(serialize($options), $cacheKey, array('config')); + } + } + return $options; + } + + /** + * Retrieve countries + * + * @return array + */ + protected function _getCountryOptions() + { + $cacheKey = 'DIRECTORY_COUNTRY_SELECT_STORE_' . Mage::app()->getStore()->getCode(); + $cache = Mage::app()->loadCache($cacheKey); + if (Mage::app()->useCache('config') && $cache) { + $options = unserialize($cache); + } else { + $collection = Mage::getModel('directory/country')->getResourceCollection()->loadByStore(); + $options = $collection->toOptionArray(false); + if (Mage::app()->useCache('config')) { + Mage::app()->saveCache(serialize($options), $cacheKey, array('config')); + } + } + return $options; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Date.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Date.php new file mode 100644 index 0000000000..921364960f --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Date.php @@ -0,0 +1,85 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Date + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Init multiline element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('date'); + } + + /** + * Required element attribute array + * + * @return array + */ + public function getRequiredXmlAttributes() + { + return array( + 'label' => null, + 'type' => null, + 'format' => null + ); + } + + /** + * Add value to element + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + protected function _addValue(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $values = $this->getEscapedValue(); + if (!empty($values)) { + $valuesXmlObj = $xmlObj->addCustomChild('values'); + foreach ($values as $element => $config) { + $valuesXmlObj->addCustomChild('item', null, array( + 'id' => $config['id'], + 'title' => $config['title'], + 'label' => $config['label'], + 'type' => $element, + 'value' => $config['value'] + )); + } + } + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Email.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Email.php new file mode 100644 index 0000000000..382b75fdcc --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Email.php @@ -0,0 +1,47 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Email + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Init email element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('email'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Fieldset.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Fieldset.php new file mode 100644 index 0000000000..aa6fa3c0e0 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Fieldset.php @@ -0,0 +1,219 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Sort child elements by specified data key + * + * @var string + */ + protected $_sortChildrenByKey = ''; + + /** + * Children sort direction + * + * @var int + */ + protected $_sortChildrenDirection = SORT_ASC; + + /** + * Main element node + * + * @var string + */ + protected $_mainNode = 'fieldset'; + + /** + * Is name attribute required + * + * @var bool + */ + protected $_nameRequired = false; + + /** + * Init fieldset object + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->_renderer = Mage_XmlConnect_Model_Simplexml_Form::getFieldsetRenderer(); + $this->setType('fieldset'); + } + + /** + * Get fieldset element object + * + * @return Mage_XmlConnect_Model_Simplexml_Element + */ + public function getElementXml() + { + $xmlObj = $this->getXmlObject(); + $this->_addRequiredAttributes($xmlObj); + foreach ($this->getAttributes() as $key => $val) { + $xmlObj->addAttribute($key, $xmlObj->xmlAttribute($val)); + } + foreach ($this->getChildrenXml(false) as $element) { + $xmlObj->appendChild($element); + } + foreach ($this->getChildrenXml(true) as $fieldset) { + $xmlObj->appendChild($fieldset); + } + $this->addAfterXmlElementToObj($xmlObj); + return $xmlObj; + } + + /** + * Default element attribute array + * + * @return array + */ + public function getXmlAttributes() + { + return array('title', 'disabled'); + } + + /** + * Required element attribute array + * + * @return array + */ + public function getRequiredXmlAttributes() + { + return array(); + } + + /** + * Get children array of elements + * + * @param bool $isFieldset + * @return array + */ + public function getChildrenXml($isFieldset = false) + { + $result = array(); + foreach ($this->getSortedElements() as $element) { + if ($this->_checkFieldset($element, $isFieldset)) { + $result[] = $element->toXmlObject(); + } + } + return $result; + } + + /** + * Check weather is element a fieldset + * + * @param Mage_XmlConnect_Model_Simplexml_Form_Abstract $element + * @param bool $equal + * @return bool + */ + protected function _checkFieldset($element, $equal = true) { + if ($equal) { + return $element->getType() == 'fieldset'; + } else { + return $element->getType() != 'fieldset'; + } + } + + /** + * Add field element to fieldset + * + * @param string $elementId + * @param string $type + * @param array $config + * @param boolean $after + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + public function addField($elementId, $type, $config, $after = false) + { + $element = parent::addField($elementId, $type, $config, $after); + if ($renderer = Mage_XmlConnect_Model_Simplexml_Form::getFieldsetElementRenderer()) { + $element->setRenderer($renderer); + } + return $element; + } + + /** + * Commence sorting elements by values by specified data key + * + * @param string $key + * @param int $direction + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset + */ + public function setSortElementsByAttribute($key, $direction = SORT_ASC) + { + $this->_sortChildrenByKey = $key; + $this->_sortDirection = $direction; + return $this; + } + + /** + * Get sorted elements as array + * + * @return array + */ + public function getSortedElements() + { + $elements = array(); + // sort children by value by specified key + if ($this->_sortChildrenByKey) { + $sortKey = $this->_sortChildrenByKey; + $uniqueIncrement = 0; // in case if there are elements with same values + /** @var Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $element */ + foreach ($this->getElements() as $element) { + $key = '_' . $uniqueIncrement; + if ($element->hasData($sortKey)) { + $key = $element->getDataUsingMethod($sortKey) . $key; + } + $elements[$key] = $element; + $uniqueIncrement++; + } + + if ($this->_sortDirection == SORT_ASC) { + ksort($elements, $this->_sortChildrenDirection); + } else { + krsort($elements, $this->_sortChildrenDirection); + } + + $elements = array_values($elements); + } else { + foreach ($this->getElements() as $element) { + $elements[] = $element; + } + } + return $elements; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/File.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/File.php new file mode 100644 index 0000000000..286b8ef8f4 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/File.php @@ -0,0 +1,47 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_File + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Init text element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('file'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Image.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Image.php new file mode 100644 index 0000000000..ca7570af62 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Image.php @@ -0,0 +1,47 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Image + extends Mage_XmlConnect_Model_Simplexml_Form_Element_File +{ + /** + * Init text element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('image'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Multiline.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Multiline.php new file mode 100644 index 0000000000..efb68d98bb --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Multiline.php @@ -0,0 +1,132 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Multiline + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Format for Xml elements id attribute + * + * @var string + */ + protected $_fieldIdFormat = '%1$s'; + + /** + * Format for Xml elements name attribute + * + * @var string + */ + protected $_fieldNameFormat = '%1$s'; + + /** + * Init multiline element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + if (!isset($attributes['line_count'])) { + Mage::throwException( + Mage::helper('xmlconnect')->__('"line_count" attribute is required for "multiline" element.') + ); + } + parent::__construct($attributes); + $this->setType('multiline'); + } + + /** + * Required element attribute array + * + * @return array + */ + public function getRequiredXmlAttributes() + { + return array( + 'label' => null, + 'type' => null + ); + } + + /** + * Return Xml id for element + * + * @param null|string $index + * @return string + */ + public function getXmlId($index = null) + { + $format = $this->_fieldIdFormat; + if (!is_null($index)) { + $format .= '_%2$s'; + } + return sprintf($format, $this->getData('attribute_code'), $index); + } + + /** + * Return Xml id for element + * + * @param null|string $index + * @return string + */ + public function getFieldName($index = null) + { + $format = $this->_fieldNameFormat; + if (!is_null($index)) { + $format .= '[%2$s]'; + } + return sprintf($format, $this->getData('attribute_code'), $index); + } + + /** + * Add value to element + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + protected function _addValue(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $values = $this->getEscapedValue(); + if (!empty($values)) { + $valuesXmlObj = $xmlObj->addCustomChild('values'); + for ($i = 0; $i < $this->getData('line_count'); $i++) { + $value = !empty($values[$i]) ? array('value' => $values[$i]) : array(); + + $valuesXmlObj->addCustomChild('item', null, array( + 'id' => $this->getXmlId($i), + 'name' => $this->getFieldName($i) + ) + $value); + } + } + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Multiselect.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Multiselect.php new file mode 100644 index 0000000000..7349989dca --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Multiselect.php @@ -0,0 +1,81 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Multiselect + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Select +{ + /** + * Init text element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('multiselect'); + } + + /** + * Add value to element + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Multiselect + */ + protected function _addValue(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $values = array(); + if (is_array($this->getEscapedValue())) { + $values = $this->getEscapedValue(); + } + + $valuesXmlObj = $xmlObj->addCustomChild('values'); + foreach ($this->getOptions() as $option) { + + if (empty($option['value'])) { + continue; + } + + $selected = array(); + if (in_array($option['value'], $values)) { + $selected = array('selected' => 1); + } + + $valuesXmlObj->addCustomChild('item', null, array( + 'label' => $option['label'], + 'value' => $option['value'] + ) + $selected); + } + + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Renderer/Interface.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Renderer/Interface.php new file mode 100644 index 0000000000..c71fd3795a --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Renderer/Interface.php @@ -0,0 +1,37 @@ + + */ +interface Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface +{ + public function render(Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract $element); +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Select.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Select.php new file mode 100644 index 0000000000..7eda8e14d2 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Select.php @@ -0,0 +1,91 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Select + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Init text element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('select'); + } + + /** + * Add value and options to select + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Select + */ + protected function _addValue(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $value = $this->getEscapedValue(); + if ($value !== null) { + $xmlObj->addAttribute( + 'value', + $xmlObj->xmlAttribute($value) + ); + } + $this->_addOptions($xmlObj); + + return $this; + } + + /** + * Add options to select + * + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Select + */ + protected function _addOptions(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + if ($this->getOptions() && is_array($this->getOptions())) { + $valuesXmlObj = $xmlObj->addCustomChild('values'); + foreach ($this->getOptions() as $option) { + + if (!isset($option['value']) || $option['value'] == '') { + continue; + } + + $valuesXmlObj->addCustomChild('item', null, array( + 'label' => $option['label'], + 'value' => $option['value'] + )); + } + } + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Text.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Text.php new file mode 100644 index 0000000000..c664e9c4e0 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Text.php @@ -0,0 +1,47 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Text + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Init text element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('text'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Textarea.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Textarea.php new file mode 100644 index 0000000000..92e1b3c9da --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Textarea.php @@ -0,0 +1,47 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Textarea + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Init textarea element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->setType('textarea'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator.php new file mode 100644 index 0000000000..5449685a94 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator.php @@ -0,0 +1,193 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Validator + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset +{ + /** + * Main element node + * + * @var string + */ + protected $_mainNode = 'validators'; + + /** + * Validator id prefix + * + * @var string + */ + protected $_validatorIdPrefix = 'validator_'; + + /** + * Rule type block renderer + * + * @var string + */ + protected $_ruleTypeBlock = 'validator_rule'; + + /** + * Init validator container + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->_renderer = Mage_XmlConnect_Model_Simplexml_Form::getValidatorRenderer(); + $this->setType('validator'); + } + + /** + * Skip name attribute for validator + * + * @todo re-factor required attributes logic to make it easy to replace them + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected function _addName(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + return $this; + } + + /** + * Default element attribute array + * + * @return array + */ + public function getXmlAttributes() + { + return array(); + } + + /** + * Required element attribute array + * + * @return array + */ + public function getRequiredXmlAttributes() + { + return array(); + } + + /** + * Set element id + * + * @param $id + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + public function setId($id) + { + parent::setId($this->getValidatorIdPrefix() . $id); + return $this; + } + + /** + * Get validator prefix + * + * @return string + */ + public function getValidatorIdPrefix() + { + return $this->_validatorIdPrefix; + } + + /** + * Set validator prefix + * + * @param string $validatorIdPrefix + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Validator + */ + public function setValidatorIdPrefix($validatorIdPrefix) + { + $this->_validatorIdPrefix = $validatorIdPrefix; + return $this; + } + + /** + * Get object attributes array + * + * @return array + */ + public function getAttributes() + { + $attributes = array_merge($this->getXmlAttributes(), $this->getCustomAttributes()); + if (!empty($attributes)) { + return $this->getXmlObjAttributes($attributes); + } else { + return $attributes; + } + } + + /** + * Add rule element to validator container + * + * @param array $config + * @param boolean $after + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract + */ + public function addRule(array $config, $after = false) + { + if (isset($config['type'])) { + $ruleType = $config['type']; + } + + $elementId = $this->getXmlId() . '_' . $ruleType; + $element = parent::addField($elementId, $this->getRuleTypeBlock(), $config, $after); + if ($renderer = Mage_XmlConnect_Model_Simplexml_Form::getValidatorRuleRenderer()) { + $element->setRenderer($renderer); + } + return $element; + } + + /** + * Get rule type block renderer + * + * @return string + */ + public function getRuleTypeBlock() + { + return $this->_ruleTypeBlock; + } + + /** + * Set rule type block renderer + * + * @param string $ruleTypeBlock + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Validator + */ + public function setRuleTypeBlock($ruleTypeBlock) + { + $this->_ruleTypeBlock = $ruleTypeBlock; + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator/Abstract.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator/Abstract.php new file mode 100644 index 0000000000..91eb1c1e4d --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator/Abstract.php @@ -0,0 +1,184 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Abstract + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract +{ + /** + * Array of the messages for default validator types + * + * @var array + */ + protected $_validatorTypeMessages = array(); + + /** + * Main element node + * + * @var string + */ + protected $_mainNode = 'validator'; + + /** + * Init validator rule element abstract + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + $this->_renderer = Mage_XmlConnect_Model_Simplexml_Form::getValidatorRuleRenderer(); + $this->_setDefaultValidatorTypeMessages(); + if (isset($attributes['type'])) { + $this->setType($attributes['type']); + } + } + + /** + * Set default validator messages + * + * @see Mage_Core_Helper_Js->_getTranslateData() and validation.js + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Abstract + */ + protected function _setDefaultValidatorTypeMessages() + { + $helper = Mage::helper('xmlconnect'); + $this->_validatorTypeMessages = array( + 'min_length' => $helper->__('Text length does not satisfy specified min text range.'), + 'max_length' => $helper->__('Text length does not satisfy specified max text range.'), + 'alphanumeric' => $helper->__('Please use only letters (a-z or A-Z) or numbers (0-9) only in this field. No spaces or other characters are allowed.'), + 'email' => $helper->__('Please enter a valid email address. For example johndoe@domain.com.'), + 'required' => $helper->__('This is a required field.'), + 'required_select' => $helper->__('Please select an option.'), + 'numeric' => $helper->__('Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.'), + 'alpha' => $helper->__('Please use letters only (a-z or A-Z) in this field.'), + 'url' => $helper->__('Please enter a valid URL. Protocol is required (http://, https:// or ftp://)'), + 'date' => $helper->__('Please enter a valid date.'), + 'max_file_size' => $helper->__('\'%s\' exceeds the allowed file size: %d (bytes)', $this->getFieldLabel(), $this->getValue()), + 'file_extensions' => $helper->__('\'%s\' is not a valid file extension. Allowed extensions: %s', $this->getFieldLabel(), $this->getValue()), + 'max_image_width' => $helper->__('\'%s\' width exceeds allowed value of %d px', $this->getFieldLabel(), $this->getValue()), + 'max_image_height' => $helper->__('\'%s\' height exceeds allowed value of %d px', $this->getFieldLabel(), $this->getValue()) + ); + return $this; + } + + /** + * Add required attributes to validator rule + * + * @todo re-factor required attributes logic to make it easy to replace them + * @throws Mage_Core_Exception + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected function _addRequiredAttributes(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + $this->_addId($xmlObj); + + foreach ($this->getRequiredXmlAttributes() as $attribute => $defValue) { + $data = $this->getData($this->_underscore($attribute)); + + if ($data) { + $xmlObj->addAttribute($attribute, $xmlObj->xmlAttribute($data)); + } elseif(null !== $defValue){ + $xmlObj->addAttribute($attribute, $xmlObj->xmlAttribute($defValue)); + } else { + Mage::throwException(Mage::helper('xmlconnect')->__('%s attribute is required.', $attribute)); + } + } + $this->_addMessage($xmlObj); + return $this; + } + + /** + * Add validator message for validator rule + * + * @throws Mage_Core_Exception + * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj + * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract + */ + protected function _addMessage(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) + { + if ($this->getMessage()) { + $message = $this->getMessage(); + } elseif (array_key_exists($this->getType(), $this->getValidatorTypeMessages())) { + $message = $this->_validatorTypeMessages[$this->getType()]; + } else { + Mage::throwException( + Mage::helper('xmlconnect')->__('"message" attribute is required for "%s" validator rule.', $this->getType()) + ); + } + $xmlObj->addAttribute('message', $xmlObj->xmlAttribute($message)); + return $this; + } + + /** + * Default validator rule attribute array + * + * @return array + */ + public function getXmlAttributes() + { + return array('relation'); + } + + /** + * Required validator rule attribute array + * + * @return array + */ + public function getRequiredXmlAttributes() + { + return array('type' => null); + } + + /** + * Get validator type messages + * + * @return array + */ + public function getValidatorTypeMessages() + { + return $this->_validatorTypeMessages; + } + + /** + * Set validator type messages + * + * @param array $validatorTypeMessages + * @return Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Abstract + */ + public function addValidatorTypeMessages(array $validatorTypeMessages) + { + $this->_validatorTypeMessages = array_merge($this->_validatorTypeMessages, $validatorTypeMessages); + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator/Rule.php b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator/Rule.php new file mode 100644 index 0000000000..bd47829a6f --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Form/Element/Validator/Rule.php @@ -0,0 +1,46 @@ + + */ +class Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Rule + extends Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Abstract +{ + /** + * Init validator rule element + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + parent::__construct($attributes); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Tabs.php b/app/code/core/Mage/XmlConnect/Model/Tabs.php index 2f18d3b18f..58da61abe6 100644 --- a/app/code/core/Mage/XmlConnect/Model/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Model/Tabs.php @@ -25,10 +25,10 @@ */ /** - * XmlConnect Model Tabs + * XmlConnect Tabs model * * @category Mage - * @package Mage_XmlConnect + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Model_Tabs @@ -69,8 +69,8 @@ public function __construct($data) /** * Translate Label fields * - * @param &array $tabItems - * @return this + * @param array &$tabItems + * @return Mage_XmlConnect_Model_Tabs */ protected function _translateLabel(&$tabItems) { diff --git a/app/code/core/Mage/XmlConnect/Model/Template.php b/app/code/core/Mage/XmlConnect/Model/Template.php index 3f7a0690c4..95998f3a52 100755 --- a/app/code/core/Mage/XmlConnect/Model/Template.php +++ b/app/code/core/Mage/XmlConnect/Model/Template.php @@ -25,10 +25,10 @@ */ /** - * XmlConnect Model Template + * XmlConnect Template model * * @category Mage - * @package Mage_XmlConnect + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Model_Template extends Mage_Core_Model_Template @@ -36,7 +36,7 @@ class Mage_XmlConnect_Model_Template extends Mage_Core_Model_Template /** * Model constructor * - * @return void + * @return null */ protected function _construct() { @@ -94,8 +94,6 @@ public function getProcessedTemplate(array $variables = array()) $htmlDescription = <<%s: EOT; - /** @var $coreHelper Mage_Core_Helper_Data */ - $coreHelper = Mage::helper('core'); $html = sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Push title')) . $this->getPushTitle(); $html .= sprintf($htmlDescription, Mage::helper('xmlconnect')->__('Message title')) diff --git a/app/code/core/Mage/XmlConnect/Model/Theme.php b/app/code/core/Mage/XmlConnect/Model/Theme.php index 674356bf51..00acf46e23 100644 --- a/app/code/core/Mage/XmlConnect/Model/Theme.php +++ b/app/code/core/Mage/XmlConnect/Model/Theme.php @@ -25,10 +25,10 @@ */ /** - * XmlConnect Model Theme + * XmlConnect Theme model * * @category Mage - * @package Mage_XmlConnect + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_Model_Theme @@ -172,14 +172,8 @@ protected function _createThemeName() /** @var $coreHelper Mage_Core_Helper_Data */ $coreHelper = Mage::helper('core'); - $themeFileName = $themesHelper->getMediaThemePath() - . DS - .$themesHelper->getCustomThemeName() - . '_' - . time() - . '_' - . $coreHelper->getRandomString(10, 'abcdefghijklmnopqrstuvwxyz0123456789') - . '.xml'; + $themeFileName = $themesHelper->getMediaThemePath() . DS .$themesHelper->getCustomThemeName() . '_' . time() + . '_' . $coreHelper->getRandomString(10, 'abcdefghijklmnopqrstuvwxyz0123456789') . '.xml'; return $themeFileName; } @@ -193,13 +187,13 @@ protected function _createCopy($filePath) { $currentThemeFileName = $this->_getThemeFile(); - $io = new Varien_Io_File(); - if (!$io->cp($currentThemeFileName, $filePath)) { + $ioFile = new Varien_Io_File(); + if (!$ioFile->cp($currentThemeFileName, $filePath)) { Mage::throwException( Mage::helper('xmlconnect')->__('Can\'t copy file "%s" to "%s".', $currentThemeFileName, $filePath) ); } else { - $io->chmod($filePath, 0755); + $ioFile->chmod($filePath, 0755); } return $filePath; @@ -221,7 +215,7 @@ public function createNewTheme($themeName, $data) $themeFileName = Mage::getModel('xmlconnect/theme', $filePath); $themeFileName->setLabel($themeName); $fileName = basename($filePath); - $themeFileName->setName(substr($fileName, 0, strlen($fileName)-4)); + $themeFileName->setName(substr($fileName, 0, -4)); $themeFileName->importAndSaveData($data); return $themeFileName; } @@ -243,7 +237,7 @@ public function getFormData() * @param string $prefix * @return array */ - protected function _flatArray($subtree, $prefix=null) + protected function _flatArray($subtree, $prefix = null) { $result = array(); foreach ($subtree as $key => $value) { @@ -269,7 +263,7 @@ protected function _flatArray($subtree, $prefix=null) * @param array $xml * @return array */ - protected function _validateFormInput($data, $xml=NULL) + protected function _validateFormInput($data, $xml = null) { $root = false; $result = array(); @@ -298,7 +292,7 @@ protected function _validateFormInput($data, $xml=NULL) * * @param SimpleXMLElement $parent * @param array $data - * @return void + * @return null */ protected function _buildRecursive($parent, $data) { @@ -315,7 +309,7 @@ protected function _buildRecursive($parent, $data) * Import data into theme form $data array, and save XML to file * * @param array $data - * @return void + * @return null */ public function importAndSaveData($data) { @@ -325,9 +319,7 @@ public function importAndSaveData($data) if (is_writeable($this->_file)) { file_put_contents($this->_file, $xml->asXML()); } else { - Mage::throwException( - Mage::helper('xmlconnect')->__('Can\'t write to file "%s".', $this->_file) - ); + Mage::throwException(Mage::helper('xmlconnect')->__('Can\'t write to file "%s".', $this->_file)); } } } diff --git a/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php b/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php index 9287cf7ebe..8b81bca344 100644 --- a/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php +++ b/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php @@ -83,7 +83,7 @@ protected function _restoreSessionFilesFormData($data) /** * Mobile applications management * - * @return void + * @return null */ public function indexAction() { @@ -95,7 +95,7 @@ public function indexAction() /** * Create new app * - * @return void + * @return null */ public function newAction() { @@ -108,7 +108,7 @@ public function newAction() /** * Submission Action, loads application data * - * @return void + * @return null */ public function submissionAction() { @@ -152,7 +152,7 @@ public function submissionAction() /** * Edit app form * - * @return void + * @return null */ public function editAction() { @@ -209,7 +209,7 @@ public function editAction() /** * Submit POST application action * - * @return void + * @return null */ public function submissionPostAction() { @@ -238,20 +238,16 @@ public function submissionPostAction() $this->_processPostRequest(); $history = Mage::getModel('xmlconnect/history'); $history->setData(array( - 'params' => $params, - 'application_id' => $app->getId(), - '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'], + 'params' => $params, 'application_id' => $app->getId(), + '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'], )); $history->save(); - $app->getResource()->updateApplicationStatus($app->getId(), - Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS); + $app->getResource()->updateApplicationStatus( + $app->getId(), Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS + ); $this->_getSession()->addSuccess($this->__('App has been submitted.')); $this->_clearSessionData(); $this->_redirect('*/*/edit', array('application_id' => $app->getId())); @@ -316,7 +312,7 @@ protected function _clearSessionData() /** * Send HTTP POST request to magentocommerce.com * - * @return void + * @return null */ protected function _processPostRequest() { @@ -325,28 +321,27 @@ protected function _processPostRequest() $params = $app->getSubmitParams(); $appConnectorUrl = Mage::getStoreConfig('xmlconnect/mobile_application/magentocommerce_url'); - $ch = curl_init($appConnectorUrl . $params['key']); + $curlHandler = curl_init($appConnectorUrl . $params['key']); // set URL and other appropriate options - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $params); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_TIMEOUT, 60); + curl_setopt($curlHandler, CURLOPT_POST, 1); + curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $params); + curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, 2); + curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($curlHandler, CURLOPT_TIMEOUT, 60); // Execute the request. - $result = curl_exec($ch); - $succeeded = curl_errno($ch) == 0 ? true : false; + $result = curl_exec($curlHandler); // close cURL resource, and free up system resources - curl_close($ch); + curl_close($curlHandler); // Assert that we received an expected message in reponse. $resultArray = json_decode($result, true); $app->setResult($result); - $success = (isset($resultArray['success'])) && ($resultArray['success'] === true); + $success = isset($resultArray['success']) && $resultArray['success'] === true; $app->setSuccess($success); if (!$app->getSuccess()) { @@ -364,7 +359,7 @@ protected function _processPostRequest() /** * Save action * - * @return void + * @return null */ public function saveAction() { @@ -470,8 +465,6 @@ protected function _saveThemeAction($data, $paramId = 'saveTheme') 'selectedTheme' => $themeName ); } - } elseif ($newThemeName) { - $response = array('error' => true, 'message' => $this->__('Cannot load theme "%s".', $themeName)); } else { $response = array('error' => true, 'message' => $this->__('Cannot load theme "%s".', $themeName)); } @@ -479,22 +472,16 @@ protected function _saveThemeAction($data, $paramId = 'saveTheme') $convertedConf = $this->_convertPost($data); $newTheme = $themesHelper->createNewTheme($themeName, $convertedConf); $response = array( - 'message' => $this->__('Theme has been created.'), - 'themes' => $themesHelper->getAllThemesArray(true), + 'message' => $this->__('Theme has been created.'), + 'themes' => $themesHelper->getAllThemesArray(true), 'themeSelector' => $themesHelper->getThemesSelector($newTheme->getName()), 'selectedTheme' => $newTheme->getName() ); } } catch (Mage_Core_Exception $e) { - $response = array( - 'error' => true, - 'message' => $e->getMessage(), - ); + $response = array('error' => true, 'message' => $e->getMessage()); } catch (Exception $e) { - $response = array( - 'error' => true, - 'message' => $this->__('Can\'t save theme.') - ); + $response = array('error' => true, 'message' => $this->__('Can\'t save theme.')); } } else { $response = array('error' => true, 'message' => $this->__('Theme name is not set.')); @@ -519,15 +506,15 @@ protected function _convertPost($data) foreach ($data as $key => $val) { $parts = explode('_', $key); // "4" - is number of expected params conf_native_bar_tintcolor in correct data - if (is_array($parts) && (count($parts) == 4)) { - @list($key0, $key1, $key2, $key3) = $parts; + if (is_array($parts) && count($parts) == 4) { + list(, $key1, $key2, $key3) = $parts; if (!isset($conf[$key1])) { $conf[$key1] = array(); } if (!isset($conf[$key1][$key2])) { $conf[$key1][$key2] = array(); } - $conf[$key1][$key2][$key3] = $val; + $conf[$key1][$key2][$key3] = $val; } } return $conf; @@ -536,7 +523,7 @@ protected function _convertPost($data) /** * Delete theme action * - * @return void + * @return null */ public function deleteThemeAction() { @@ -560,10 +547,7 @@ public function deleteThemeAction() ); } } catch (Mage_Core_Exception $e) { - $response = array( - 'error' => true, - 'message' => $e->getMessage(), - ); + $response = array('error' => true, 'message' => $e->getMessage()); } catch (Exception $e) { $response = array( 'error' => true, @@ -582,7 +566,7 @@ public function deleteThemeAction() /** * Save Theme action * - * @return void + * @return null */ public function saveThemeAction() { @@ -593,7 +577,7 @@ public function saveThemeAction() /** * Save Theme action * - * @return void + * @return null */ public function resetThemeAction() { @@ -602,15 +586,9 @@ public function resetThemeAction() Mage::helper('xmlconnect/theme')->resetTheme($theme); $response = Mage::helper('xmlconnect/theme')->getAllThemesArray(true); } catch (Mage_Core_Exception $e) { - $response = array( - 'error' => true, - 'message' => $e->getMessage(), - ); + $response = array('error' => true, 'message' => $e->getMessage()); } catch (Exception $e) { - $response = array( - 'error' => true, - 'message' => $this->__('Can\'t reset theme.') - ); + $response = array('error' => true, 'message' => $this->__('Can\'t reset theme.')); } if (is_array($response)) { $response = Mage::helper('core')->jsonEncode($response); @@ -621,7 +599,7 @@ public function resetThemeAction() /** * Preview Home action handler * - * @return void + * @return null */ public function previewHomeAction() { @@ -639,7 +617,7 @@ public function previewHomeHorAction() /** * Preview Catalog action handler * - * @return void + * @return null */ public function previewCatalogAction() { @@ -737,7 +715,7 @@ protected function _previewAction($block) /** * Delete app action * - * @return void + * @return null */ public function deleteAction() { @@ -769,9 +747,7 @@ public function deleteTemplateAction() Mage::getModel('xmlconnect/template')->load($id)->delete(); // display success message - Mage::getSingleton('adminhtml/session')->addSuccess( - $this->__('Template has been deleted.') - ); + Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Template has been deleted.')); // go to grid $this->_redirect('*/*/template'); @@ -787,9 +763,7 @@ public function deleteTemplateAction() } // display error message - Mage::getSingleton('adminhtml/session')->addError( - $this->__('Unable to find template to delete.') - ); + Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find template to delete.')); } /** @@ -815,7 +789,7 @@ public function historyAction() /** * Render apps grid * - * @return void + * @return null */ public function gridAction() { @@ -826,7 +800,7 @@ public function gridAction() /** * Process all uploaded files - * setup filenames to the configuration return array + * setup file names to the configuration return array * * @param array $data * @param bool $restore @@ -844,13 +818,14 @@ protected function _processUploadedFiles($data, $restore = false) if (!empty($_FILES)) { foreach ($_FILES as $field => $file) { if (!empty($file['name']) && is_scalar($file['name'])) { - $uploadedFileName = Mage::helper('xmlconnect/image')->handleUpload($field, $data); + $uploadedFileName = Mage::helper('xmlconnect/image')->handleUpload($field); if (!empty($uploadedFileName)) { $this->_uploadedFiles[$field] = $uploadedFileName; } } } } + foreach ($this->_uploadedFiles as $fieldPath => $fileName) { Mage::helper('xmlconnect')->_injectFieldToArray($data, $fieldPath, $fileName); } @@ -973,7 +948,7 @@ protected function _initTemplate($paramName = 'id') /** * List AirMail message queue grid * - * @return void + * @return null */ public function queueAction() { @@ -985,7 +960,7 @@ public function queueAction() /** * Edit message action * - * @return void + * @return null */ public function editQueueAction() { @@ -1000,7 +975,7 @@ public function editQueueAction() /** * Filtering posted data. Converting localized data if needed * - * @param array + * @param array $data * @return array */ protected function _filterPostData($data) @@ -1012,7 +987,7 @@ protected function _filterPostData($data) /** * Cancel queue action * - * @return void + * @return null */ public function cancelQueueAction() { @@ -1039,7 +1014,7 @@ public function cancelQueueAction() /** * Delete queue action * - * @return void + * @return null */ public function deleteQueueAction() { @@ -1066,7 +1041,7 @@ public function deleteQueueAction() /** * Cancel selected queue action * - * @return void + * @return null */ public function massCancelQueueAction() { @@ -1077,9 +1052,7 @@ public function massCancelQueueAction() try { $queue = Mage::getModel('xmlconnect/queue'); foreach ($queueIds as $queueId) { - $queue->reset() - ->load((int)$queueId) - ->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED) + $queue->reset()->load((int)$queueId)->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED) ->save(); } Mage::getSingleton('adminhtml/session')->addSuccess( @@ -1096,7 +1069,7 @@ public function massCancelQueueAction() /** * Delete selected queue action * - * @return void + * @return null */ public function massDeleteQueueAction() { @@ -1107,15 +1080,10 @@ public function massDeleteQueueAction() try { $queue = Mage::getModel('xmlconnect/queue'); foreach ($queueIds as $queueId) { - $queue->reset() - ->load($queueId) - ->setStatus(Mage_XmlConnect_Model_Queue::STATUS_DELETED) - ->save(); + $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) - ) + Mage::helper('adminhtml')->__('Total of %d record(s) were deleted.', count($queueIds)) ); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); @@ -1128,7 +1096,7 @@ public function massDeleteQueueAction() /** * Save AirMail message action * - * @return void + * @return null */ public function saveMessageAction() { @@ -1143,12 +1111,25 @@ public function saveMessageAction() $message = $this->_initMessage(); if (!$template->getId() && !$message->getTemplateId()) { - $this->_getSession()->addError( - $this->__('Template for new AirMail Message does not exist.') - ); + $this->_getSession()->addError($this->__('Template for new AirMail Message does not exist.')); $this->_redirect('*/*/queue'); return; } + + /** @var $app Mage_XmlConnect_Model_Application */ + $app = Mage::getModel('xmlconnect/application')->loadByCode($template->getAppCode()); + $deviceType = Mage::helper('xmlconnect')->getDeviceType($app); + + if ($deviceType == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID + && $data['type'] == Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL + ) { + $this->_getSession()->addError($this->__('Android doesn\'t support AirMail message type.')); + $redirectParams = $this->_getQueueMessageParams($message); + $action = $message->getId() ? 'editQueue' : 'queueMessage'; + $this->_redirect('*/*/' . $action, $redirectParams); + return; + } + $temporaryObject = new Varien_Object(); $temporaryObject->setData($data); @@ -1163,7 +1144,7 @@ public function saveMessageAction() $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 be edited when status of the message is "IN QUEUE" only.') + $this->__('Message can be edited when status of the message is "In Queue" only.') ); $this->_redirect('*/*/queue'); return; @@ -1207,22 +1188,34 @@ public function saveMessageAction() 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'); - } + $redirectParams = $this->_getQueueMessageParams($message); $this->_redirect('*/*/queueMessage', $redirectParams); } else { $this->_redirect('*/*/queue'); } } + /** + * Get queue message action params + * + * @param Mage_XmlConnect_Model_Queue $message + * @return array + */ + protected function _getQueueMessageParams(Mage_XmlConnect_Model_Queue $message) + { + $redirectParams = array(); + if ($message && $message->getId()) { + $redirectParams['id'] = $message->getId(); + } else { + $redirectParams['template_id'] = (int) $this->getRequest()->getParam('template_id'); + } + return $redirectParams; + } + /** * Temlate grid * - * @return void + * @return null */ public function templateAction() { @@ -1234,7 +1227,7 @@ public function templateAction() /** * Create new template action * - * @return void + * @return null */ public function newTemplateAction() { @@ -1244,7 +1237,7 @@ public function newTemplateAction() /** * Edit template action * - * @return void + * @return null */ public function editTemplateAction() { @@ -1252,9 +1245,7 @@ public function editTemplateAction() $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->_getSession()->addError($this->__('At last one application has to be created.')); $this->_redirect('*/*/template'); return; } @@ -1267,7 +1258,7 @@ public function editTemplateAction() /** * Save template action * - * @return void + * @return null */ public function saveTemplateAction() { @@ -1276,7 +1267,7 @@ public function saveTemplateAction() $isError = false; if ($data) { $data = Mage::getModel('core/input_filter_maliciousCode')->filter($data); - Mage::getSingleton('adminhtml/session')->setFormData($data); + Mage::getSingleton('adminhtml/session')->setTemplateFormData($data); try { $id = $this->getRequest()->getParam('id'); $template = $this->_initTemplate(); @@ -1308,7 +1299,7 @@ public function saveTemplateAction() /** * Add message to queue action * - * @return void + * @return null */ public function queueMessageAction() { @@ -1316,22 +1307,36 @@ public function queueMessageAction() if (!$message->getId()) { $template = $this->_initTemplate('template_id'); if (!$template->getId()) { - $this->_getSession()->addError( - $this->__('Template for new AirMail Message does not exist.') - ); + $this->_getSession()->addError($this->__('Template for new AirMail Message does not exist.')); $this->_redirect('*/*/template'); } } + if (isset($template)) { + $appCode = $template->getAppCode(); + } else { + $appCode = Mage::getModel('xmlconnect/template')->load($message->getTemplateId())->getAppCode(); + } + + /** @var $app Mage_XmlConnect_Model_Application */ + $app = Mage::getModel('xmlconnect/application')->loadByCode($appCode); + + if(!$app->isNotificationsActive()) { + $this->_getSession()->addError( + $this->__('Queue is allowed only for applications with enabled Push Notification.') + ); + $action = $message->getId() ? 'queue' : 'template'; + $this->_redirect('*/*/' . $action); + return; + } + $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->_addBreadcrumb($this->__('AirMail Message Queue'), $this->__('AirMail Message Queue'), $this->getUrl('*/*/queue') ); $this->_addBreadcrumb($title, $title); @@ -1343,7 +1348,7 @@ public function queueMessageAction() /** * Edit queue message action * - * @return void + * @return null */ public function editMessageAction() { diff --git a/app/code/core/Mage/XmlConnect/controllers/CartController.php b/app/code/core/Mage/XmlConnect/controllers/CartController.php index c8a3588fc0..b48bfe6457 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CartController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CartController.php @@ -36,42 +36,48 @@ class Mage_XmlConnect_CartController extends Mage_XmlConnect_Controller_Action /** * Shopping cart display action * - * @return void + * @return null */ public function indexAction() { - $messages = array(); - $cart = $this->_getCart(); - if ($cart->getQuote()->getItemsCount()) { - $cart->init(); - $cart->save(); - - if (!$this->_getQuote()->validateMinimumAmount()) { - $warning = Mage::getStoreConfig('sales/minimum_order/description'); - $messages[parent::MESSAGE_STATUS_WARNING][] = $warning; + try { + $messages = array(); + $cart = $this->_getCart(); + if ($cart->getQuote()->getItemsCount()) { + $cart->init(); + $cart->save(); + + if (!$this->_getQuote()->validateMinimumAmount()) { + $warning = Mage::getStoreConfig('sales/minimum_order/description'); + $messages[parent::MESSAGE_STATUS_WARNING][] = $warning; + } } - } - foreach ($cart->getQuote()->getMessages() as $message) { - if ($message) { - $messages[$message->getType()][] = $message->getText(); + foreach ($cart->getQuote()->getMessages() as $message) { + if ($message) { + $messages[$message->getType()][] = $message->getText(); + } } - } - - /** - * if customer enters shopping cart we should mark quote - * as modified bc he can has checkout page in another window. - */ - $this->_getSession()->setCartWasUpdated(true); - $this->loadLayout(false)->getLayout()->getBlock('xmlconnect.cart')->setMessages($messages); - $this->renderLayout(); + /** + * if customer enters shopping cart we should mark quote + * as modified bc he can has checkout page in another window. + */ + $this->_getSession()->setCartWasUpdated(true); + $this->loadLayout(false)->getLayout()->getBlock('xmlconnect.cart')->setMessages($messages); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + Mage::logException($e); + $this->_message($this->__('Can\'t load cart.'), self::MESSAGE_STATUS_ERROR); + } } /** * Update shoping cart data action * - * @return void + * @return null */ public function updateAction() { @@ -87,17 +93,17 @@ public function updateAction() } } $cart = $this->_getCart(); - if (! $cart->getCustomerSession()->getCustomer()->getId() && $cart->getQuote()->getCustomerId()) { + if (!$cart->getCustomerSession()->getCustomer()->getId() && $cart->getQuote()->getCustomerId()) { $cart->getQuote()->setCustomerId(null); } - $cart->updateItems($cartData) - ->save(); + $cart->updateItems($cartData)->save(); } $this->_getSession()->setCartWasUpdated(true); $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) { + Mage::logException($e); $this->_message($this->__('Can\'t update cart.'), self::MESSAGE_STATUS_ERROR); } } @@ -128,7 +134,7 @@ protected function _getProductRequest($requestInfo) /** * Add product to shopping cart action * - * @return void + * @return null */ public function addAction() { @@ -145,8 +151,7 @@ public function addAction() $product = null; $productId = (int) $this->getRequest()->getParam('product'); if ($productId) { - $_product = Mage::getModel('catalog/product') - ->setStoreId(Mage::app()->getStore()->getId()) + $_product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId()) ->load($productId); if ($_product->getId()) { $product = $_product; @@ -165,7 +170,6 @@ public function addAction() if ($product->isConfigurable()) { $request = $this->_getProductRequest($params); - /** * Hardcoded Configurable product default * Set min required qty for a product if it's need @@ -190,7 +194,6 @@ public function addAction() } $cart->save(); - $this->_getSession()->setCartWasUpdated(true); if (isset($params['whishlist_id'])) { @@ -227,7 +230,7 @@ public function addAction() if (isset($wishlistMessage)) { $this->_message($wishlistMessage, self::MESSAGE_STATUS_ERROR); } else { - $productName = Mage::helper('core')->htmlEscape($product->getName()); + $productName = Mage::helper('core')->escapeHtml($product->getName()); $message = $this->__('%s has been added to your cart.', $productName); if ($cart->getQuote()->getHasError()) { $message .= $this->__(' But cart has some errors.'); @@ -243,6 +246,7 @@ public function addAction() $this->_message($messageText, parent::MESSAGE_STATUS_ERROR); } } catch (Exception $e) { + Mage::logException($e); $this->_message($this->__('Can\'t add item to shopping cart.'), self::MESSAGE_STATUS_ERROR); } } @@ -250,7 +254,7 @@ public function addAction() /** * Delete shoping cart item action * - * @return void + * @return null */ public function deleteAction() { @@ -262,6 +266,7 @@ public function deleteAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), parent::MESSAGE_STATUS_ERROR); } catch (Exception $e) { + Mage::logException($e); $this->_message($this->__('Can\'t remove the item.'), self::MESSAGE_STATUS_ERROR); } } @@ -270,7 +275,7 @@ public function deleteAction() /** * Initialize coupon * - * @return void + * @return null */ public function couponAction() { @@ -295,15 +300,19 @@ public function couponAction() try { $this->_getQuote()->getShippingAddress()->setCollectShippingRates(true); - $this->_getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '') - ->collectTotals() - ->save(); + $this->_getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '')->collectTotals()->save(); if ($couponCode) { if ($couponCode == $this->_getQuote()->getCouponCode()) { - $this->_message($this->__('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($this->__('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($this->__('Coupon code was canceled.'), parent::MESSAGE_STATUS_SUCCESS); @@ -312,20 +321,123 @@ public function couponAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { + Mage::logException($e); $this->_message($this->__('Can\'t apply the coupon code.'), self::MESSAGE_STATUS_ERROR); } } + /** + * Add Gift Card action + * + * @return null + */ + public function addGiftcardAction() + { + /** + * No reason continue with empty shopping cart + */ + if (!$this->_getQuote()->getItemsCount()) { + $this->_message($this->__('Shopping cart is empty.'), self::MESSAGE_STATUS_ERROR); + return; + } + + $data = $this->getRequest()->getPost(); + if (!empty($data['giftcard_code'])) { + $code = $data['giftcard_code']; + try { + Mage::getModel('enterprise_giftcardaccount/giftcardaccount')->loadByCode($code)->addToCart(); + $this->_message( + $this->__('Gift Card "%s" was added.', Mage::helper('core')->escapeHtml($code)), + self::MESSAGE_STATUS_SUCCESS + ); + return; + } catch (Mage_Core_Exception $e) { + Mage::dispatchEvent('enterprise_giftcardaccount_add', array('status' => 'fail', 'code' => $code)); + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Cannot apply gift card.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } else { + $this->_message($this->__('Gift Card code is empty.'), self::MESSAGE_STATUS_ERROR); + return; + } + } + + /** + * Remove Gift Card action + * + * @return null + */ + public function removeGiftcardAction() + { + $code = $this->getRequest()->getParam('giftcard_code'); + if ($code) { + try { + Mage::getModel('enterprise_giftcardaccount/giftcardaccount')->loadByCode($code)->removeFromCart(); + $this->_message( + $this->__('Gift Card "%s" was removed.', Mage::helper('core')->escapeHtml($code)), + self::MESSAGE_STATUS_SUCCESS + ); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Cannot remove gift card.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } else { + $this->_message($this->__('Gift Card code is empty.'), self::MESSAGE_STATUS_ERROR); + return; + } + } + + /** + * Remove Store Credit action + * + * @return null + */ + public function removeStoreCreditAction() + { + if (!Mage::helper('enterprise_customerbalance')->isEnabled()) { + $this->_message($this->__('Customer balance is disabled for current store'), self::MESSAGE_STATUS_ERROR); + return; + } + + $quote = $this->_getQuote(); + + if ($quote->getUseCustomerBalance()) { + $this->_message( + $this->__('The store credit payment has been removed from shopping cart.'), + self::MESSAGE_STATUS_SUCCESS + ); + $quote->setUseCustomerBalance(false)->collectTotals()->save(); + return; + } else { + $this->_message( + $this->__('Store Credit payment is not being used in your shopping cart.'), + self::MESSAGE_STATUS_ERROR + ); + return; + } + } + /** * Get shopping cart summary and flag is_virtual * - * @return void + * @return null */ public function infoAction() { - $this->_getQuote()->collectTotals()->save(); - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->_getQuote()->collectTotals()->save(); + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + Mage::logException($e); + $this->_message($this->__('Can\'t load cart info.'), self::MESSAGE_STATUS_ERROR); + } } /** diff --git a/app/code/core/Mage/XmlConnect/controllers/CatalogController.php b/app/code/core/Mage/XmlConnect/controllers/CatalogController.php index e512bba80e..9b1381c2e8 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CatalogController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CatalogController.php @@ -36,22 +36,32 @@ class Mage_XmlConnect_CatalogController extends Mage_XmlConnect_Controller_Actio /** * Category list * - * @return void + * @return null */ public function categoryAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + Mage::logException($e); + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + Mage::logException($e); + $this->_message( + $this->__('An error occurred while loading categories.'), self::MESSAGE_STATUS_ERROR + ); + } } /** * Filter product list * - * @return void + * @return null */ public function filtersAction() { - try{ + try { $this->loadLayout(false); $this->renderLayout(); } catch (Mage_Core_Exception $e) { @@ -59,8 +69,7 @@ public function filtersAction() } catch (Exception $e) { Mage::logException($e); $this->_message( - $this->__('An error occurred while loading category filters.'), - self::MESSAGE_STATUS_ERROR + $this->__('An error occurred while loading category filters.'), self::MESSAGE_STATUS_ERROR ); } } @@ -68,7 +77,7 @@ public function filtersAction() /** * Product information * - * @return void + * @return null */ public function productAction() { @@ -87,51 +96,79 @@ public function productAction() /** * Product options list * - * @return void + * @return null */ public function productOptionsAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load product options.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Product gallery images list * - * @return void + * @return null */ public function productGalleryAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load product gallery.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Product reviews list * - * @return void + * @return null */ public function productReviewsAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load product reviews.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Add new review * - * @return void + * @return null */ public function productReviewAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load product review.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Perform search products * - * @return void + * @return null */ public function searchAction() { @@ -176,20 +213,34 @@ public function searchAction() } } - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load search.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Retrieve suggestions based on search query * - * @return void + * @return null */ public function searchSuggestAction() { $this->getRequest()->setParam('q', $this->getRequest()->getParam('query')); - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load search.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** @@ -210,7 +261,11 @@ public function sendEmailAction() } if (!$helper->isAllowForGuest() && !$session->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message( + $this->__('Customer not logged in.'), + self::MESSAGE_STATUS_ERROR, + array('logged_in' => '0') + ); return $this; } @@ -266,8 +321,7 @@ public function sendEmailAction() */ $categoryId = $this->getRequest()->getParam('category_id', null); if ($categoryId) { - $category = Mage::getModel('catalog/category') - ->load($categoryId); + $category = Mage::getModel('catalog/category')->load($categoryId); $product->setCategory($category); Mage::register('current_category', $category); } diff --git a/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php b/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php index 5e89b941f6..4cc97dbcb5 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php @@ -28,7 +28,7 @@ * XmlConnect checkout controller * * @category Mage - * @package Mage_Checkout + * @package Mage_Xmlconnect * @author Magento Core Team */ class Mage_XmlConnect_CheckoutController extends Mage_XmlConnect_Controller_Action @@ -36,7 +36,7 @@ class Mage_XmlConnect_CheckoutController extends Mage_XmlConnect_Controller_Acti /** * Make sure customer is logged in * - * @return void + * @return null */ public function preDispatch() { @@ -45,7 +45,11 @@ public function preDispatch() && !Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout() ) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message( + $this->__('Customer not logged in.'), + self::MESSAGE_STATUS_ERROR, + array('logged_in' => '0') + ); return ; } } @@ -63,7 +67,7 @@ public function getOnepage() /** * Onepage Checkout page * - * @return void + * @return null */ public function indexAction() { @@ -87,47 +91,75 @@ public function indexAction() Mage::getSingleton('checkout/session')->setCartWasUpdated(false); $this->getOnepage()->initCheckout(); - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load checkout.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Display customer new billing addrress form * - * @return void + * @return null */ public function newBillingAddressFormAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load billing address form.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Display customer new shipping addrress form * - * @return void + * @return null */ public function newShippingAddressFormAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load shipping address form.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Billing addresses list action * - * @return void + * @return null */ public function billingAddressAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load billing address.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Save billing address to current quote using onepage model * - * @return void + * @return null */ public function saveBillingAddressAction() { @@ -155,18 +187,25 @@ public function saveBillingAddressAction() /** * Shipping addresses list action * - * @return void + * @return null */ public function shippingAddressAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load billing address.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Save shipping address to current quote using onepage model * - * @return void + * @return null */ public function saveShippingAddressAction() { @@ -259,7 +298,7 @@ protected function _checkUseForShipping(array $data, $billingAddress, $shippingA /** * Get shipping methods for current quote * - * @return void + * @return null */ public function shippingMethodsAction() { @@ -279,7 +318,7 @@ public function shippingMethodsAction() /** * Shipping method save action * - * @return void + * @return null */ public function saveShippingMethodAction() { @@ -290,9 +329,16 @@ public function saveShippingMethodAction() $data = $this->getRequest()->getPost('shipping_method', ''); $result = $this->getOnepage()->saveShippingMethod($data); - if (!isset($result['error'])) { + if (!$result) { + + Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array( + 'request' => $this->getRequest(), + 'quote' => $this->getOnepage()->getQuote() + )); + $this->getOnepage()->getQuote()->collectTotals()->save(); + $this->_message($this->__('Shipping method has been set.'), self::MESSAGE_STATUS_SUCCESS); - } else { + } elseif(isset($result['error'])) { if (!is_array($result['message'])) { $result['message'] = array($result['message']); } @@ -300,6 +346,7 @@ public function saveShippingMethodAction() 'request' => $this->getRequest(), 'quote' => $this->getOnepage()->getQuote() )); + $this->getOnepage()->getQuote()->collectTotals()->save(); $this->_message(implode('. ', $result['message']), self::MESSAGE_STATUS_ERROR); } } @@ -308,7 +355,7 @@ public function saveShippingMethodAction() /** * Save checkout method * - * @return void + * @return null */ public function saveMethodAction() { @@ -329,7 +376,7 @@ public function saveMethodAction() /** * Get payment methods action * - * @return void + * @return null */ public function paymentMethodsAction() { @@ -346,7 +393,7 @@ public function paymentMethodsAction() /** * Save payment action * - * @return void + * @return null */ public function savePaymentAction() { @@ -375,19 +422,26 @@ public function savePaymentAction() /** * Order summary info action * - * @return void + * @return null */ public function orderReviewAction() { $this->getOnepage()->getQuote()->collectTotals()->save(); - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load order review.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Create order action * - * @return void + * @return null */ public function saveOrderAction() { diff --git a/app/code/core/Mage/XmlConnect/controllers/CmsController.php b/app/code/core/Mage/XmlConnect/controllers/CmsController.php index 9103c06f33..0ea582df1e 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CmsController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CmsController.php @@ -27,14 +27,16 @@ /** * XmlConnect cms page controller * - * @author Magento Core Team + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team */ class Mage_XmlConnect_CmsController extends Mage_XmlConnect_Controller_Action { /** * Declare content type header * - * @return void + * @return null */ public function preDispatch() { @@ -45,7 +47,7 @@ public function preDispatch() /** * Category list * - * @return void + * @return null */ public function pageAction() { diff --git a/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php b/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php index a757a13131..68c24a2e7e 100644 --- a/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php +++ b/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php @@ -36,7 +36,7 @@ class Mage_XmlConnect_ConfigurationController extends Mage_Core_Controller_Front /** * Declare content type header * - * @return void + * @return null */ public function preDispatch() { @@ -52,7 +52,6 @@ public function preDispatch() */ protected function _initApp() { - $cookieName = Mage_XmlConnect_Model_Application::APP_CODE_COOKIE_NAME; $code = $this->getRequest()->getParam($cookieName); $screenSize = (string) $this->getRequest()->getParam( @@ -62,12 +61,16 @@ protected function _initApp() $app = Mage::getModel('xmlconnect/application'); if ($app) { $app->loadByCode($code); - Mage::app()->setCurrentStore(Mage::app()->getStore($app->getStoreId())->getCode()); + Mage::app()->setCurrentStore( + Mage::app()->getStore($app->getStoreId())->getCode() + ); Mage::getSingleton('core/locale')->emulate($app->getStoreId()); $app->setScreenSize($screenSize); + if (!$app->getId()) { Mage::throwException($this->__('App with specified code does not exist.')); } + $app->loadConfiguration(); } else { Mage::throwException($this->__('App code required.')); @@ -82,20 +85,22 @@ protected function _initApp() * Set application coolies: application code and device screen size. * * @param Mage_XmlConnect_Model_Application $app - * @return void + * @return null */ protected function _initCookies(Mage_XmlConnect_Model_Application $app) { - $cookieToSetArray = array ( + $cookieToSetArray = array( array( 'cookieName' => Mage_XmlConnect_Model_Application::APP_CODE_COOKIE_NAME, 'paramName' => Mage_XmlConnect_Model_Application::APP_CODE_COOKIE_NAME, - 'value' => $app->getCode()), + 'value' => $app->getCode() + ), array( 'cookieName' => Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_NAME, 'paramName' => Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_NAME, - 'value' => $app->getScreenSize()) - ); + 'value' => $app->getScreenSize() + )); + foreach ($cookieToSetArray as $item) { if (!isset($_COOKIE[$item['cookieName']]) || $_COOKIE[$item['cookieName']] != $this->getRequest()->getParam($item['paramName']) @@ -105,13 +110,7 @@ protected function _initCookies(Mage_XmlConnect_Model_Application $app) */ $cookieExpireOffset = 3600 * 24 * 30; Mage::getSingleton('core/cookie')->set( - $item['cookieName'], - $item['value'], - $cookieExpireOffset, - '/', - null, - null, - true + $item['cookieName'], $item['value'], $cookieExpireOffset, '/', null, null, true ); } } @@ -120,7 +119,7 @@ protected function _initCookies(Mage_XmlConnect_Model_Application $app) /** * Default action * - * @return void + * @return null */ public function indexAction() { @@ -143,14 +142,10 @@ public function indexAction() $this->loadLayout(false); $this->renderLayout(); } catch (Mage_Core_Exception $e) { - $this->_message( - $e->getMessage(), - Mage_XmlConnect_Controller_Action::MESSAGE_STATUS_ERROR - ); + $this->_message($e->getMessage(), Mage_XmlConnect_Controller_Action::MESSAGE_STATUS_ERROR); } catch (Exception $e) { $this->_message( - $this->__('Can\'t show configuration.'), - Mage_XmlConnect_Controller_Action::MESSAGE_STATUS_ERROR + $this->__('Can\'t show configuration.'), Mage_XmlConnect_Controller_Action::MESSAGE_STATUS_ERROR ); Mage::logException($e); } @@ -161,15 +156,14 @@ public function indexAction() * * @param string $text * @param string $status - * @param string $type - * @param string $action - * @return void + * @return null */ - protected function _message($text, $status, $type='', $action='') + protected function _message($text, $status) { + /** @var $message Mage_XmlConnect_Model_Simplexml_Element */ $message = Mage::getModel('xmlconnect/simplexml_element', ''); - $message->addChild('status', $status); - $message->addChild('text', $text); + $message->addCustomChild('status', $status); + $message->addCustomChild('text', $text); $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 12591cdbc2..35ce112d60 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CustomerController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CustomerController.php @@ -34,9 +34,9 @@ class Mage_XmlConnect_CustomerController extends Mage_XmlConnect_Controller_Action { /** - * Customer authentification action + * Customer authentication action * - * @return void + * @return null */ public function loginAction() { @@ -63,6 +63,7 @@ public function loginAction() switch ($e->getCode()) { case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED: // TODO: resend confirmation email message with action + $message = $e->getMessage(); break; case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD: $message = $e->getMessage(); @@ -82,7 +83,7 @@ public function loginAction() /** * Customer logout * - * @return void + * @return null */ public function logoutAction() { @@ -92,6 +93,7 @@ public function logoutAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { + Mage::logException($e); $this->_message($this->__('Customer logout problem.'), self::MESSAGE_STATUS_ERROR); } } @@ -99,42 +101,52 @@ public function logoutAction() /** * Customer registration/edit account form * - * @return void + * @return null */ public function formAction() { - $customer = null; - $editFlag = (int)$this->getRequest()->getParam('edit'); - if ($editFlag == 1) { - if (!$this->_getSession()->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); - return; + try { + $customer = null; + $editFlag = (int)$this->getRequest()->getParam('edit'); + if ($editFlag == 1) { + if (!$this->_getSession()->isLoggedIn()) { + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); + return; + } + $customer = $this->_getSession()->getCustomer(); } - $customer = $this->_getSession()->getCustomer(); - } - $this->loadLayout(false)->getLayout()->getBlock('xmlconnect.customer.form')->setCustomer($customer); - $this->renderLayout(); + $this->loadLayout(false)->getLayout()->getBlock('xmlconnect.customer.form')->setCustomer($customer); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + Mage::logException($e); + $this->_message($this->__('Can\'t load customer form.'), self::MESSAGE_STATUS_ERROR); + } } /** * Change customer data action * - * @return void + * @return null */ public function editAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); - return ; + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); + return; } if ($this->getRequest()->isPost()) { $customer = $this->_getSession()->getCustomer(); /* @var $customerForm Mage_Customer_Model_Form */ $customerForm = Mage::getModel('customer/form'); - $customerForm->setFormCode('customer_account_edit') - ->setEntity($customer); + $customerForm->setFormCode('customer_account_edit')->setEntity($customer); $customerData = $customerForm->extractData($this->getRequest()); @@ -165,7 +177,7 @@ public function editAction() $oldPass = $this->_getSession()->getCustomer()->getPasswordHash(); if (strpos($oldPass, ':')) { - list($_salt, $salt) = explode(':', $oldPass); + list(, $salt) = explode(':', $oldPass); } else { $salt = false; } @@ -208,7 +220,7 @@ public function editAction() /** * Save customer account * - * @return void + * @return null */ public function saveAction() { @@ -231,8 +243,7 @@ public function saveAction() /* @var $customerForm Mage_Customer_Model_Form */ $customerForm = Mage::getModel('customer/form'); - $customerForm->setFormCode('customer_account_create') - ->setEntity($customer); + $customerForm->setFormCode('customer_account_create')->setEntity($customer); $customerData = $customerForm->extractData($this->getRequest()); @@ -290,7 +301,7 @@ public function saveAction() $message = $this->__('Invalid customer data.'); } $this->_message($message, self::MESSAGE_STATUS_ERROR); - return ; + return; } } catch (Mage_Core_Exception $e) { if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) { @@ -309,7 +320,7 @@ public function saveAction() /** * Send new password to customer by specified email * - * @return void + * @return null */ public function forgotPasswordAction() { @@ -319,8 +330,7 @@ public function forgotPasswordAction() $this->_message($this->__('Invalid email address.'), self::MESSAGE_STATUS_ERROR); return; } - $customer = Mage::getModel('customer/customer') - ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()) + $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId()) ->loadByEmail($email); if ($customer->getId()) { @@ -329,22 +339,19 @@ public function forgotPasswordAction() $customer->changePassword($newPassword, false); $customer->sendPasswordReminderEmail(); $this->_message( - $this->__('A new password has been sent.'), - self::MESSAGE_STATUS_SUCCESS + $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( - $this->__('Problem changing or sending password.'), - self::MESSAGE_STATUS_ERROR + $this->__('Problem changing or sending password.'), self::MESSAGE_STATUS_ERROR ); } } else { $this->_message( - $this->__('This email address was not found in our records.'), - self::MESSAGE_STATUS_ERROR + $this->__('This email address was not found in our records.'), self::MESSAGE_STATUS_ERROR ); } } else { @@ -355,18 +362,28 @@ public function forgotPasswordAction() /** * Customer addresses list * - * @return void + * @return null */ public function addressAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); - return ; + Mage::log('address:'.$this->_getSession()->getSessionId()); + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); + return; } if (count($this->_getSession()->getCustomer()->getAddresses())) { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load addresses.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } else { /** @var $message Mage_XmlConnect_Model_Simplexml_Element */ $message = Mage::getModel('xmlconnect/simplexml_element', ''); @@ -379,43 +396,56 @@ public function addressAction() /** * Customer add/edit address form * - * @return void + * @return null */ public function addressFormAction() { - if (!$this->_getSession()->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); - return ; - } + try { + if (!$this->_getSession()->isLoggedIn()) { + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); + return; + } - $address = Mage::getModel('customer/address'); + $address = Mage::getModel('customer/address'); - /** - * Init address object - */ - $addressId = (int)$this->getRequest()->getParam('id'); - if ($addressId) { - $address->load($addressId); - if ($address->getCustomerId() != $this->_getSession()->getCustomerId()) { - $this->_message($this->__('Specified address does not exist.'), self::MESSAGE_STATUS_ERROR); - return ; + /** + * Init address object + */ + $addressId = (int)$this->getRequest()->getParam('id'); + if ($addressId) { + $address->load($addressId); + if ($address->getCustomerId() != $this->_getSession()->getCustomerId()) { + $this->_message($this->__('Specified address does not exist.'), self::MESSAGE_STATUS_ERROR); + return; + } } - } - $this->loadLayout(false)->getLayout()->getBlock('xmlconnect.customer.address.form')->setAddress($address); - $this->renderLayout(); + $this->loadLayout(false)->getLayout()->getBlock('xmlconnect.customer.address.form')->setAddress($address); + + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } catch (Exception $e) { + Mage::logException($e); + $this->_message($this->__('Can\'t load customer form.'), self::MESSAGE_STATUS_ERROR); + } } /** * Remove customer address * - * @return void + * @return null */ public function deleteAddressAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); - return ; + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); + return; } $addressId = $this->getRequest()->getParam('id', false); @@ -442,12 +472,14 @@ public function deleteAddressAction() /** * Add/Save customer address * - * @return void + * @return null */ public function saveAddressAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); return; } @@ -491,7 +523,7 @@ public function saveAddressAction() if (true === $addressValidation) { $address->save(); - + /** @var $message Mage_XmlConnect_Model_Simplexml_Element */ $message = Mage::getModel('xmlconnect/simplexml_element', ''); $message->addChild('status', self::MESSAGE_STATUS_SUCCESS); $message->addChild('text', $this->__('Address has been saved.')); @@ -519,35 +551,46 @@ public function saveAddressAction() /** * Customer orders list * - * @return void + * @return null */ public function orderListAction() { if (!$this->_getSession()->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); - return ; + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); + return; } - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load order list.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Customer order details * - * @return void + * @return null */ public function orderDetailsAction() { try { if (!$this->_getSession()->isLoggedIn()) { - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); return; } $orderId = (int) $this->getRequest()->getParam('order_id'); if (!$orderId) { - $this->_message($this->__('Order id not specified.'), self::MESSAGE_STATUS_ERROR); + $this->_message($this->__('Order id is not specified.'), self::MESSAGE_STATUS_ERROR); return; } @@ -580,9 +623,7 @@ protected function _canViewOrder($order) { $customerId = Mage::getSingleton('customer/session')->getCustomerId(); $availableStates = Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates(); - if ($order->getId() - && $order->getCustomerId() - && ($order->getCustomerId() == $customerId) + if ($order->getId() && $order->getCustomerId() && ($order->getCustomerId() == $customerId) && in_array($order->getState(), $availableStates, true) ) { return true; @@ -593,7 +634,7 @@ protected function _canViewOrder($order) /** * Check if customer is loggined * - * @return void + * @return null */ public function isLogginedAction() { @@ -624,4 +665,114 @@ protected function _getSession() { return Mage::getSingleton('customer/session'); } + + /** + * Store Credit info + * + * @return null + */ + public function storeCreditAction() + { + try { + /** + * Check is available Customer Balance + */ + if (!is_object(Mage::getConfig()->getNode('modules/Enterprise_CustomerBalance'))) { + $this->_message( + $this->__('Customer balance available in enterprise version of Magento only.'), + self::MESSAGE_STATUS_ERROR + ); + return; + } + $this->loadLayout(false); + $this->renderLayout(); + return; + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to render the store credits.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } + + /** + * Check Gift card action + * + * @return null + */ + public function giftcardCheckAction() + { + try { + /** + * Check is available Customer Balance + */ + if (!is_object(Mage::getConfig()->getNode('modules/Enterprise_GiftCardAccount'))) { + $this->_message( + $this->__('Gift card account available in enterprise version of Magento only.'), + self::MESSAGE_STATUS_ERROR + ); + return; + } + /* @var $card Enterprise_GiftCardAccount_Model_Giftcardaccount */ + $card = Mage::getModel('enterprise_giftcardaccount/giftcardaccount') + ->loadByCode($this->getRequest()->getParam('giftcard_code', '')); + Mage::register('current_giftcardaccount', $card); + + $card->isValid(true, true, true, false); + + $this->loadLayout(false); + $this->renderLayout(); + return; + } catch (Mage_Core_Exception $e) { + $card->unsetData(); + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to render a gift card account.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } + + /** + * Redeem Gift card action + * + * @return null + */ + public function giftcardRedeemAction() + { + try { + /** + * Check is available Customer Balance + */ + if (!is_object(Mage::getConfig()->getNode('modules/Enterprise_GiftCardAccount'))) { + $this->_message( + $this->__('Gift card account available in enterprise version of Magento only.'), + self::MESSAGE_STATUS_ERROR + ); + return; + } + + $code = $this->getRequest()->getParam('giftcard_code', ''); + if ($code) { + if (!Mage::helper('enterprise_customerbalance')->isEnabled()) { + Mage::throwException($this->__('Redemption functionality is disabled.')); + } + Mage::getModel('enterprise_giftcardaccount/giftcardaccount')->loadByCode($code) + ->setIsRedeemed(true)->redeem(); + + $this->_message( + $this->__('Gift Card "%s" was redeemed.', Mage::helper('core')->escapeHtml($code)), + self::MESSAGE_STATUS_SUCCESS + ); + } + return; + } catch (Mage_Core_Exception $e) { + if (isset($card) && is_object($card)) { + $card->unsetData(); + } + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Cannot redeem Gift Card.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } } diff --git a/app/code/core/Mage/XmlConnect/controllers/IndexController.php b/app/code/core/Mage/XmlConnect/controllers/IndexController.php index 8bbc928b3f..f4c8c2281b 100644 --- a/app/code/core/Mage/XmlConnect/controllers/IndexController.php +++ b/app/code/core/Mage/XmlConnect/controllers/IndexController.php @@ -27,18 +27,27 @@ /** * XmlConnect index controller * - * @author Magento Core Team + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team */ class Mage_XmlConnect_IndexController extends Mage_XmlConnect_Controller_Action { /** * Default action * - * @return void + * @return null */ public function indexAction() { - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load categories.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } } diff --git a/app/code/core/Mage/XmlConnect/controllers/Paypal/MeclController.php b/app/code/core/Mage/XmlConnect/controllers/Paypal/MeclController.php new file mode 100644 index 0000000000..9fa4427ca7 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/controllers/Paypal/MeclController.php @@ -0,0 +1,410 @@ + + */ +class Mage_XmlConnect_Paypal_MeclController extends Mage_XmlConnect_Controller_Action +{ + /** + * Config mode type + * + * @var string + */ + protected $_configType = 'xmlconnect/payment_method_paypal_config'; + + /** + * Config method type + * + * @var string + */ + protected $_configMethod = Mage_XmlConnect_Model_Payment_Method_Paypal_Mecl::MECL_METHOD_CODE; + + /** + * Checkout mode type + * + * @var string + */ + protected $_checkoutType = 'xmlconnect/paypal_mecl_checkout'; + + /** + * Paypal Mobile Express Checkout Library + * + * @var Mage_XmlConnect_Model_Payment_Method_Paypal_Mecl + */ + protected $_checkout = null; + + /** + * PayPal Mobile Express Checkout Library config model + * + * @var Mage_XmlConnect_Model_Payment_Method_Paypal_Config + */ + protected $_config = null; + + /** + * Checkout Quote + * + * @var Mage_Sales_Model_Quote + */ + protected $_quote = false; + + /** + * Instantiate config + */ + protected function _construct() + { + parent::_construct(); + $this->_config = Mage::getModel($this->_configType, array($this->_configMethod)); + } + + /** + * Make sure customer is logged in + * + * @return null + */ + public function preDispatch() + { + parent::preDispatch(); + if (!Mage::getSingleton('customer/session')->isLoggedIn() + && !Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout() + ) { + $this->setFlag('', self::FLAG_NO_DISPATCH, true); + $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, + array('logged_in' => '0') + ); + return; + } + } + + /** + * Start Mobile Express Checkout by requesting initial token and dispatching customer to PayPal + */ + public function startAction() + { + try { + $this->_initCheckout(); + + $customer = Mage::getSingleton('customer/session')->getCustomer(); + if ($customer && $customer->getId()) { + $this->_checkout->setCustomerWithAddressChange( + $customer, null, $this->_getQuote()->getShippingAddress() + ); + } + + $token = $this->_checkout->start(Mage::getUrl('*/*/return'), Mage::getUrl('*/*/cancel')); + + if ($token) { + $this->_initToken($token); + /** @var $message Mage_XmlConnect_Model_Simplexml_Element */ + $message = Mage::getModel('xmlconnect/simplexml_element', ''); + $message->addChild('status', self::MESSAGE_STATUS_SUCCESS); + $message->addChild('token', $token); + $this->getResponse()->setBody($message->asNiceXml()); + } else { + $this->_message($this->__('Token has not been set.'), self::MESSAGE_STATUS_ERROR); + } + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to start Mobile Express Checkout.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } + + /** + * Return from PayPal and dispatch customer to order review page + * (GetExpressCheckoutDetails method call) + */ + public function returnAction() + { + try { + $this->_initCheckout(); + $this->_checkout->returnFromPaypal($this->_initToken()); + $this->_message($this->__('Mobile Express Checkout processed successfully.'), self::MESSAGE_STATUS_SUCCESS); + return; + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + Mage::logException($e); + $this->_message($this->__('Unable to initialize return action.'), self::MESSAGE_STATUS_ERROR); + } + } + + /** + * Review order after returning from PayPal + */ + public function reviewAction() + { + try { + $this->_initCheckout(); + $this->_checkout->prepareOrderReview($this->_initToken()); + $this->loadLayout(false); + $this->_initLayoutMessages('paypal/session'); + + $messages = $this->_getSession()->getMessages(true); + $messageArray = array(); + foreach ($messages->getItems() as $message) { + $messageArray[] = $message; + } + + $detailsBlock = $this->getLayout()->getBlock('xmlconnect.cart.paypal.mecl.review'); + if (count($messageArray)) { + $detailsBlock->setPaypalMessages($messageArray); + } + + $detailsBlock->setQuote($this->_getQuote())->getChild('details')->setQuote($this->_getQuote()) + ->getChild('totals')->setQuote($this->_getQuote()); + $this->renderLayout(); + return; + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to initialize express checkout review.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } + + /** + * Get shipping method list for PayPal + */ + public function shippingMethodsAction() + { + try { + $this->_initCheckout(); + $this->_checkout->prepareOrderReview($this->_initToken()); + $this->loadLayout(false); + + $this->getLayout()->getBlock('xmlconnect.cart.paypal.mecl.shippingmethods')->setQuote($this->_getQuote()); + $this->renderLayout(); + return; + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message( + $this->__('Unable to initialize express checkout shipping method list.'), + self::MESSAGE_STATUS_ERROR + ); + Mage::logException($e); + } + } + + /** + * Update shipping method (combined action for ajax and regular request) + */ + public function saveShippingMethodAction() + { + try { + $this->_initCheckout(); + if ($this->getRequest()->getParam('shipping_method', false)) { + $this->_checkout->updateShippingMethod($this->getRequest()->getParam('shipping_method')); + $this->_message($this->__('Shipping method successfully updated'), self::MESSAGE_STATUS_SUCCESS); + } else { + $this->_message($this->__('Shipping method is required'), self::MESSAGE_STATUS_ERROR); + } + return; + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to update shipping method.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } + + /** + * Submit the order + */ + public function placeOrderAction() + { + try { + $this->_initCheckout(); + $this->_checkout->place($this->_initToken()); + + // prepare session to success or cancellation page + $session = $this->_getCheckoutSession(); + $session->clearHelperData(); + + // "last successful quote" + $quoteId = $this->_getQuote()->getId(); + $session->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId); + + // an order may be created + $order = $this->_checkout->getOrder(); + if ($order) { + $orderId = $order->getId(); + $realOrderId = $order->getIncrementId(); + $session->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId()); + } + + // recurring profiles may be created along with the order or without it + $profiles = $this->_checkout->getRecurringPaymentProfiles(); + if ($profiles) { + $ids = array(); + foreach($profiles as $profile) { + $ids[] = $profile->getId(); + } + $session->setLastRecurringProfileIds($ids); + } + + $this->_initToken(false); // no need in token anymore + + /** @var $message Mage_XmlConnect_Model_Simplexml_Element */ + $message = Mage::getModel('xmlconnect/simplexml_element', ''); + $message->addChild('status', self::MESSAGE_STATUS_SUCCESS); + + $text = $this->__('Thank you for your purchase! '); + $text .= $this->__('Your order # is: %s. ', $realOrderId); + $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); + $this->getResponse()->setBody($message->asNiceXml()); + return; + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to place the order.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } + + /** + * Cancel Mobile Express Checkout + */ + public function cancelAction() + { + try { + $this->_initToken(false); + // if there is an order - cancel it + $orderId = $this->_getCheckoutSession()->getLastOrderId(); + $order = ($orderId) ? Mage::getModel('sales/order')->load($orderId) : false; + + if ($order && $order->getId() && $order->getQuoteId() == $this->_getCheckoutSession()->getQuoteId()) { + $order->cancel()->save(); + $this->_getCheckoutSession()->unsLastQuoteId()->unsLastSuccessQuoteId()->unsLastOrderId() + ->unsLastRealOrderId(); + } + + $this->_message($this->__('Mobile Express Checkout has been canceled.'), self::MESSAGE_STATUS_SUCCESS); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to cancel Mobile Express Checkout.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } + } + + /** + * Instantiate quote and checkout + * + * @throws Mage_Core_Exception + * @return null + */ + protected function _initCheckout() + { + $quote = $this->_getQuote(); + if (!$quote->hasItems() || $quote->getHasError()) { + Mage::throwException($this->__('Unable to initialize PayPal Mobile Express Checkout.')); + } + if (!$quote->validateMinimumAmount()) { + $error = Mage::getStoreConfig('sales/minimum_order/error_message'); + Mage::throwException($error); + } + $this->_getCheckoutSession()->setCartWasUpdated(false); + + $this->_checkout = Mage::getSingleton($this->_checkoutType, array( + 'config' => $this->_config, 'quote' => $quote + )); + } + + /** + * Return checkout session object + * + * @return Mage_Checkout_Model_Session + */ + protected function _getCheckoutSession() + { + return Mage::getSingleton('checkout/session'); + } + + /** + * Return checkout quote object + * + * @return Mage_Sale_Model_Quote + */ + protected function _getQuote() + { + if (!$this->_quote) { + $this->_quote = $this->_getCheckoutSession()->getQuote(); + } + return $this->_quote; + } + + /** + * Search for proper checkout token in request or session or (un)set specified one + * Combined getter/setter + * + * @throws Mage_Core_Exception + * @param string $setToken + * @return Mage_Paypal_ExpressController|string + */ + protected function _initToken($setToken = null) + { + if (null !== $setToken) { + if (false === $setToken) { + if (!$this->_getSession()->getExpressCheckoutToken()) { // security measure for avoid unset token twice + Mage::throwException($this->__('PayPal Mobile Express Checkout Token does not exist.')); + } + $this->_getSession()->unsExpressCheckoutToken(); + } else { + $this->_getSession()->setExpressCheckoutToken($setToken); + } + return $this; + } + + $setToken = $this->getRequest()->getParam('token'); + if ($setToken) { + if ($setToken !== $this->_getSession()->getExpressCheckoutToken()) { + Mage::throwException($this->__('Wrong PayPal Mobile Express Checkout Token specified.')); + } + } else { + $setToken = $this->_getSession()->getExpressCheckoutToken(); + } + return $setToken; + } + + /** + * PayPal session instance getter + * + * @return Mage_PayPal_Model_Session + */ + private function _getSession() + { + return Mage::getSingleton('paypal/session'); + } +} diff --git a/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php b/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php index 7b35f5e25b..9ae6d5b99e 100644 --- a/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php +++ b/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php @@ -50,7 +50,7 @@ class Mage_XmlConnect_Paypal_MepController extends Mage_XmlConnect_Controller_Ac /** * Make sure customer is logged in * - * @return void + * @return null */ public function preDispatch() { @@ -59,33 +59,43 @@ public function preDispatch() && !Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout() ) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); - return ; + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); + return; } } /** * Start MEP Checkout * - * @return void + * @return null */ public function indexAction() { try { + if (is_object(Mage::getConfig()->getNode('modules/Enterprise_GiftCardAccount'))) { + $giftcardInfoBlock = $this->getLayout()->addBlock( + 'enterprise_giftcardaccount/checkout_onepage_payment_additional', 'giftcard_info' + ); + + if (intval($giftcardInfoBlock->getAppliedGiftCardAmount())) { + $this->_message( + $this->__('Paypal MEP doesn\'t support checkout with any discount.'), + self::MESSAGE_STATUS_ERROR + ); + return; + } + } + $this->_initCheckout(); $this->_checkout->initCheckout(); - $this->_message( - $this->__('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( - $this->__('Unable to start MEP Checkout.'), - self::MESSAGE_STATUS_ERROR - ); + $this->_message($this->__('Unable to start MEP Checkout.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } @@ -93,7 +103,7 @@ public function indexAction() /** * Save shipping address to current quote using onepage model * - * @return void + * @return null */ public function saveShippingAddressAction() { @@ -131,10 +141,7 @@ public function saveShippingAddressAction() $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } catch (Exception $e) { - $this->_message( - $this->__('Unable to save shipping address.'), - self::MESSAGE_STATUS_ERROR - ); + $this->_message($this->__('Unable to save shipping address.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } @@ -142,7 +149,7 @@ public function saveShippingAddressAction() /** * Get shipping methods for current quote * - * @return void + * @return null */ public function shippingMethodsAction() { @@ -153,10 +160,7 @@ public function shippingMethodsAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message( - $this->__('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); } } @@ -164,7 +168,7 @@ public function shippingMethodsAction() /** * Shipping method save action * - * @return void + * @return null */ public function saveShippingMethodAction() { @@ -176,12 +180,9 @@ public function saveShippingMethodAction() try { $this->_initCheckout(); $data = $this->getRequest()->getPost('shipping_method', ''); - $this->_quote->getShippingAddress() - ->setShippingMethod($data) - ->setCollectShippingRates(true) - ->save(); - + $this->_getQuote()->getShippingAddress()->setShippingMethod($data)->setCollectShippingRates(true)->save(); $result = $this->_checkout->saveShippingMethod($data); + if (!isset($result['error'])) { /** @var $message Mage_XmlConnect_Model_Simplexml_Element */ $message = Mage::getModel('xmlconnect/simplexml_element', ''); @@ -192,15 +193,9 @@ public function saveShippingMethodAction() } else { $quoteAddress = $this->_getQuote()->getShippingAddress(); } - $taxAmount = Mage::helper('core')->currency( - $quoteAddress->getBaseTaxAmount(), - false, - false - ); - $message->addChild( - 'tax_amount', - Mage::helper('xmlconnect')->formatPriceForXml($taxAmount) - ); + $taxAmount = Mage::helper('core')->currency($quoteAddress->getBaseTaxAmount(), false, false); + $message->addChild('tax_amount', Mage::helper('xmlconnect')->formatPriceForXml($taxAmount)); + $this->_getQuote()->collectTotals()->save(); $this->getResponse()->setBody($message->asNiceXml()); } else { if (!is_array($result['message'])) { @@ -211,10 +206,7 @@ public function saveShippingMethodAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message( - $this->__('Unable to save shipping method.'), - self::MESSAGE_STATUS_ERROR - ); + $this->_message($this->__('Unable to save shipping method.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } } @@ -222,7 +214,7 @@ public function saveShippingMethodAction() /** * Shopping cart totals * - * @return void + * @return null */ public function cartTotalsAction() { @@ -242,7 +234,7 @@ public function cartTotalsAction() /** * Submit the order * - * @return void + * @return null */ public function saveOrderAction() { @@ -263,9 +255,7 @@ public function saveOrderAction() $data = $this->getRequest()->getPost('payment', array()); if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $data['payer'] = Mage::getSingleton('customer/session') - ->getCustomer() - ->getEmail(); + $data['payer'] = Mage::getSingleton('customer/session')->getCustomer()->getEmail(); } $this->_checkout->savePayment($data); @@ -304,7 +294,7 @@ public function saveOrderAction() * Instantiate quote and checkout * * @throws Mage_Core_Exception - * @return void + * @return null */ protected function _initCheckout() { diff --git a/app/code/core/Mage/XmlConnect/controllers/PbridgeController.php b/app/code/core/Mage/XmlConnect/controllers/PbridgeController.php index 398050564a..8a33ad5a1f 100755 --- a/app/code/core/Mage/XmlConnect/controllers/PbridgeController.php +++ b/app/code/core/Mage/XmlConnect/controllers/PbridgeController.php @@ -72,7 +72,7 @@ protected function _checkPbridge() * Index Action. * Forward to result action * - * @return void + * @return null */ public function indexAction() { @@ -82,7 +82,7 @@ public function indexAction() /** * Result Action * - * @return void + * @return null */ public function resultAction() { @@ -131,8 +131,6 @@ public function outputAction() EOT; } - $this->getResponse()->setBody( - html_entity_decode(Mage::helper('xmlconnect')->htmlize($body)) - ); + $this->getResponse()->setBody(html_entity_decode(Mage::helper('xmlconnect')->htmlize($body))); } } diff --git a/app/code/core/Mage/XmlConnect/controllers/ReviewController.php b/app/code/core/Mage/XmlConnect/controllers/ReviewController.php index 0a0d2f8268..0c99bdcb62 100644 --- a/app/code/core/Mage/XmlConnect/controllers/ReviewController.php +++ b/app/code/core/Mage/XmlConnect/controllers/ReviewController.php @@ -27,7 +27,9 @@ /** * XmlConnect review controller * - * @author Magento Core Team + * @category Mage + * @package Mage_Xmlconnect + * @author Magento Core Team */ class Mage_XmlConnect_ReviewController extends Mage_XmlConnect_Controller_Action { @@ -38,22 +40,17 @@ class Mage_XmlConnect_ReviewController extends Mage_XmlConnect_Controller_Action */ protected function _initProduct() { - Mage::dispatchEvent('review_controller_product_init_before', array('controller_action'=>$this)); + Mage::dispatchEvent('review_controller_product_init_before', array('controller_action' => $this)); + $productId = (int) $this->getRequest()->getParam('id'); $product = $this->_loadProduct($productId); try { - Mage::dispatchEvent( - 'review_controller_product_init', - array('product' => $product) - ); - Mage::dispatchEvent( - 'review_controller_product_init_after', - array( - 'product' => $product, - 'controller_action' => $this - ) - ); + Mage::dispatchEvent('review_controller_product_init', array('product' => $product)); + Mage::dispatchEvent('review_controller_product_init_after', array( + 'product' => $product, + 'controller_action' => $this + )); } catch (Mage_Core_Exception $e) { Mage::logException($e); return false; @@ -75,9 +72,7 @@ protected function _loadProduct($productId) return false; } - $product = Mage::getModel('catalog/product') - ->setStoreId(Mage::app()->getStore()->getId()) - ->load($productId); + $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId); /** @var $product Mage_Catalog_Model_Product */ if (!$product->getId() || !$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) { return false; @@ -98,9 +93,7 @@ protected function _loadProduct($productId) */ protected function _checkGuestAllowed() { - if (Mage::getSingleton('customer/session')->isLoggedIn() - || Mage::helper('review')->getIsGuestAllowToWrite() - ) { + if (Mage::getSingleton('customer/session')->isLoggedIn() || Mage::helper('review')->getIsGuestAllowToWrite()) { return true; } @@ -114,7 +107,7 @@ protected function _checkGuestAllowed() /** * Get review form * - * @return void + * @return null */ public function formAction() { @@ -122,14 +115,21 @@ public function formAction() return; } - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + $this->_message($this->__('Unable to load review form.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + } } /** * Save product review * - * @return void + * @return null */ public function saveAction() { @@ -140,39 +140,38 @@ public function saveAction() $data = $this->getRequest()->getPost(); $rating = $this->getRequest()->getPost('ratings', array()); - if (($product = $this->_initProduct()) && !empty($data)) { + $product = $this->_initProduct(); + if ($product && !empty($data)) { /** @var $review Mage_Review_Model_Review */ $review = Mage::getModel('review/review')->setData($data); + $validate = $review->validate(); - if (($validate = $review->validate()) === true) { + if ($validate === true) { try { $review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE)) - ->setEntityPkValue($product->getId()) - ->setStatusId(Mage_Review_Model_Review::STATUS_PENDING) + ->setEntityPkValue($product->getId())->setStatusId(Mage_Review_Model_Review::STATUS_PENDING) ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) ->setStoreId(Mage::app()->getStore()->getId()) - ->setStores(array(Mage::app()->getStore()->getId())) - ->save(); + ->setStores(array(Mage::app()->getStore()->getId()))->save(); foreach ($rating as $ratingId => $optionId) { - Mage::getModel('rating/rating') - ->setRatingId($ratingId) - ->setReviewId($review->getId()) + Mage::getModel('rating/rating')->setRatingId($ratingId)->setReviewId($review->getId()) ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) ->addOptionVote($optionId, $product->getId()); } $review->aggregate(); $this->_message( - $this->__('Your review has been accepted for moderation.'), - self::MESSAGE_STATUS_SUCCESS + $this->__('Your review has been accepted for moderation.'), self::MESSAGE_STATUS_SUCCESS ); } catch (Exception $e) { $this->_message($this->__('Unable to post the review.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); } } else { if (is_array($validate)) { - $this->_message(implode('. ', $validate), self::MESSAGE_STATUS_ERROR); + $validate = array_map(array($this, '_trimDot'), $validate); + $this->_message(implode('. ', $validate) . '.', self::MESSAGE_STATUS_ERROR); } else { $this->_message($this->__('Unable to post the review.'), self::MESSAGE_STATUS_ERROR); } @@ -181,4 +180,15 @@ public function saveAction() $this->_message($this->__('Unable to post the review.'), self::MESSAGE_STATUS_ERROR); } } + + /** + * Trim ending dot (the ".") symbol from string + * + * @param string $text + * @return string + */ + private function _trimDot($text) + { + return trim($text, " \n\r\t."); + } } diff --git a/app/code/core/Mage/XmlConnect/controllers/WishlistController.php b/app/code/core/Mage/XmlConnect/controllers/WishlistController.php index 3037c58597..7fad737b17 100644 --- a/app/code/core/Mage/XmlConnect/controllers/WishlistController.php +++ b/app/code/core/Mage/XmlConnect/controllers/WishlistController.php @@ -36,14 +36,16 @@ class Mage_XmlConnect_WishlistController extends Mage_XmlConnect_Controller_Acti /** * Check if customer is logged in * - * @return void + * @return null */ public function preDispatch() { parent::preDispatch(); if (!$this->_getCustomerSession()->isLoggedIn()) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); - $this->_message($this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR); + $this->_message( + $this->__('Customer not logged in.'), self::MESSAGE_STATUS_ERROR, array('logged_in' => '0') + ); return ; } } @@ -82,23 +84,32 @@ protected function _getWishlist() /** * Display customer wishlist * - * @return void + * @return null */ public function indexAction() { $this->_getWishlist(); - $this->loadLayout(false); - $this->renderLayout(); + try { + $this->loadLayout(false); + $this->renderLayout(); + } catch (Mage_Core_Exception $e) { + $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); + } catch (Exception $e) { + Mage::logException($e); + $this->_message( + $this->__('An error occurred while loading wishlist.'), + self::MESSAGE_STATUS_ERROR + ); + } } /** * Adding new item * - * @return void + * @return null */ public function addAction() { - $session = $this->_getCustomerSession(); $wishlist = $this->_getWishlist(); if (!$wishlist) { return; @@ -118,30 +129,39 @@ public function addAction() } try { - $item = $wishlist->addNewItem($product); + $buyRequest = new Varien_Object($this->getRequest()->getParams()); + $result = $wishlist->addNewItem($product, $buyRequest); if (strlen(trim((string)$request->getParam('description')))) { - $item->setDescription($request->getParam('description')) - ->save(); + $result->setDescription($request->getParam('description'))->save(); } $wishlist->save(); - Mage::dispatchEvent('wishlist_add_product', array('wishlist'=>$wishlist, 'product'=>$product)); + Mage::dispatchEvent('wishlist_add_product', array( + 'wishlist' => $wishlist, + 'product' => $product, + 'item' => $result + )); Mage::helper('wishlist')->calculate(); - $message = $this->__('%1$s has been added to your wishlist.', $product->getName()); - $this->_message($message, self::MESSAGE_STATUS_SUCCESS); + $this->_message( + $this->__('%1$s has been added to your wishlist.', $product->getName()), + self::MESSAGE_STATUS_SUCCESS + ); } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { - $this->_message($this->__('An error occurred while adding item to wishlist.'), self::MESSAGE_STATUS_ERROR); + Mage::logException($e); + $this->_message( + $this->__('An error occurred while adding item to wishlist.'), self::MESSAGE_STATUS_ERROR + ); } } /** * Remove item * - * @return void + * @return null */ public function removeAction() { @@ -169,7 +189,7 @@ public function removeAction() /** * Clear wishlist action * - * @return void + * @return null */ public function clearAction() { @@ -185,7 +205,9 @@ public function clearAction() } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch(Exception $e) { - $this->_message($this->__('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(); @@ -194,7 +216,7 @@ public function clearAction() /** * Update wishlist item comments * - * @return void + * @return null */ public function updateAction() { @@ -234,7 +256,10 @@ public function updateAction() $this->_message($message, self::MESSAGE_STATUS_SUCCESS); } catch (Exception $e) { - $this->_message($this->__('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($this->__('No items were updated.'), self::MESSAGE_STATUS_ERROR); @@ -250,7 +275,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 + * @return null */ public function cartAction() { @@ -268,23 +293,20 @@ public function cartAction() return; } - /* @var $session Mage_Wishlist_Model_Session */ - $session = Mage::getSingleton('wishlist/session'); - $cart = Mage::getSingleton('checkout/cart'); - try { + $cart = Mage::getSingleton('checkout/cart'); $item->addToCart($cart, true); $cart->save()->getQuote()->collectTotals(); $wishlist->save(); - Mage::helper('wishlist')->calculate(); - $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($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) { + } 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(); $message = Mage::getModel('xmlconnect/simplexml_element', ''); diff --git a/app/code/core/Mage/XmlConnect/etc/config.xml b/app/code/core/Mage/XmlConnect/etc/config.xml index 42d5a5c103..339824ed87 100644 --- a/app/code/core/Mage/XmlConnect/etc/config.xml +++ b/app/code/core/Mage/XmlConnect/etc/config.xml @@ -29,6 +29,7 @@ 1.6.0.0 + 22.0 @@ -167,6 +168,13 @@ 0 paypal + + 1 + xmlconnect/payment_method_paypal_mecl + PayPal Mobile Express Checkout Library + 0 + paypal + diff --git a/app/design/adminhtml/default/default/template/paypal/system/config/payflowlink/info.phtml b/app/design/adminhtml/default/default/template/paypal/system/config/payflowlink/info.phtml index b5e5351071..7898e15828 100644 --- a/app/design/adminhtml/default/default/template/paypal/system/config/payflowlink/info.phtml +++ b/app/design/adminhtml/default/default/template/paypal/system/config/payflowlink/info.phtml @@ -72,7 +72,7 @@
    __('Note:') ?>
    • - __('Do not set any fields in the Billing and Shipping Information block as editable in your Payflow accout.') ?> + __('Do not set any fields in the Billing and Shipping Information block as editable in your Payflow account.'); ?>
    • __('Do not enable AVS or CSC options. The do not work when using Payflow Link Silent Mode.') ?> diff --git a/app/design/adminhtml/default/default/template/sales/order/shipment/packaging/popup.phtml b/app/design/adminhtml/default/default/template/sales/order/shipment/packaging/popup.phtml index 0e064fb260..aacd90daba 100644 --- a/app/design/adminhtml/default/default/template/sales/order/shipment/packaging/popup.phtml +++ b/app/design/adminhtml/default/default/template/sales/order/shipment/packaging/popup.phtml @@ -80,6 +80,7 @@ document.observe("dom:loaded", function() { getContainers(); ?>