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/vendortext45
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).
- '
';
@@ -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 . '>' . $this->_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 @@
0paypal
+
+ 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() {